|
27 | 27 | import Portal from '../portal/portal.svelte';
|
28 | 28 |
|
29 | 29 | interface Props {
|
| 30 | + initialAssetId?: string; |
30 | 31 | assets: (TimelineAsset | AssetResponseDto)[];
|
31 | 32 | assetInteraction: AssetInteraction;
|
32 | 33 | disableAssetSelect?: boolean;
|
|
44 | 45 | }
|
45 | 46 |
|
46 | 47 | let {
|
| 48 | + initialAssetId = undefined, |
47 | 49 | assets = $bindable(),
|
48 | 50 | assetInteraction,
|
49 | 51 | disableAssetSelect = false,
|
|
117 | 119 | };
|
118 | 120 | });
|
119 | 121 |
|
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 | +
|
121 | 130 | let shiftKeyIsDown = $state(false);
|
122 | 131 | let lastAssetMouseEvent: TimelineAsset | null = $state(null);
|
123 | 132 | let slidingWindow = $state({ top: 0, bottom: 0 });
|
|
150 | 159 | }
|
151 | 160 | });
|
152 | 161 | 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); |
155 | 164 | await navigate({ targetRoute: 'current', assetId: $viewingAsset.id });
|
156 | 165 | };
|
157 | 166 |
|
|
324 | 333 | if (onNext) {
|
325 | 334 | asset = await onNext();
|
326 | 335 | } else {
|
327 |
| - if (currentViewAssetIndex >= assets.length - 1) { |
| 336 | + if (currentIndex >= assets.length - 1) { |
328 | 337 | return false;
|
329 | 338 | }
|
330 | 339 |
|
331 |
| - currentViewAssetIndex = currentViewAssetIndex + 1; |
332 |
| - asset = currentViewAssetIndex < assets.length ? assets[currentViewAssetIndex] : undefined; |
| 340 | + currentIndex = currentIndex + 1; |
| 341 | + asset = currentIndex < assets.length ? assets[currentIndex] : undefined; |
333 | 342 | }
|
334 | 343 |
|
335 | 344 | if (!asset) {
|
|
374 | 383 | if (onPrevious) {
|
375 | 384 | asset = await onPrevious();
|
376 | 385 | } else {
|
377 |
| - if (currentViewAssetIndex <= 0) { |
| 386 | + if (currentIndex <= 0) { |
378 | 387 | return false;
|
379 | 388 | }
|
380 | 389 |
|
381 |
| - currentViewAssetIndex = currentViewAssetIndex - 1; |
382 |
| - asset = currentViewAssetIndex >= 0 ? assets[currentViewAssetIndex] : undefined; |
| 390 | + currentIndex = currentIndex - 1; |
| 391 | + asset = currentIndex >= 0 ? assets[currentIndex] : undefined; |
383 | 392 | }
|
384 | 393 |
|
385 | 394 | if (!asset) {
|
|
412 | 421 | );
|
413 | 422 | if (assets.length === 0) {
|
414 | 423 | await goto(AppRoute.PHOTOS);
|
415 |
| - } else if (currentViewAssetIndex === assets.length) { |
| 424 | + } else if (currentIndex === assets.length) { |
416 | 425 | await handlePrevious();
|
417 | 426 | } else {
|
418 |
| - await setAssetId(assets[currentViewAssetIndex].id); |
| 427 | + await setAssetId(assets[currentIndex].id); |
419 | 428 | }
|
420 | 429 | break;
|
421 | 430 | }
|
|
0 commit comments