High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
fix(web): ensure current asset index stays within bounds (#14013)
Michel Heusschend3fe238eef03
diff --git a/web/src/lib/components/shared-components/gallery-viewer/gallery-viewer.svelte b/web/src/lib/components/shared-components/gallery-viewer/gallery-viewer.svelteindex aa84bd69f0..35eaf45d53 100644--- a/web/src/lib/components/shared-components/gallery-viewer/gallery-viewer.svelte+++ b/web/src/lib/components/shared-components/gallery-viewer/gallery-viewer.svelte@@ -66,11 +66,15 @@const handleNext = async () => {try {- const asset = onNext ? await onNext() : assets[++currentViewAssetIndex];- if (asset) {- setAsset(asset);- await navigate({ targetRoute: 'current', assetId: $viewingAsset.id });+ let asset: AssetResponseDto | undefined;+ if (onNext) {+ asset = await onNext();+ } else {+ currentViewAssetIndex = Math.min(currentViewAssetIndex + 1, assets.length - 1);+ asset = assets[currentViewAssetIndex];}++ await navigateToAsset(asset);} catch (error) {handleError(error, $t('errors.cannot_navigate_next_asset'));}@@ -78,16 +82,27 @@const handlePrevious = async () => {try {- const asset = onPrevious ? await onPrevious() : assets[--currentViewAssetIndex];- if (asset) {- setAsset(asset);- await navigate({ targetRoute: 'current', assetId: $viewingAsset.id });+ let asset: AssetResponseDto | undefined;+ if (onPrevious) {+ asset = await onPrevious();+ } else {+ currentViewAssetIndex = Math.max(currentViewAssetIndex - 1, 0);+ asset = assets[currentViewAssetIndex];}++ await navigateToAsset(asset);} catch (error) {handleError(error, $t('errors.cannot_navigate_previous_asset'));}};+ const navigateToAsset = async (asset?: AssetResponseDto) => {+ if (asset && asset.id !== $viewingAsset.id) {+ setAsset(asset);+ await navigate({ targetRoute: 'current', assetId: $viewingAsset.id });+ }+ };+const handleAction = async (action: Action) => {switch (action.type) {case AssetAction.ARCHIVE: