Skip to content

Commit 6b50d95

Browse files
authored
fix: incorrect next/previous action after folder view refresh (#20447)
1 parent 27c456e commit 6b50d95

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

web/src/lib/components/shared-components/gallery-viewer/gallery-viewer.svelte

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import Portal from '../portal/portal.svelte';
2828
2929
interface Props {
30+
initialAssetId?: string;
3031
assets: (TimelineAsset | AssetResponseDto)[];
3132
assetInteraction: AssetInteraction;
3233
disableAssetSelect?: boolean;
@@ -44,6 +45,7 @@
4445
}
4546
4647
let {
48+
initialAssetId = undefined,
4749
assets = $bindable(),
4850
assetInteraction,
4951
disableAssetSelect = false,
@@ -117,7 +119,14 @@
117119
};
118120
});
119121
120-
let currentViewAssetIndex = 0;
122+
let currentIndex = 0;
123+
if (initialAssetId && assets.length > 0) {
124+
const index = assets.findIndex(({ id }) => id === initialAssetId);
125+
if (index !== -1) {
126+
currentIndex = index;
127+
}
128+
}
129+
121130
let shiftKeyIsDown = $state(false);
122131
let lastAssetMouseEvent: TimelineAsset | null = $state(null);
123132
let slidingWindow = $state({ top: 0, bottom: 0 });
@@ -150,8 +159,8 @@
150159
}
151160
});
152161
const viewAssetHandler = async (asset: TimelineAsset) => {
153-
currentViewAssetIndex = assets.findIndex((a) => a.id == asset.id);
154-
await setAssetId(assets[currentViewAssetIndex].id);
162+
currentIndex = assets.findIndex((a) => a.id == asset.id);
163+
await setAssetId(assets[currentIndex].id);
155164
await navigate({ targetRoute: 'current', assetId: $viewingAsset.id });
156165
};
157166
@@ -324,12 +333,12 @@
324333
if (onNext) {
325334
asset = await onNext();
326335
} else {
327-
if (currentViewAssetIndex >= assets.length - 1) {
336+
if (currentIndex >= assets.length - 1) {
328337
return false;
329338
}
330339
331-
currentViewAssetIndex = currentViewAssetIndex + 1;
332-
asset = currentViewAssetIndex < assets.length ? assets[currentViewAssetIndex] : undefined;
340+
currentIndex = currentIndex + 1;
341+
asset = currentIndex < assets.length ? assets[currentIndex] : undefined;
333342
}
334343
335344
if (!asset) {
@@ -374,12 +383,12 @@
374383
if (onPrevious) {
375384
asset = await onPrevious();
376385
} else {
377-
if (currentViewAssetIndex <= 0) {
386+
if (currentIndex <= 0) {
378387
return false;
379388
}
380389
381-
currentViewAssetIndex = currentViewAssetIndex - 1;
382-
asset = currentViewAssetIndex >= 0 ? assets[currentViewAssetIndex] : undefined;
390+
currentIndex = currentIndex - 1;
391+
asset = currentIndex >= 0 ? assets[currentIndex] : undefined;
383392
}
384393
385394
if (!asset) {
@@ -412,10 +421,10 @@
412421
);
413422
if (assets.length === 0) {
414423
await goto(AppRoute.PHOTOS);
415-
} else if (currentViewAssetIndex === assets.length) {
424+
} else if (currentIndex === assets.length) {
416425
await handlePrevious();
417426
} else {
418-
await setAssetId(assets[currentViewAssetIndex].id);
427+
await setAssetId(assets[currentIndex].id);
419428
}
420429
break;
421430
}

web/src/routes/(user)/folders/[[photos=photos]]/[[assetId=id]]/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import TreeItems from '$lib/components/shared-components/tree/tree-items.svelte';
2222
import Sidebar from '$lib/components/sidebar/sidebar.svelte';
2323
import { AppRoute, QueryParameter } from '$lib/constants';
24-
import { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
2524
import type { Viewport } from '$lib/managers/timeline-manager/types';
25+
import { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
2626
import { foldersStore } from '$lib/stores/folders.svelte';
2727
import { preferences } from '$lib/stores/user.store';
2828
import { cancelMultiselect } from '$lib/utils/asset-utils';
@@ -40,7 +40,6 @@
4040
let { data }: Props = $props();
4141
4242
const viewport: Viewport = $state({ width: 0, height: 0 });
43-
4443
const assetInteraction = new AssetInteraction();
4544
4645
const handleNavigateToFolder = (folderName: string) => navigateToView(joinPaths(data.tree.path, folderName));
@@ -104,6 +103,7 @@
104103
{#if data.pathAssets && data.pathAssets.length > 0}
105104
<div bind:clientHeight={viewport.height} bind:clientWidth={viewport.width} class="mt-2">
106105
<GalleryViewer
106+
initialAssetId={data.asset?.id}
107107
assets={data.pathAssets}
108108
{assetInteraction}
109109
{viewport}

0 commit comments

Comments
 (0)