Files
spacedrive/interface/app/$libraryId/Explorer/util.ts
T
a1ed97b702 [ENG-816, ENG-821] Re-implement reveal in finder + ContextMenu overhaul (#1029)
* mostly there

* native opening working

* more

* cleanup

* reorganise

* remove unnecessary import

* uncomment some stuff

* spacing

* store quickview ref inside provider

* fix linting

* clippy

---------

Co-authored-by: Utku <74243531+utkubakir@users.noreply.github.com>
Co-authored-by: Jamie Pine <32987599+jamiepine@users.noreply.github.com>
2023-06-27 15:34:53 +00:00

50 lines
1.4 KiB
TypeScript

import { useMemo } from 'react';
import { ExplorerItem, FilePathSearchOrdering, getExplorerItemData } from '@sd/client';
import { ExplorerParamsSchema } from '~/app/route-schemas';
import { useZodSearchParams } from '~/hooks';
import { flattenThumbnailKey, useExplorerStore } from './store';
export function useExplorerOrder(): FilePathSearchOrdering | undefined {
const explorerStore = useExplorerStore();
const ordering = useMemo(() => {
if (explorerStore.orderBy === 'none') return undefined;
const obj = {};
explorerStore.orderBy.split('.').reduce((acc, next, i, all) => {
if (all.length - 1 === i) acc[next] = explorerStore.orderByDirection;
else acc[next] = {};
return acc[next];
}, obj as any);
return obj as FilePathSearchOrdering;
}, [explorerStore.orderBy, explorerStore.orderByDirection]);
return ordering;
}
export function useExplorerSearchParams() {
return useZodSearchParams(ExplorerParamsSchema);
}
export function useExplorerItemData(explorerItem: ExplorerItem) {
const explorerStore = useExplorerStore();
const newThumbnail = !!(
explorerItem.thumbnail_key &&
explorerStore.newThumbnails.has(flattenThumbnailKey(explorerItem.thumbnail_key))
);
return useMemo(() => {
const itemData = getExplorerItemData(explorerItem);
if (!itemData.hasLocalThumbnail) {
itemData.hasLocalThumbnail = newThumbnail;
}
return itemData;
}, [explorerItem, newThumbnail]);
}