2022-09-13 06:32:32 +00:00
|
|
|
import { proxy, useSnapshot } from 'valtio';
|
2022-11-01 13:32:56 +00:00
|
|
|
import { resetStore } from '@sd/client/src/stores/util';
|
2022-09-05 01:20:22 +00:00
|
|
|
|
2023-02-28 05:29:48 +00:00
|
|
|
export type ExplorerLayoutMode = 'rows' | 'grid' | 'columns' | 'media';
|
2022-09-04 22:58:16 +00:00
|
|
|
|
|
|
|
export enum ExplorerKind {
|
|
|
|
Location,
|
|
|
|
Tag,
|
|
|
|
Space
|
|
|
|
}
|
|
|
|
|
2023-02-14 05:27:11 +00:00
|
|
|
export type CutCopyType = 'Cut' | 'Copy';
|
2023-01-20 13:18:11 +00:00
|
|
|
|
2022-09-04 22:58:16 +00:00
|
|
|
const state = {
|
|
|
|
locationId: null as number | null,
|
|
|
|
layoutMode: 'grid' as ExplorerLayoutMode,
|
|
|
|
gridItemSize: 100,
|
|
|
|
listItemSize: 40,
|
|
|
|
selectedRowIndex: 1,
|
2022-10-21 05:49:15 +00:00
|
|
|
tagAssignMode: false,
|
2023-02-24 08:12:21 +00:00
|
|
|
showInspector: false,
|
2022-09-04 22:58:16 +00:00
|
|
|
multiSelectIndexes: [] as number[],
|
|
|
|
contextMenuObjectId: null as number | null,
|
2022-11-01 13:32:56 +00:00
|
|
|
contextMenuActiveObject: null as object | null,
|
2023-01-20 13:18:11 +00:00
|
|
|
newThumbnails: {} as Record<string, boolean>,
|
|
|
|
cutCopyState: {
|
|
|
|
sourceLocationId: 0,
|
|
|
|
sourcePathId: 0,
|
2023-02-14 05:27:11 +00:00
|
|
|
actionType: 'Cut',
|
2023-01-20 13:18:11 +00:00
|
|
|
active: false
|
|
|
|
}
|
2022-09-04 22:58:16 +00:00
|
|
|
};
|
|
|
|
|
2022-09-13 06:32:32 +00:00
|
|
|
// Keep the private and use `useExplorerState` or `getExplorerStore` or you will get production build issues.
|
|
|
|
const explorerStore = proxy({
|
2022-09-04 22:58:16 +00:00
|
|
|
...state,
|
|
|
|
reset: () => resetStore(explorerStore, state),
|
|
|
|
addNewThumbnail: (cas_id: string) => {
|
|
|
|
explorerStore.newThumbnails[cas_id] = true;
|
|
|
|
},
|
|
|
|
selectMore: (indexes: number[]) => {
|
|
|
|
if (!explorerStore.multiSelectIndexes.length && indexes.length) {
|
|
|
|
explorerStore.multiSelectIndexes = [explorerStore.selectedRowIndex, ...indexes];
|
|
|
|
} else {
|
|
|
|
explorerStore.multiSelectIndexes = [
|
|
|
|
...new Set([...explorerStore.multiSelectIndexes, ...indexes])
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-09-13 06:32:32 +00:00
|
|
|
|
|
|
|
export function useExplorerStore() {
|
2023-02-25 06:16:57 +00:00
|
|
|
// const { library } = useLibraryContext();
|
2023-02-23 09:56:32 +00:00
|
|
|
|
2023-02-25 06:16:57 +00:00
|
|
|
// useEffect(() => {
|
|
|
|
// explorerStore.reset();
|
|
|
|
// }, [library.uuid]);
|
2023-02-23 09:56:32 +00:00
|
|
|
|
2022-09-13 06:32:32 +00:00
|
|
|
return useSnapshot(explorerStore);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getExplorerStore() {
|
|
|
|
return explorerStore;
|
|
|
|
}
|