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/upload.ts

46 lines
1 KiB
TypeScript
Raw Normal View History

import { writable, derived } from 'svelte/store';
import type { UploadAsset } from '../models/upload-asset';
function createUploadStore() {
const uploadAssets = writable<Array<UploadAsset>>([]);
const { subscribe } = uploadAssets;
const isUploading = derived(uploadAssets, ($uploadAssets) => {
return $uploadAssets.length > 0 ? true : false;
});
const addNewUploadAsset = (newAsset: UploadAsset) => {
uploadAssets.update((currentSet) => [...currentSet, newAsset]);
};
const updateProgress = (id: string, progress: number) => {
uploadAssets.update((uploadingAssets) => {
return uploadingAssets.map((asset) => {
if (asset.id == id) {
return {
...asset,
progress: progress
};
}
return asset;
});
});
};
const removeUploadAsset = (id: string) => {
uploadAssets.update((uploadingAsset) => uploadingAsset.filter((a) => a.id != id));
};
return {
subscribe,
isUploading,
addNewUploadAsset,
updateProgress,
removeUploadAsset
};
}
export const uploadAssetsStore = createUploadStore();