Files
spacedrive/interface/hooks/useExplorerStore.tsx
Vítor Vasconcellos 3304e8f6ce QuickPreview Component (Needs test on MacOS) (#665)
* Add QuickPreview Component
 - Improve the handling of Range requests
 - Implement logic to answer HEAD and OPTIONS methods
 - Handle CORS pre-flight requests
 - Expand accepted file types
 - Improve error handling of invalid Range requests

* Fix linter errors
 - Add `use std::cmp::min` to custom_uri (Required on MacOS & Windows)
 - Improve logic for retrieving file information in QuickPreview.tsx

* More linter errors

* Simplify `QuickPreview` by extracting the logic for choosing the file preview tag to a `FilePreview` component
 - Fix the typo in `QuickPreview` props name
 - Remove the unused `handleMedia` ref
 - Move the remaining `QuickPreview` logic to the `transitions` callback
 - Simplify the `cors` return type in `custom_uri.rs`

* Refactor range handling in `handle_file` function
 - Move range handling logic to the initialization of the `range` variable
 - Replace `if let` with `match` to reduce code duplication
 - Don't export FilePreview
 - Export QuickPreviewProps

* Fix typo in `RangeNotSatisfiable` error message
 - Remove redundant variables

* Fixing cas_id generation on watcher
Some improvements on watcher file creation

* Rust fmt

---------

Co-authored-by: Ericson Soares <ericson.ds999@gmail.com>
Co-authored-by: Jamie Pine <ijamespine@me.com>
2023-04-05 21:15:13 -07:00

68 lines
1.7 KiB
TypeScript

import { proxy, useSnapshot } from 'valtio';
import { ExplorerItem } from '@sd/client';
import { resetStore } from '@sd/client/src/stores/util';
export type ExplorerLayoutMode = 'rows' | 'grid' | 'columns' | 'media';
export enum ExplorerKind {
Location,
Tag,
Space
}
export type CutCopyType = 'Cut' | 'Copy';
const state = {
locationId: null as number | null,
layoutMode: 'grid' as ExplorerLayoutMode,
gridItemSize: 100,
listItemSize: 40,
selectedRowIndex: 1,
showBytesInGridView: true,
tagAssignMode: false,
showInspector: false,
multiSelectIndexes: [] as number[],
contextMenuObjectId: null as number | null,
contextMenuActiveObject: null as object | null,
newThumbnails: {} as Record<string, boolean>,
cutCopyState: {
sourceLocationId: 0,
sourcePathId: 0,
actionType: 'Cut',
active: false
},
quickViewObject: null as ExplorerItem | null
};
// 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() {
// const { library } = useLibraryContext();
// useEffect(() => {
// explorerStore.reset();
// }, [library.uuid]);
return useSnapshot(explorerStore);
}
export function getExplorerStore() {
return explorerStore;
}