2024-02-14 14:09:49 +01:00
|
|
|
import { getKey } from '$lib/utils';
|
2024-02-14 15:38:57 +01:00
|
|
|
import { getAssetInfo, type AssetResponseDto } from '@immich/sdk';
|
2023-08-01 03:27:56 +02:00
|
|
|
import { writable } from 'svelte/store';
|
|
|
|
|
|
|
|
function createAssetViewingStore() {
|
|
|
|
const viewingAssetStoreState = writable<AssetResponseDto>();
|
2024-03-14 22:12:32 +01:00
|
|
|
const preloadAssets = writable<AssetResponseDto[]>([]);
|
2023-08-01 03:27:56 +02:00
|
|
|
const viewState = writable<boolean>(false);
|
|
|
|
|
2024-04-04 03:20:54 +02:00
|
|
|
const setAsset = (asset: AssetResponseDto, assetsToPreload: AssetResponseDto[] = []) => {
|
|
|
|
preloadAssets.set(assetsToPreload);
|
|
|
|
viewingAssetStoreState.set(asset);
|
2023-08-01 03:27:56 +02:00
|
|
|
viewState.set(true);
|
|
|
|
};
|
|
|
|
|
2024-04-04 03:20:54 +02:00
|
|
|
const setAssetId = async (id: string) => {
|
|
|
|
const asset = await getAssetInfo({ id, key: getKey() });
|
|
|
|
setAsset(asset);
|
|
|
|
};
|
|
|
|
|
2023-08-01 03:27:56 +02:00
|
|
|
const showAssetViewer = (show: boolean) => {
|
|
|
|
viewState.set(show);
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
asset: {
|
|
|
|
subscribe: viewingAssetStoreState.subscribe,
|
|
|
|
},
|
2024-03-14 22:12:32 +01:00
|
|
|
preloadAssets: {
|
|
|
|
subscribe: preloadAssets.subscribe,
|
|
|
|
},
|
2023-08-01 03:27:56 +02:00
|
|
|
isViewing: {
|
|
|
|
subscribe: viewState.subscribe,
|
|
|
|
set: viewState.set,
|
|
|
|
},
|
2024-04-04 03:20:54 +02:00
|
|
|
setAsset,
|
2023-08-01 03:27:56 +02:00
|
|
|
setAssetId,
|
|
|
|
showAssetViewer,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export const assetViewingStore = createAssetViewingStore();
|