mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-21 15:07:54 -04:00
* init * changes * Now updating statistics once a minute * More robust statistics updater * Concurrency is hard * improvements to stats * refactor * adjust setting back/forward padding so it matches top bar * refactor sidebar * rename * setting up screens * some changes * Co-authored-by: Brendan Allan <Brendonovich@users.noreply.github.com> * yes * yes2 * refactored explorerItem.ts * important explorer code shouldn't be thrown away in a util moment * support for multiple thumbnails in ExplorerItem * clippy * move debug * yes * label filters * ts * comment out unconnected stuff * added .mid for midi files --------- Co-authored-by: Ericson Fogo Soares <ericson.ds999@gmail.com> Co-authored-by: Brendan Allan <brendonovich@outlook.com>
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import { useMemo } from 'react';
|
|
import { getExplorerItemData, useSelector, type ExplorerItem } from '@sd/client';
|
|
import { ExplorerParamsSchema } from '~/app/route-schemas';
|
|
import { useZodSearchParams } from '~/hooks';
|
|
|
|
import { explorerStore, flattenThumbnailKey } from './store';
|
|
|
|
export function useExplorerSearchParams() {
|
|
return useZodSearchParams(ExplorerParamsSchema);
|
|
}
|
|
|
|
export function useExplorerItemData(explorerItem: ExplorerItem) {
|
|
const newThumbnail = useSelector(explorerStore, (s) => {
|
|
const firstThumbnail =
|
|
explorerItem.type === 'Label'
|
|
? explorerItem.thumbnails?.[0]
|
|
: 'thumbnail' in explorerItem && explorerItem.thumbnail;
|
|
|
|
return !!(firstThumbnail && s.newThumbnails.has(flattenThumbnailKey(firstThumbnail)));
|
|
});
|
|
|
|
return useMemo(() => {
|
|
const itemData = getExplorerItemData(explorerItem);
|
|
|
|
if (!itemData.hasLocalThumbnail) {
|
|
itemData.hasLocalThumbnail = newThumbnail;
|
|
}
|
|
|
|
return itemData;
|
|
}, [explorerItem, newThumbnail]);
|
|
}
|
|
|
|
export type ExplorerItemData = ReturnType<typeof useExplorerItemData>;
|
|
|
|
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;
|
|
case 'SpacedropPeer':
|
|
return item.item.name;
|
|
default:
|
|
return pubIdToString(item.item.pub_id);
|
|
}
|
|
};
|