Files
spacedrive/interface/app/$libraryId/Explorer/util.ts
Vítor Vasconcellos 0d3805339e [ENG-591] - Fix some funky behaviors (#827)
* WIP

* Some minor fixes for light theme
 - Fix `useIsDark` not reading the initial theme value (only reacting to theme changes)
 - Fix `Inspector` always showing a dark image when no item was selected
 - Fix `Thumb` video extension using black text on light theme

* Improve form error messages
 - Fix `addLocationDialog` not registering the path input
 - Remove `@hookform/error-message`

* Fix Dialog not respecting max-width
 - Fix ErrorMessage animation jumping

* A lot of misc fixes
 - Implement an `useExplorerItemData` (cleaner fix for thumbnail flicker)
 - Fix broken image showing for `Thumb` due a rece condition when props are updated
 - Implement an `ExternalObject` component that hacks an alternative for `onLoad` and `onError` events for <object>
 - Fix `Overview` broken layout when `Inspector` is open and window is small
 - Improve `IndexerRuleEditor` UX in `AddLocationDialog`
 - Improve the way `IndexerRuleEditor` handles rules deletion
 - Fix `IndexerRuleEditor` closing the the new rule form even when the rule creation fails
 - Add an editable prop to `IndexerRuleEditor` to disable all editable functions
 - Fix `getIcon` fallbacking to Document instead of the dark version of an icon if it exists
 - Add some missing colors to white theme

* Format

* Fix Backup restore key dialog not resetting after error

* Feedback

* Format

* Normalize imports

* Fix ColorPicker export

* Fix Thumb video ext not showing in MediaView with show square thumbnails
 - Fix AddLocationDialog Error resetting when changing IndexRules
2023-05-20 03:11:10 +00:00

42 lines
1.2 KiB
TypeScript

import { z } from 'zod';
import { ExplorerItem, ObjectKind, ObjectKindKey, Ordering, isObject, isPath } from '@sd/client';
import { useExplorerStore, useZodSearchParams } from '~/hooks';
export function useExplorerOrder(): Ordering | undefined {
const explorerStore = useExplorerStore();
if (explorerStore.orderBy === 'none') return undefined;
return { [explorerStore.orderBy]: explorerStore.orderByDirection === 'asc' } as Ordering;
}
export function getItemObject(data: ExplorerItem) {
return isObject(data) ? data.item : data.item.object;
}
export function getItemFilePath(data: ExplorerItem) {
return isObject(data) ? data.item.file_paths[0] : data.item;
}
export function getExplorerItemData(data: ExplorerItem) {
const filePath = getItemFilePath(data);
const objectData = getItemObject(data);
return {
kind: (ObjectKind[objectData?.kind ?? 0] as ObjectKindKey) || null,
casId: filePath?.cas_id || null,
isDir: isPath(data) && data.item.is_dir,
extension: filePath?.extension || null,
hasThumbnail: data.has_thumbnail
};
}
export const SEARCH_PARAMS = z.object({
path: z.string().optional(),
take: z.coerce.number().default(100)
});
export function useExplorerSearchParams() {
return useZodSearchParams(SEARCH_PARAMS);
}