Files
spacedrive/interface/app/$libraryId/Explorer/util.ts
ameer2468 0a4c1f41e7 Job Manager improvement & refactor (#783)
* d

* wip

* Nit: margin and padding tweak

* UI design tweaks

* Update Job.tsx

* Improve UI

* [WIP] - Refactor job manager

* remove invalidate explorer event on thumb generation. the event above performs atomic updates on the front end when new thumbnails are generated, now just need to make that work

* prettier formatting + removed unused imports

* UI tweaks

* progress bar width adjustment

* tweaks

* fix em

* fix thumbnail generation

* fix progress bar

* fix time

---------

Co-authored-by: Jamie Pine <ijamespine@me.com>
Co-authored-by: Brendan Allan <brendonovich@outlook.com>
Co-authored-by: Oscar Beaumont <oscar@otbeaumont.me>
2023-05-08 22:31:49 +00:00

35 lines
1.1 KiB
TypeScript

import { z } from 'zod';
import { ExplorerItem, ObjectKind, ObjectKindKey, isObject, isPath } from '@sd/client';
import { useZodSearchParams } from '~/hooks';
export function getExplorerItemData(data: ExplorerItem, newThumbnails?: Record<string, boolean>) {
const objectData = getItemObject(data);
const filePath = getItemFilePath(data);
return {
cas_id: filePath?.cas_id || null,
isDir: isPath(data) && data.item.is_dir,
kind: (ObjectKind[objectData?.kind ?? 0] as ObjectKindKey) || null,
newThumb :!!newThumbnails?.[filePath?.cas_id || ''],
hasThumbnail: data.has_thumbnail || !!newThumbnails?.[filePath?.cas_id || ''] || false,
extension: filePath?.extension || null
};
}
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 const SEARCH_PARAMS = z.object({
path: z.string().default(''),
limit: z.coerce.number().default(100)
});
export function useExplorerSearchParams() {
return useZodSearchParams(SEARCH_PARAMS);
}