feat(web): preload assets in photo-viewer (#7920)

* feat(web): preload assets in photo-viewer

* PR feedback

---------

Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
Sam Holton
2024-03-14 17:12:32 -04:00
committed by GitHub
parent 582cdcab82
commit ab4b8eca15
4 changed files with 66 additions and 13 deletions

View File

@@ -4,10 +4,23 @@ import { writable } from 'svelte/store';
function createAssetViewingStore() {
const viewingAssetStoreState = writable<AssetResponseDto>();
const preloadAssets = writable<AssetResponseDto[]>([]);
const viewState = writable<boolean>(false);
const setAssetId = async (id: string) => {
const setAssetId = async (id: string, preloadIds?: string[]) => {
const data = await getAssetInfo({ id, key: getKey() });
if (preloadIds) {
const preloadList = [];
for (const preloadId of preloadIds) {
if (preloadId) {
const preloadAsset = await getAssetInfo({ id: preloadId, key: getKey() });
preloadList.push(preloadAsset);
}
}
preloadAssets.set(preloadList);
}
viewingAssetStoreState.set(data);
viewState.set(true);
};
@@ -20,6 +33,9 @@ function createAssetViewingStore() {
asset: {
subscribe: viewingAssetStoreState.subscribe,
},
preloadAssets: {
subscribe: preloadAssets.subscribe,
},
isViewing: {
subscribe: viewState.subscribe,
set: viewState.set,