refactor(web): folders store (#14305)

* refactor(web): folders store

* use typescript private
This commit is contained in:
Michel Heusschen 2024-11-23 20:22:13 +01:00 committed by GitHub
parent 454836b551
commit c33b918d74
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 52 additions and 81 deletions

View file

@ -0,0 +1,45 @@
import {
getAssetsByOriginalPath,
getUniqueOriginalPaths,
/**
* TODO: Incorrect type
*/
type AssetResponseDto,
} from '@immich/sdk';
type AssetCache = {
[path: string]: AssetResponseDto[];
};
class FoldersStore {
private initialized = false;
uniquePaths = $state<string[]>([]);
assets = $state<AssetCache>({});
async fetchUniquePaths() {
if (this.initialized) {
return;
}
this.initialized = true;
const uniquePaths = await getUniqueOriginalPaths();
this.uniquePaths.push(...uniquePaths);
this.uniquePaths.sort();
}
async fetchAssetsByPath(path: string) {
if (this.assets[path]) {
return;
}
this.assets[path] = await getAssetsByOriginalPath({ path });
}
clearCache() {
this.initialized = false;
this.uniquePaths = [];
this.assets = {};
}
}
export const foldersStore = new FoldersStore();