Skip to content

Commit b080fc6

Browse files
committed
- move asset stack functions from actions into timeline-manager
1 parent 5b04235 commit b080fc6

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed

web/src/lib/components/photos-page/asset-grid.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@
421421
const onStackAssets = async () => {
422422
const result = await stackAssets(assetInteraction.selectedAssets);
423423
424-
updateStackedAssetInTimeline(timelineManager, result);
424+
timelineManager.stackAssets(result);//updateStackedAssetInTimeline(timelineManager, result);
425425
426426
onEscape();
427427
};
@@ -525,18 +525,18 @@
525525
}
526526
527527
case AssetAction.UNSTACK: {
528-
updateUnstackedAssetInTimeline(timelineManager, action.assets);
528+
timelineManager.unstackAssets(action.assets);//updateUnstackedAssetInTimeline(timelineManager, action.assets);
529529
break;
530530
}
531531
case AssetAction.REMOVE_ASSET_FROM_STACK: {
532532
timelineManager.addAssets([toTimelineAsset(action.asset)]);
533533
if (action.stack) {
534-
refreshStackedAssetInTimeline(timelineManager, action.stack);
534+
timelineManager.refreshStack(action.stack)//refreshStackedAssetInTimeline(timelineManager, action.stack);
535535
}
536536
break;
537537
}
538538
case AssetAction.SET_STACK_PRIMARY_ASSET: {
539-
refreshStackedAssetInTimeline(timelineManager, action.stack, true);
539+
timelineManager.refreshStack(action.stack, true);//refreshStackedAssetInTimeline(timelineManager, action.stack, true);
540540
break;
541541
}
542542
}

web/src/lib/managers/timeline-manager/timeline-manager.svelte.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AssetOrder, getAssetInfo, getTimeBuckets } from '@immich/sdk';
1+
import { AssetOrder, getAssetInfo, getTimeBuckets, type StackResponseDto } from '@immich/sdk';
22

33
import { authManager } from '$lib/managers/auth-manager.svelte';
44

@@ -23,6 +23,7 @@ import {
2323
retrieveRange as retrieveRangeUtil,
2424
} from '$lib/managers/timeline-manager/internal/search-support.svelte';
2525
import { WebsocketSupport } from '$lib/managers/timeline-manager/internal/websocket-support.svelte';
26+
import type { StackResponse } from '$lib/utils/asset-utils';
2627
import { DayGroup } from './day-group.svelte';
2728
import { isMismatched, updateObject } from './internal/utils.svelte';
2829
import { MonthGroup } from './month-group.svelte';
@@ -544,4 +545,43 @@ export class TimelineManager {
544545
getAssetOrder() {
545546
return this.#options.order ?? AssetOrder.Desc;
546547
}
548+
549+
stackAssets({ stack, toDeleteIds }: StackResponse) {
550+
if (stack) {
551+
this.updateAssetOperation([stack.primaryAssetId], (asset) => {
552+
asset.stack = {
553+
id: stack.id,
554+
primaryAssetId: stack.primaryAssetId,
555+
assetCount: stack.assets.length,
556+
};
557+
return { remove: false };
558+
});
559+
this.removeAssets(toDeleteIds);
560+
}
561+
}
562+
563+
unstackAssets(assets: TimelineAsset[]) {
564+
this.updateAssetOperation(
565+
assets.map(({ id }) => id),
566+
(asset) => {
567+
asset.stack = null;
568+
return { remove: false };
569+
},
570+
);
571+
this.addAssets(assets);
572+
}
573+
574+
refreshStack(stack: StackResponseDto, addPrimaryAsset: boolean = false) {
575+
if (stack) {
576+
if (addPrimaryAsset) {
577+
this.addAssets(
578+
stack.assets.filter((asset) => asset.id === stack.primaryAssetId).map((asset) => toTimelineAsset(asset)),
579+
);
580+
}
581+
this.stackAssets({
582+
stack,
583+
toDeleteIds: stack.assets.filter((asset) => asset.id !== stack.primaryAssetId).map(({ id }) => id),
584+
});
585+
}
586+
}
547587
}

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@
2727
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
2828
import { isFaceEditMode } from '$lib/stores/face-edit.svelte';
2929
import { preferences, user } from '$lib/stores/user.store';
30-
import {
31-
updateStackedAssetInTimeline,
32-
updateUnstackedAssetInTimeline,
33-
type OnLink,
34-
type OnUnlink,
35-
} from '$lib/utils/actions';
30+
import { type OnLink, type OnUnlink } from '$lib/utils/actions';
3631
import { openFileUploadDialog } from '$lib/utils/file-uploader';
3732
import { AssetVisibility } from '@immich/sdk';
3833
@@ -131,8 +126,8 @@
131126
{#if assetInteraction.selectedAssets.length > 1 || isAssetStackSelected}
132127
<StackAction
133128
unstack={isAssetStackSelected}
134-
onStack={(result) => updateStackedAssetInTimeline(timelineManager, result)}
135-
onUnstack={(assets) => updateUnstackedAssetInTimeline(timelineManager, assets)}
129+
onStack={(result) => timelineManager.stackAssets(result)}
130+
onUnstack={(assets) => timelineManager.unstackAssets(assets)}
136131
/>
137132
{/if}
138133
{#if isLinkActionAvailable}

0 commit comments

Comments
 (0)