1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-10 13:56:47 +01:00
immich/web/src/lib/stores/asset-viewing.store.ts
2024-04-03 21:20:54 -04:00

42 lines
1.1 KiB
TypeScript

import { getKey } from '$lib/utils';
import { getAssetInfo, type AssetResponseDto } from '@immich/sdk';
import { writable } from 'svelte/store';
function createAssetViewingStore() {
const viewingAssetStoreState = writable<AssetResponseDto>();
const preloadAssets = writable<AssetResponseDto[]>([]);
const viewState = writable<boolean>(false);
const setAsset = (asset: AssetResponseDto, assetsToPreload: AssetResponseDto[] = []) => {
preloadAssets.set(assetsToPreload);
viewingAssetStoreState.set(asset);
viewState.set(true);
};
const setAssetId = async (id: string) => {
const asset = await getAssetInfo({ id, key: getKey() });
setAsset(asset);
};
const showAssetViewer = (show: boolean) => {
viewState.set(show);
};
return {
asset: {
subscribe: viewingAssetStoreState.subscribe,
},
preloadAssets: {
subscribe: preloadAssets.subscribe,
},
isViewing: {
subscribe: viewState.subscribe,
set: viewState.set,
},
setAsset,
setAssetId,
showAssetViewer,
};
}
export const assetViewingStore = createAssetViewingStore();