mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-20 06:28:14 -04:00
* 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>
35 lines
1.1 KiB
TypeScript
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);
|
|
}
|