refactor: asset viewing store (#27204)

This commit is contained in:
Jason Rasmussen
2026-03-26 13:22:40 -04:00
committed by GitHub
parent fb84c1cf61
commit 7877097b3f
20 changed files with 129 additions and 154 deletions
@@ -1,7 +1,10 @@
import { authManager } from '$lib/managers/auth-manager.svelte';
import type { ImageLoaderStatus } from '$lib/utils/adaptive-image-loader.svelte';
import { canCopyImageToClipboard } from '$lib/utils/asset-utils';
import { BaseEventManager } from '$lib/utils/base-event-manager.svelte';
import type { AssetGridRouteSearchParams } from '$lib/utils/navigation';
import { PersistedLocalStorage } from '$lib/utils/persisted';
import { getAssetInfo, type AssetResponseDto } from '@immich/sdk';
import type { ZoomImageWheelState } from '@zoom-image/core';
import { cubicOut } from 'svelte/easing';
@@ -21,7 +24,7 @@ export type Events = {
Copy: [];
};
export class AssetViewerManager extends BaseEventManager<Events> {
class AssetViewerManager extends BaseEventManager<Events> {
#zoomState = $state(createDefaultZoomState());
#animationFrameId: number | null = null;
@@ -40,6 +43,18 @@ export class AssetViewerManager extends BaseEventManager<Events> {
isPlayingMotionPhoto = $state(false);
isShowEditor = $state(false);
#viewingAssetStoreState = $state<AssetResponseDto>();
#viewState = $state<boolean>(false);
gridScrollTarget = $state<AssetGridRouteSearchParams | null | undefined>();
get asset() {
return this.#viewingAssetStoreState;
}
get isViewing() {
return this.#viewState;
}
get isImageLoading() {
return this.#isImageLoading;
}
@@ -145,6 +160,21 @@ export class AssetViewerManager extends BaseEventManager<Events> {
closeEditor() {
this.isShowEditor = false;
}
setAsset(asset: AssetResponseDto) {
this.#viewingAssetStoreState = asset;
this.#viewState = true;
}
async setAssetId(id: string): Promise<AssetResponseDto> {
const asset = await getAssetInfo({ ...authManager.params, id });
this.setAsset(asset);
return asset;
}
showAssetViewer(show: boolean) {
this.#viewState = show;
}
}
export const assetViewerManager = new AssetViewerManager();