2023-08-03 03:57:11 +02:00
|
|
|
import { AssetBucket, AssetGridState, BucketPosition, Viewport } from '$lib/models/asset-grid-state';
|
|
|
|
import type { AssetCountByTimeBucket } from '@api';
|
2022-09-04 15:34:39 +02:00
|
|
|
|
2023-08-01 03:27:56 +02:00
|
|
|
export interface AssetStore {
|
2023-08-03 03:57:11 +02:00
|
|
|
init: (viewport: Viewport, data: AssetCountByTimeBucket[], userId: string | undefined) => void;
|
|
|
|
|
|
|
|
// bucket
|
|
|
|
loadBucket: (bucket: string, position: BucketPosition) => Promise<void>;
|
|
|
|
updateBucket: (bucket: string, actualBucketHeight: number) => number;
|
|
|
|
cancelBucket: (bucket: AssetBucket) => void;
|
|
|
|
|
|
|
|
// asset
|
2023-08-01 03:27:56 +02:00
|
|
|
removeAsset: (assetId: string) => void;
|
|
|
|
updateAsset: (assetId: string, isFavorite: boolean) => void;
|
2023-08-03 03:57:11 +02:00
|
|
|
|
|
|
|
// asset navigation
|
|
|
|
getNextAssetId: (assetId: string) => Promise<string | null>;
|
|
|
|
getPreviousAssetId: (assetId: string) => Promise<string | null>;
|
|
|
|
|
|
|
|
// store
|
2023-08-01 03:27:56 +02:00
|
|
|
subscribe: (run: (value: AssetGridState) => void, invalidate?: (value?: AssetGridState) => void) => () => void;
|
|
|
|
}
|
2022-09-04 15:34:39 +02:00
|
|
|
|
2023-08-01 03:27:56 +02:00
|
|
|
export function createAssetStore(): AssetStore {
|
2023-08-03 03:57:11 +02:00
|
|
|
const store = new AssetGridState();
|
2023-08-01 03:27:56 +02:00
|
|
|
|
2023-07-01 06:50:47 +02:00
|
|
|
return {
|
2023-08-03 03:57:11 +02:00
|
|
|
init: store.init.bind(store),
|
|
|
|
loadBucket: store.loadBucket.bind(store),
|
|
|
|
updateBucket: store.updateBucket.bind(store),
|
|
|
|
cancelBucket: store.cancelBucket.bind(store),
|
|
|
|
removeAsset: store.removeAsset.bind(store),
|
|
|
|
updateAsset: store.updateAsset.bind(store),
|
|
|
|
getNextAssetId: store.getNextAssetId.bind(store),
|
|
|
|
getPreviousAssetId: store.getPreviousAssetId.bind(store),
|
|
|
|
subscribe: store.subscribe,
|
2023-07-01 06:50:47 +02:00
|
|
|
};
|
2022-09-04 15:34:39 +02:00
|
|
|
}
|