MCPcopy Create free account
hub / github.com/andylow92/file-system-like-github / SearchDialog

Function SearchDialog

apps/web/src/components/SearchDialog.tsx:32–213  ·  view source on GitHub ↗
({ open, onClose, onSelectFile }: SearchDialogProps)

Source from the content-addressed store, hash-verified

30 * - Hybrid: fuses Text + Semantic via Reciprocal Rank Fusion (best of both).
31 */
32export function SearchDialog({ open, onClose, onSelectFile }: SearchDialogProps) {
33 const [mode, setMode] = useState<SearchMode>('text');
34 const [query, setQuery] = useState('');
35 const [items, setItems] = useState<DisplayItem[]>([]);
36 const [activeIndex, setActiveIndex] = useState(0);
37 const [error, setError] = useState<string | null>(null);
38 const inputRef = useRef<HTMLInputElement>(null);
39
40 useEffect(() => {
41 if (open) {
42 setMode('text');
43 setQuery('');
44 setItems([]);
45 setActiveIndex(0);
46 setError(null);
47 requestAnimationFrame(() => inputRef.current?.focus());
48 }
49 }, [open]);
50
51 useEffect(() => {
52 if (!open) {
53 return;
54 }
55
56 const trimmed = query.trim();
57 if (!trimmed) {
58 setItems([]);
59 setError(null);
60 return;
61 }
62
63 let cancelled = false;
64 const handle = window.setTimeout(async () => {
65 try {
66 const next = await runSearch(mode, trimmed);
67 if (!cancelled) {
68 setItems(next);
69 setActiveIndex(0);
70 setError(null);
71 }
72 } catch (err: unknown) {
73 if (!cancelled) {
74 setError(getErrorMessage(err));
75 setItems([]);
76 }
77 }
78 }, 150);
79
80 return () => {
81 cancelled = true;
82 window.clearTimeout(handle);
83 };
84 }, [query, mode, open]);
85
86 if (!open) {
87 return null;
88 }
89

Callers

nothing calls this directly

Calls 3

getErrorMessageFunction · 0.90
runSearchFunction · 0.85
chooseFunction · 0.85

Tested by

no test coverage detected