fix(web): prevent fetching asset info twice (#8486)

This commit is contained in:
Michel Heusschen
2024-04-04 03:20:54 +02:00
committed by GitHub
parent 0529076ed7
commit 66650f5944
8 changed files with 47 additions and 61 deletions
+9 -15
View File
@@ -7,24 +7,17 @@ function createAssetViewingStore() {
const preloadAssets = writable<AssetResponseDto[]>([]);
const viewState = writable<boolean>(false);
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);
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);
};
@@ -40,6 +33,7 @@ function createAssetViewingStore() {
subscribe: viewState.subscribe,
set: viewState.set,
},
setAsset,
setAssetId,
showAssetViewer,
};