mirror of
https://github.com/immich-app/immich.git
synced 2025-12-18 09:13:15 +03:00
fix(web): update stack state in timeline (#17021)
* fix(web): update stack state in timeline * js docs * fix: handle state update from unstack action from gallery viewer * use navigate in View Stack notification --------- Co-authored-by: Snowknight26 <Snowknight26@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { notificationController, NotificationType } from '$lib/components/shared-components/notification/notification';
|
||||
import type { AssetStore } from '$lib/stores/assets-store.svelte';
|
||||
import type { StackResponse } from '$lib/utils/asset-utils';
|
||||
import { deleteAssets as deleteBulk, type AssetResponseDto } from '@immich/sdk';
|
||||
import { t } from 'svelte-i18n';
|
||||
import { get } from 'svelte/store';
|
||||
@@ -11,7 +13,7 @@ export type OnUnlink = (assets: { still: AssetResponseDto; motion: AssetResponse
|
||||
export type OnAddToAlbum = (ids: string[], albumId: string) => void;
|
||||
export type OnArchive = (ids: string[], isArchived: boolean) => void;
|
||||
export type OnFavorite = (ids: string[], favorite: boolean) => void;
|
||||
export type OnStack = (ids: string[]) => void;
|
||||
export type OnStack = (result: StackResponse) => void;
|
||||
export type OnUnstack = (assets: AssetResponseDto[]) => void;
|
||||
|
||||
export const deleteAssets = async (force: boolean, onAssetDelete: OnDelete, ids: string[]) => {
|
||||
@@ -30,3 +32,46 @@ export const deleteAssets = async (force: boolean, onAssetDelete: OnDelete, ids:
|
||||
handleError(error, $t('errors.unable_to_delete_assets'));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the asset stack state in the asset store based on the provided stack response.
|
||||
* This function updates the stack information so that the icon is shown for the primary asset
|
||||
* and removes any assets from the timeline that are marked for deletion.
|
||||
*
|
||||
* @param {AssetStore} assetStore - The asset store to update.
|
||||
* @param {StackResponse} stackResponse - The stack response containing the stack and assets to delete.
|
||||
*/
|
||||
export function updateStackedAssetInTimeline(assetStore: AssetStore, { stack, toDeleteIds }: StackResponse) {
|
||||
if (stack != undefined) {
|
||||
assetStore.updateAssetOperation([stack.primaryAssetId], (asset) => {
|
||||
asset.stack = {
|
||||
id: stack.id,
|
||||
primaryAssetId: stack.primaryAssetId,
|
||||
assetCount: stack.assets.length,
|
||||
};
|
||||
return { remove: false };
|
||||
});
|
||||
|
||||
assetStore.removeAssets(toDeleteIds);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the asset store to reflect the unstacked state of assets.
|
||||
* This function updates the stack property of each asset to undefined, effectively unstacking them.
|
||||
* It also adds the unstacked assets back to the asset store.
|
||||
*
|
||||
* @param assetStore - The asset store to update.
|
||||
* @param assets - The array of asset response DTOs to update in the asset store.
|
||||
*/
|
||||
export function updateUnstackedAssetInTimeline(assetStore: AssetStore, assets: AssetResponseDto[]) {
|
||||
assetStore.updateAssetOperation(
|
||||
assets.map((asset) => asset.id),
|
||||
(asset) => {
|
||||
asset.stack = undefined;
|
||||
return { remove: false };
|
||||
},
|
||||
);
|
||||
|
||||
assetStore.addAssets(assets);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user