Skip to content

Commit 5b04235

Browse files
committed
- add new action to refresh stacks
- optionally adds a primary asset - updates the asset and its stack - removes the non-primary assets
1 parent 708e42d commit 5b04235

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

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

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@
2626
import { searchStore } from '$lib/stores/search.svelte';
2727
import { featureFlags } from '$lib/stores/server-config.store';
2828
import { handlePromiseError } from '$lib/utils';
29-
import { deleteAssets, updateStackedAssetInTimeline, updateUnstackedAssetInTimeline } from '$lib/utils/actions';
29+
import {
30+
deleteAssets,
31+
refreshStackedAssetInTimeline,
32+
updateStackedAssetInTimeline,
33+
updateUnstackedAssetInTimeline,
34+
} from '$lib/utils/actions';
3035
import { archiveAssets, cancelMultiselect, selectAllAssets, stackAssets } from '$lib/utils/asset-utils';
3136
import { navigate } from '$lib/utils/navigation';
3237
import {
@@ -526,32 +531,12 @@
526531
case AssetAction.REMOVE_ASSET_FROM_STACK: {
527532
timelineManager.addAssets([toTimelineAsset(action.asset)]);
528533
if (action.stack) {
529-
//Have to unstack then restack assets in timeline in order to update the stack count in the timeline.
530-
updateUnstackedAssetInTimeline(
531-
timelineManager,
532-
action.stack.assets.map((asset) => toTimelineAsset(asset)),
533-
);
534-
updateStackedAssetInTimeline(timelineManager, {
535-
stack: action.stack,
536-
toDeleteIds: action.stack.assets
537-
.filter((asset) => asset.id !== action.stack?.primaryAssetId)
538-
.map((asset) => asset.id),
539-
});
534+
refreshStackedAssetInTimeline(timelineManager, action.stack);
540535
}
541536
break;
542537
}
543538
case AssetAction.SET_STACK_PRIMARY_ASSET: {
544-
//Have to unstack then restack assets in timeline in order for the currently removed new primary asset to be made visible.
545-
updateUnstackedAssetInTimeline(
546-
timelineManager,
547-
action.stack.assets.map((asset) => toTimelineAsset(asset)),
548-
);
549-
updateStackedAssetInTimeline(timelineManager, {
550-
stack: action.stack,
551-
toDeleteIds: action.stack.assets
552-
.filter((asset) => asset.id !== action.stack.primaryAssetId)
553-
.map((asset) => asset.id),
554-
});
539+
refreshStackedAssetInTimeline(timelineManager, action.stack, true);
555540
break;
556541
}
557542
}

web/src/lib/utils/actions.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { notificationController, NotificationType } from '$lib/components/shared
22
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
33
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
44
import type { StackResponse } from '$lib/utils/asset-utils';
5-
import { AssetVisibility, deleteAssets as deleteBulk, restoreAssets } from '@immich/sdk';
5+
import { toTimelineAsset } from '$lib/utils/timeline-util';
6+
import { AssetVisibility, deleteAssets as deleteBulk, restoreAssets, type StackResponseDto } from '@immich/sdk';
67
import { t } from 'svelte-i18n';
78
import { get } from 'svelte/store';
89
import { handleError } from './handle-error';
@@ -100,3 +101,26 @@ export function updateUnstackedAssetInTimeline(timelineManager: TimelineManager,
100101

101102
timelineManager.addAssets(assets);
102103
}
104+
105+
export function refreshStackedAssetInTimeline(
106+
timelineManager: TimelineManager,
107+
stack: StackResponseDto,
108+
addPrimaryAsset: boolean = false,
109+
) {
110+
if (stack != undefined) {
111+
if (addPrimaryAsset) {
112+
timelineManager.addAssets(
113+
stack.assets.filter((a) => a.id === stack.primaryAssetId).map((a) => toTimelineAsset(a)),
114+
);
115+
}
116+
timelineManager.updateAssetOperation([stack.primaryAssetId], (asset) => {
117+
asset.stack = {
118+
id: stack.id,
119+
primaryAssetId: stack.primaryAssetId,
120+
assetCount: stack.assets.length,
121+
};
122+
return { remove: false };
123+
});
124+
timelineManager.removeAssets(stack.assets.filter((a) => a.id !== stack.primaryAssetId).map(({ id }) => id));
125+
}
126+
}

0 commit comments

Comments
 (0)