2022-06-03 11:04:30 -05:00
|
|
|
import { writable, derived } from 'svelte/store';
|
|
|
|
|
|
|
|
|
|
export const downloadAssets = writable<Record<string, number>>({});
|
|
|
|
|
|
|
|
|
|
export const isDownloading = derived(downloadAssets, ($downloadAssets) => {
|
2022-07-26 12:28:07 -05:00
|
|
|
if (Object.keys($downloadAssets).length == 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-06-03 11:04:30 -05:00
|
|
|
|
2022-07-26 12:28:07 -05:00
|
|
|
return true;
|
|
|
|
|
});
|
2023-06-30 12:24:28 -04:00
|
|
|
|
|
|
|
|
const update = (key: string, value: number | null) => {
|
|
|
|
|
downloadAssets.update((state) => {
|
|
|
|
|
const newState = { ...state };
|
|
|
|
|
if (value === null) {
|
|
|
|
|
delete newState[key];
|
|
|
|
|
} else {
|
|
|
|
|
newState[key] = value;
|
|
|
|
|
}
|
|
|
|
|
return newState;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const clearDownload = (key: string) => update(key, null);
|
|
|
|
|
export const updateDownload = (key: string, value: number) => update(key, value);
|