mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-21 06:59:17 -04:00
65 lines
1.6 KiB
TypeScript
65 lines
1.6 KiB
TypeScript
import { proxy, useSnapshot } from 'valtio';
|
|
import { onLibraryChange } from '@sd/client';
|
|
import { resetStore } from '@sd/client/src/stores/util';
|
|
|
|
export type ExplorerLayoutMode = 'list' | 'grid' | 'columns' | 'media';
|
|
|
|
export enum ExplorerKind {
|
|
Location,
|
|
Tag,
|
|
Space
|
|
}
|
|
|
|
export enum CutCopyType {
|
|
Cut,
|
|
Copy
|
|
}
|
|
|
|
const state = {
|
|
locationId: null as number | null,
|
|
layoutMode: 'grid' as ExplorerLayoutMode,
|
|
gridItemSize: 100,
|
|
listItemSize: 40,
|
|
selectedRowIndex: 1,
|
|
tagAssignMode: false,
|
|
showInspector: true,
|
|
multiSelectIndexes: [] as number[],
|
|
contextMenuObjectId: null as number | null,
|
|
contextMenuActiveObject: null as object | null,
|
|
newThumbnails: {} as Record<string, boolean>,
|
|
cutCopyState: {
|
|
sourceLocationId: 0,
|
|
sourcePathId: 0,
|
|
actionType: CutCopyType.Cut,
|
|
active: false
|
|
}
|
|
};
|
|
|
|
onLibraryChange(() => getExplorerStore().reset());
|
|
|
|
// Keep the private and use `useExplorerState` or `getExplorerStore` or you will get production build issues.
|
|
const explorerStore = proxy({
|
|
...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])
|
|
];
|
|
}
|
|
}
|
|
});
|
|
|
|
export function useExplorerStore() {
|
|
return useSnapshot(explorerStore);
|
|
}
|
|
|
|
export function getExplorerStore() {
|
|
return explorerStore;
|
|
}
|