Skip to content

High performance self-hosted photo and video management solution.

fix: escape handling (#25627)

Daniel Dietzler4e0e1b2c5cad
diff --git a/web/src/lib/components/timeline/TimelineAssetViewer.svelte b/web/src/lib/components/timeline/TimelineAssetViewer.svelte
index f61d88c1c4..e26d969858 100644
--- a/web/src/lib/components/timeline/TimelineAssetViewer.svelte
+++ b/web/src/lib/components/timeline/TimelineAssetViewer.svelte
@@ -97,7 +97,6 @@
};
const handleClose = async (asset: { id: string }) => {
- assetViewingStore.showAssetViewer(false);
invisible = true;
$gridScrollTarget = { at: asset.id };
await navigate({ targetRoute: 'current', assetId: null, assetGridRouteSearchParams: $gridScrollTarget });
diff --git a/web/src/lib/components/timeline/actions/TimelineKeyboardActions.svelte b/web/src/lib/components/timeline/actions/TimelineKeyboardActions.svelte
index 6bc9ba3549..77f5300180 100644
--- a/web/src/lib/components/timeline/actions/TimelineKeyboardActions.svelte
+++ b/web/src/lib/components/timeline/actions/TimelineKeyboardActions.svelte
@@ -141,43 +141,41 @@
}
};
- let shortcutList = $derived(
- (() => {
- if (searchStore.isSearchEnabled || $showAssetViewer) {
- return [];
- }
+ const shortcutList = $derived.by(() => {
+ if (searchStore.isSearchEnabled || $showAssetViewer) {
+ return [];
+ }
- const shortcuts: ShortcutOptions[] = [
- { shortcut: { key: '?', shift: true }, onShortcut: handleOpenShortcutModal },
- { shortcut: { key: '/' }, onShortcut: () => goto(Route.explore()) },
- { shortcut: { key: 'A', ctrl: true }, onShortcut: () => selectAllAssets(timelineManager, assetInteraction) },
- { shortcut: { key: 'ArrowRight' }, onShortcut: () => setFocusTo('earlier', 'asset') },
- { shortcut: { key: 'ArrowLeft' }, onShortcut: () => setFocusTo('later', 'asset') },
- { shortcut: { key: 'D' }, onShortcut: () => setFocusTo('earlier', 'day') },
- { shortcut: { key: 'D', shift: true }, onShortcut: () => setFocusTo('later', 'day') },
- { shortcut: { key: 'M' }, onShortcut: () => setFocusTo('earlier', 'month') },
- { shortcut: { key: 'M', shift: true }, onShortcut: () => setFocusTo('later', 'month') },
- { shortcut: { key: 'Y' }, onShortcut: () => setFocusTo('earlier', 'year') },
- { shortcut: { key: 'Y', shift: true }, onShortcut: () => setFocusTo('later', 'year') },
- { shortcut: { key: 'G' }, onShortcut: handleOpenDateModal },
- ];
- if (onEscape) {
- shortcuts.push({ shortcut: { key: 'Escape' }, onShortcut: onEscape });
- }
+ const shortcuts: ShortcutOptions[] = [
+ { shortcut: { key: '?', shift: true }, onShortcut: handleOpenShortcutModal },
+ { shortcut: { key: '/' }, onShortcut: () => goto(Route.explore()) },
+ { shortcut: { key: 'A', ctrl: true }, onShortcut: () => selectAllAssets(timelineManager, assetInteraction) },
+ { shortcut: { key: 'ArrowRight' }, onShortcut: () => setFocusTo('earlier', 'asset') },
+ { shortcut: { key: 'ArrowLeft' }, onShortcut: () => setFocusTo('later', 'asset') },
+ { shortcut: { key: 'D' }, onShortcut: () => setFocusTo('earlier', 'day') },
+ { shortcut: { key: 'D', shift: true }, onShortcut: () => setFocusTo('later', 'day') },
+ { shortcut: { key: 'M' }, onShortcut: () => setFocusTo('earlier', 'month') },
+ { shortcut: { key: 'M', shift: true }, onShortcut: () => setFocusTo('later', 'month') },
+ { shortcut: { key: 'Y' }, onShortcut: () => setFocusTo('earlier', 'year') },
+ { shortcut: { key: 'Y', shift: true }, onShortcut: () => setFocusTo('later', 'year') },
+ { shortcut: { key: 'G' }, onShortcut: handleOpenDateModal },
+ ];
+ if (onEscape) {
+ shortcuts.push({ shortcut: { key: 'Escape' }, onShortcut: onEscape });
+ }
- if (assetInteraction.selectionActive) {
- shortcuts.push(
- { shortcut: { key: 'Delete' }, onShortcut: onDelete },
- { shortcut: { key: 'Delete', shift: true }, onShortcut: () => trashOrDelete(true) },
- { shortcut: { key: 'D', ctrl: true }, onShortcut: () => deselectAllAssets() },
- { shortcut: { key: 's' }, onShortcut: () => onStackAssets() },
- { shortcut: { key: 'a', shift: true }, onShortcut: toggleArchive },
- );
- }
+ if (assetInteraction.selectionActive) {
+ shortcuts.push(
+ { shortcut: { key: 'Delete' }, onShortcut: onDelete },
+ { shortcut: { key: 'Delete', shift: true }, onShortcut: () => trashOrDelete(true) },
+ { shortcut: { key: 'D', ctrl: true }, onShortcut: () => deselectAllAssets() },
+ { shortcut: { key: 's' }, onShortcut: () => onStackAssets() },
+ { shortcut: { key: 'a', shift: true }, onShortcut: toggleArchive },
+ );
+ }
- return shortcuts;
- })(),
- );
+ return shortcuts;
+ });
</script>
<svelte:document onkeydown={onKeyDown} onkeyup={onKeyUp} onselectstart={onSelectStart} use:shortcuts={shortcutList} />
diff --git a/web/src/lib/modals/AlbumOptionsModal.svelte b/web/src/lib/modals/AlbumOptionsModal.svelte
index 4553f022df..392389fe92 100644
--- a/web/src/lib/modals/AlbumOptionsModal.svelte
+++ b/web/src/lib/modals/AlbumOptionsModal.svelte
@@ -3,6 +3,7 @@
import HeaderActionButton from '$lib/components/HeaderActionButton.svelte';
import OnEvents from '$lib/components/OnEvents.svelte';
import UserAvatar from '$lib/components/shared-components/user-avatar.svelte';
+ import { AlbumPageViewMode } from '$lib/constants';
import {
getAlbumActions,
handleRemoveUserFromAlbum,
@@ -55,7 +56,7 @@
sharedLinks = sharedLinks.filter(({ id }) => sharedLink.id !== id);
};
- const { AddUsers, CreateSharedLink } = $derived(getAlbumActions($t, album));
+ const { AddUsers, CreateSharedLink } = $derived(getAlbumActions($t, album, AlbumPageViewMode.OPTIONS));
let sharedLinks: SharedLinkResponseDto[] = $state([]);
diff --git a/web/src/lib/services/album.service.ts b/web/src/lib/services/album.service.ts
index 240867be54..ac0a1045b3 100644
--- a/web/src/lib/services/album.service.ts
+++ b/web/src/lib/services/album.service.ts
@@ -1,5 +1,6 @@
import { goto } from '$app/navigation';
import ToastAction from '$lib/components/ToastAction.svelte';
+import { AlbumPageViewMode } from '$lib/constants';
import { eventManager } from '$lib/managers/event-manager.svelte';
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
import AlbumAddUsersModal from '$lib/modals/AlbumAddUsersModal.svelte';
@@ -25,7 +26,7 @@ import {
type UserResponseDto,
} from '@immich/sdk';
import { modalManager, toastManager, type ActionItem } from '@immich/ui';
-import { mdiLink, mdiPlus, mdiPlusBoxOutline, mdiShareVariantOutline, mdiUpload } from '@mdi/js';
+import { mdiArrowLeft, mdiLink, mdiPlus, mdiPlusBoxOutline, mdiShareVariantOutline, mdiUpload } from '@mdi/js';
import { type MessageFormatter } from 'svelte-i18n';
import { get } from 'svelte/store';
@@ -39,7 +40,7 @@ export const getAlbumsActions = ($t: MessageFormatter) => {
return { Create };
};
-export const getAlbumActions = ($t: MessageFormatter, album: AlbumResponseDto) => {
+export const getAlbumActions = ($t: MessageFormatter, album: AlbumResponseDto, viewMode: AlbumPageViewMode) => {
const isOwned = get(user).id === album.ownerId;
const Share: ActionItem = {
@@ -66,7 +67,16 @@ export const getAlbumActions = ($t: MessageFormatter, album: AlbumResponseDto) =
onAction: () => modalManager.show(SharedLinkCreateModal, { albumId: album.id }),
};
- return { Share, AddUsers, CreateSharedLink };
+ const Close: ActionItem = {
+ title: $t('go_back'),
+ type: $t('command'),
+ icon: mdiArrowLeft,
+ onAction: () => goto(Route.albums()),
+ $if: () => viewMode === AlbumPageViewMode.VIEW,
+ shortcuts: { key: 'Escape' },
+ };
+
+ return { Share, AddUsers, CreateSharedLink, Close };
};
export const getAlbumAssetsActions = ($t: MessageFormatter, album: AlbumResponseDto, assets: TimelineAsset[]) => {
diff --git a/web/src/routes/(user)/albums/[albumId=id]/[[photos=photos]]/[[assetId=id]]/+page.svelte b/web/src/routes/(user)/albums/[albumId=id]/[[photos=photos]]/[[assetId=id]]/+page.svelte
index c50d296de5..88baa416b8 100644
--- a/web/src/routes/(user)/albums/[albumId=id]/[[photos=photos]]/[[assetId=id]]/+page.svelte
+++ b/web/src/routes/(user)/albums/[albumId=id]/[[photos=photos]]/[[assetId=id]]/+page.svelte
@@ -1,5 +1,5 @@
<script lang="ts">
- import { afterNavigate, goto, onNavigate } from '$app/navigation';
+ import { goto, onNavigate } from '$app/navigation';
import { scrollMemoryClearer } from '$lib/actions/scroll-memory';
import ActionButton from '$lib/components/ActionButton.svelte';
import AlbumDescription from '$lib/components/album-page/album-description.svelte';
@@ -52,13 +52,7 @@
import { handlePromiseError } from '$lib/utils';
import { cancelMultiselect } from '$lib/utils/asset-utils';
import { handleError } from '$lib/utils/handle-error';
- import {
- isAlbumsRoute,
- isPeopleRoute,
- isSearchRoute,
- navigate,
- type AssetGridRouteSearchParams,
- } from '$lib/utils/navigation';
+ import { isAlbumsRoute, navigate, type AssetGridRouteSearchParams } from '$lib/utils/navigation';
import { AlbumUserRole, AssetVisibility, getAlbumInfo, updateAlbumInfo, type AlbumResponseDto } from '@immich/sdk';
import { CommandPaletteDefaultProvider, Icon, IconButton, modalManager, toastManager } from '@immich/ui';
import {
@@ -91,7 +85,6 @@
let oldAt: AssetGridRouteSearchParams | null | undefined = $state();
- let backUrl: string = $state(Route.albums());
let viewMode: AlbumPageViewMode = $state(AlbumPageViewMode.VIEW);
let timelineManager = $state<TimelineManager>() as TimelineManager;
@@ -100,25 +93,6 @@
const assetInteraction = new AssetInteraction();
const timelineInteraction = new AssetInteraction();
- afterNavigate(({ from }) => {
- let url: string | undefined = from?.url?.pathname;
-
- const route = from?.route?.id;
- if (isSearchRoute(route)) {
- url = from?.url.href;
- }
-
- if (isAlbumsRoute(route) || isPeopleRoute(route)) {
- url = Route.albums();
- }
-
- backUrl = url || Route.albums();
-
- if (backUrl === Route.sharedLinks()) {
- backUrl = history.state?.backUrl || Route.albums();
- }
- });
-
const handleFavorite = async () => {
try {
await activityManager.toggleLike();
@@ -158,7 +132,6 @@
cancelMultiselect(assetInteraction);
return;
}
- await goto(backUrl);
return;
};
@@ -305,7 +278,7 @@
const onAlbumDelete = async ({ id }: AlbumResponseDto) => {
if (id === album.id) {
- await goto(backUrl);
+ await goto(Route.albums());
viewMode = AlbumPageViewMode.VIEW;
}
};
@@ -332,7 +305,7 @@
};
const { Cast } = $derived(getGlobalActions($t));
- const { Share } = $derived(getAlbumActions($t, album));
+ const { Share, Close } = $derived(getAlbumActions($t, album, viewMode));
const { AddAssets, Upload } = $derived(getAlbumAssetsActions($t, album, timelineInteraction.selectedAssets));
</script>
@@ -346,7 +319,7 @@
onAlbumUserDelete={refreshAlbum}
onAlbumUpdate={(newAlbum) => (album = newAlbum)}
/>
-<CommandPaletteDefaultProvider name={$t('album')} actions={[AddAssets, Upload]} />
+<CommandPaletteDefaultProvider name={$t('album')} actions={[AddAssets, Upload, Close]} />
<div class="flex overflow-hidden" use:scrollMemoryClearer={{ routeStartsWith: Route.albums() }}>
<div class="relative w-full shrink">
@@ -512,7 +485,7 @@
</AssetSelectControlBar>
{:else}
{#if viewMode === AlbumPageViewMode.VIEW}
- <ControlAppBar showBackButton backIcon={mdiArrowLeft} onClose={() => goto(backUrl)}>
+ <ControlAppBar showBackButton backIcon={mdiArrowLeft} onClose={() => goto(Route.albums())}>
{#snippet trailing()}
<ActionButton action={Cast} />
diff --git a/web/src/routes/(user)/people/[personId]/[[photos=photos]]/[[assetId=id]]/+page.svelte b/web/src/routes/(user)/people/[personId]/[[photos=photos]]/[[assetId=id]]/+page.svelte
index ed005b1f9c..641510aae1 100644
--- a/web/src/routes/(user)/people/[personId]/[[photos=photos]]/[[assetId=id]]/+page.svelte
+++ b/web/src/routes/(user)/people/[personId]/[[photos=photos]]/[[assetId=id]]/+page.svelte
@@ -33,7 +33,6 @@
import { Route } from '$lib/route';
import { getPersonActions } from '$lib/services/person.service';
import { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
- import { assetViewingStore } from '$lib/stores/asset-viewing.store';
import { locale } from '$lib/stores/preferences.store';
import { preferences } from '$lib/stores/user.store';
import { websocketEvents } from '$lib/stores/websocket';
@@ -61,7 +60,6 @@
let { data }: Props = $props();
let numberOfAssets = $derived(data.statistics.assets);
- let { isViewing: showAssetViewer } = assetViewingStore;
let timelineManager = $state<TimelineManager>() as TimelineManager;
const options = $derived({ visibility: AssetVisibility.Timeline, personId: data.person.id });
@@ -106,16 +104,13 @@
});
const handleEscape = async () => {
- if ($showAssetViewer) {
- return;
- }
if (assetInteraction.selectionActive) {
assetInteraction.clearMultiselect();
return;
- } else {
- await goto(previousRoute);
- return;
}
+
+ await goto(previousRoute);
+ return;
};
const updateAssetCount = async () => {