From a373d50c31fb367b76c45b0a2c9d20e99e0741d4 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Fri, 13 Sep 2024 12:27:10 -0400 Subject: [PATCH] fix(web): memory viewer (#12649) refactor(web): memory viewer --- .../memory-page/memory-viewer.svelte | 403 ++++++++++-------- .../components/photos-page/memory-lane.svelte | 4 +- .../gallery-viewer/gallery-viewer.svelte | 12 +- web/src/lib/constants.ts | 3 +- 4 files changed, 242 insertions(+), 180 deletions(-) diff --git a/web/src/lib/components/memory-page/memory-viewer.svelte b/web/src/lib/components/memory-page/memory-viewer.svelte index 0088eb7a43..ae6416873e 100644 --- a/web/src/lib/components/memory-page/memory-viewer.svelte +++ b/web/src/lib/components/memory-page/memory-viewer.svelte @@ -1,8 +1,9 @@ canGoForward && toNext() }, - { shortcut: { key: 'd' }, onShortcut: () => canGoForward && toNext() }, - { shortcut: { key: 'ArrowLeft' }, onShortcut: () => canGoBack && toPrevious() }, - { shortcut: { key: 'a' }, onShortcut: () => canGoBack && toPrevious() }, - { shortcut: { key: 'Escape' }, onShortcut: () => goto(AppRoute.PHOTOS) }, - ]} + use:shortcuts={$isViewing + ? [] + : [ + { shortcut: { key: 'ArrowRight' }, onShortcut: () => handleNextAsset() }, + { shortcut: { key: 'd' }, onShortcut: () => handleNextAsset() }, + { shortcut: { key: 'ArrowLeft' }, onShortcut: () => handlePreviousAsset() }, + { shortcut: { key: 'a' }, onShortcut: () => handlePreviousAsset() }, + { shortcut: { key: 'Escape' }, onShortcut: () => handleEscape() }, + ]} /> {#if isMultiSelectionMode} @@ -172,61 +235,56 @@ - + - - + + {/if}
- {#if currentMemory} + {#if current && current.memory.assets.length > 0} goto(AppRoute.PHOTOS)} forceDark>

- {$memoryLaneTitle(currentMemory.yearsAgo)} + {$memoryLaneTitle(current.memory.yearsAgo)}

- {#if canGoForward} -
- (paused = !paused)} - class="hover:text-black" - /> +
+ handleAction(paused ? 'play' : 'pause')} + class="hover:text-black" + /> - {#each currentMemory.assets as _, index} - - - {#await resetPromise} - - {:then} - assetIndex ? 0 : $progress * 100}%`} - /> - {/await} - - {/each} + {#each current.memory.assets as asset, index} + + + {#await resetPromise} + + {:then} + current.assetIndex ? 0 : $progress * 100}%`} + /> + {/await} + + {/each} -
-

- {(assetIndex + 1).toLocaleString($locale)}/{currentMemory.assets.length.toLocaleString($locale)} -

-
+
+

+ {(current.assetIndex + 1).toLocaleString($locale)}/{current.memory.assets.length.toLocaleString($locale)} +

- {/if} +
{#if galleryInView} @@ -250,22 +308,17 @@ class="ml-[-100%] box-border flex h-[calc(100vh_-_180px)] w-[300%] items-center justify-center gap-10 overflow-hidden" > -
+
@@ -293,12 +346,12 @@ class="main-view relative flex h-full w-[70vw] place-content-center place-items-center rounded-2xl bg-black" >
- {#key currentAsset.id} + {#key current.asset.id} {currentAsset.exifInfo?.description} {/key} @@ -309,59 +362,59 @@ class:opacity-100={!galleryInView} >
- {#if canGoBack} + {#if current.previous}
{/if} - {#if canGoForward} + {#if current.next}
- +
{/if}

- {fromLocalDateTime(currentMemory.assets[0].localDateTime).toLocaleString(DateTime.DATE_FULL)} + {fromLocalDateTime(current.memory.assets[0].localDateTime).toLocaleString(DateTime.DATE_FULL)}

- {currentAsset.exifInfo?.city || ''} - {currentAsset.exifInfo?.country || ''} + {current.asset.exifInfo?.city || ''} + {current.asset.exifInfo?.country || ''}

-
+
@@ -411,7 +464,13 @@ use:resizeObserver={({ height, width }) => ((viewport.height = height), (viewport.width = width))} bind:this={memoryGallery} > - +
{/if} diff --git a/web/src/lib/components/photos-page/memory-lane.svelte b/web/src/lib/components/photos-page/memory-lane.svelte index 5bc55796ae..459c7a6118 100644 --- a/web/src/lib/components/photos-page/memory-lane.svelte +++ b/web/src/lib/components/photos-page/memory-lane.svelte @@ -69,11 +69,11 @@ {/if}
(innerWidth = width)}> - {#each $memoryStore as memory, index (memory.yearsAgo)} + {#each $memoryStore as memory (memory.yearsAgo)} {#if memory.assets.length > 0} void) | undefined = undefined; export let showAssetName = false; + export let onPrevious: (() => Promise) | undefined = undefined; + export let onNext: (() => Promise) | undefined = undefined; let { isViewing: isViewerOpen, asset: viewingAsset, setAsset } = assetViewingStore; @@ -50,8 +52,9 @@ const handleNext = async () => { try { - if (currentViewAssetIndex < assets.length - 1) { - setAsset(assets[++currentViewAssetIndex]); + const asset = onNext ? await onNext() : assets[++currentViewAssetIndex]; + if (asset) { + setAsset(asset); await navigate({ targetRoute: 'current', assetId: $viewingAsset.id }); } } catch (error) { @@ -61,8 +64,9 @@ const handlePrevious = async () => { try { - if (currentViewAssetIndex > 0) { - setAsset(assets[--currentViewAssetIndex]); + const asset = onPrevious ? await onPrevious() : assets[--currentViewAssetIndex]; + if (asset) { + setAsset(asset); await navigate({ targetRoute: 'current', assetId: $viewingAsset.id }); } } catch (error) { diff --git a/web/src/lib/constants.ts b/web/src/lib/constants.ts index 05011680dc..7af4635a84 100644 --- a/web/src/lib/constants.ts +++ b/web/src/lib/constants.ts @@ -71,9 +71,8 @@ export const dateFormats = { export enum QueryParameter { ACTION = 'action', - ASSET_INDEX = 'assetIndex', + ID = 'id', IS_OPEN = 'isOpen', - MEMORY_INDEX = 'memoryIndex', ONBOARDING_STEP = 'step', OPEN_SETTING = 'openSetting', PREVIOUS_ROUTE = 'previousRoute',