spacedrive/interface/hooks/useExplorerStore.tsx

65 lines
1.6 KiB
TypeScript
Raw Normal View History

import { proxy, useSnapshot } from 'valtio';
Mobile - File Import (#443) * Fix File modal and Stats * Add disabled and loading state for dialog * Close library drowdown with drawer * catch Rust panics on mobile to prevent UB * Update packages * Move create lib dialog to container * Create library on onboarding * Cleanup metro config & update packages * onClose for Dialog & update library cache * Fix pods, downgrade react-native-svg * Fix lib switching, organization, start import modal * Add device size info * Revert merge + version upgrade/fix * Create Location & Remove placeholder data * Create default modal component * Check if the location already exists * Add media-library + prettier * fix build * Fix Xcode shellScript too * More small fixes * don't export bindings on mobile devices * Explorer store + cleanup * Explorer comp. & add flashlist * [WIP] Files in Locations & new file thumb * clean merge * Fix imports * Fix core on mobile * Add platform context to mobile * Refactor libraryStore * Add thumb url path to platform context * Try fixing app startup * Add zip and video to filethumb * Delete bindings.ts from mobile * Remove heroicons from mobile too * useForwardedRef hook * Media Library permission stuff * Clean import modal * remove valtio-persist from @sd/client * prevent Sentry capturing all events * refactor `@sd/client` to make it better for mobile * fix mobile splashscreen Just trust me bro * fix mobile draw active style * use custom valtioPersist for current library state * remove mobile lockfile It's now in the pnpm workspace so it shared the main one. * finally remove valtio-persist * remove 'mobile' from Platform as it's in interface Co-authored-by: Oscar Beaumont <oscar@otbeaumont.me>
2022-11-01 13:32:56 +00:00
import { resetStore } from '@sd/client/src/stores/util';
2022-09-05 01:20:22 +00:00
export type ExplorerLayoutMode = 'rows' | 'grid' | 'columns' | 'media';
2022-09-04 22:58:16 +00:00
export enum ExplorerKind {
Location,
Tag,
Space
}
export type CutCopyType = 'Cut' | 'Copy';
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,
tagAssignMode: false,
showInspector: false,
2022-09-04 22:58:16 +00:00
multiSelectIndexes: [] as number[],
contextMenuObjectId: null as number | null,
Mobile - File Import (#443) * Fix File modal and Stats * Add disabled and loading state for dialog * Close library drowdown with drawer * catch Rust panics on mobile to prevent UB * Update packages * Move create lib dialog to container * Create library on onboarding * Cleanup metro config & update packages * onClose for Dialog & update library cache * Fix pods, downgrade react-native-svg * Fix lib switching, organization, start import modal * Add device size info * Revert merge + version upgrade/fix * Create Location & Remove placeholder data * Create default modal component * Check if the location already exists * Add media-library + prettier * fix build * Fix Xcode shellScript too * More small fixes * don't export bindings on mobile devices * Explorer store + cleanup * Explorer comp. & add flashlist * [WIP] Files in Locations & new file thumb * clean merge * Fix imports * Fix core on mobile * Add platform context to mobile * Refactor libraryStore * Add thumb url path to platform context * Try fixing app startup * Add zip and video to filethumb * Delete bindings.ts from mobile * Remove heroicons from mobile too * useForwardedRef hook * Media Library permission stuff * Clean import modal * remove valtio-persist from @sd/client * prevent Sentry capturing all events * refactor `@sd/client` to make it better for mobile * fix mobile splashscreen Just trust me bro * fix mobile draw active style * use custom valtioPersist for current library state * remove mobile lockfile It's now in the pnpm workspace so it shared the main one. * finally remove valtio-persist * remove 'mobile' from Platform as it's in interface Co-authored-by: Oscar Beaumont <oscar@otbeaumont.me>
2022-11-01 13:32:56 +00:00
contextMenuActiveObject: null as object | null,
newThumbnails: {} as Record<string, boolean>,
cutCopyState: {
sourceLocationId: 0,
sourcePathId: 0,
actionType: 'Cut',
active: false
}
2022-09-04 22:58:16 +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])
];
}
}
});
export function useExplorerStore() {
// const { library } = useLibraryContext();
// useEffect(() => {
// explorerStore.reset();
// }, [library.uuid]);
return useSnapshot(explorerStore);
}
export function getExplorerStore() {
return explorerStore;
}