File browser as widget

This commit is contained in:
2026-02-17 19:23:01 +00:00
parent 0746844d6f
commit 21213c281d
27 changed files with 23 additions and 34 deletions
@@ -0,0 +1,23 @@
import { useCallback } from 'react';
import { useUserState } from '@/state/useUserState';
type PinnedFile = { path: string; name: string; pinnedAt: number };
export const usePinnedFiles = () => {
const [pinned, setPinned] = useUserState<PinnedFile[]>('pinnedFiles', []);
const togglePin = useCallback(
(path: string, name: string) => {
setPinned((prev) => {
const exists = prev.some((f) => f.path === path);
if (exists) return prev.filter((f) => f.path !== path);
return [{ path, name, pinnedAt: Date.now() }, ...prev];
});
},
[setPinned],
);
const isPinned = useCallback((path: string) => pinned.some((f) => f.path === path), [pinned]);
return { pinned, togglePin, isPinned };
};