mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-21 06:59:17 -04:00
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { useMemo } from 'react';
|
|
import { getExplorerItemData, type ExplorerItem } from '@sd/client';
|
|
import { ExplorerParamsSchema } from '~/app/route-schemas';
|
|
import { useZodSearchParams } from '~/hooks';
|
|
|
|
import { flattenThumbnailKey, useExplorerStore } from './store';
|
|
|
|
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]);
|
|
}
|
|
|
|
export const pubIdToString = (pub_id: number[]) =>
|
|
pub_id.map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
|
|
export const uniqueId = (item: ExplorerItem | { pub_id: number[] }) => {
|
|
if ('pub_id' in item) return pubIdToString(item.pub_id);
|
|
|
|
const { type } = item;
|
|
|
|
switch (type) {
|
|
case 'NonIndexedPath':
|
|
return item.item.path;
|
|
default:
|
|
return pubIdToString(item.item.pub_id);
|
|
}
|
|
};
|