MCPcopy Create free account
hub / github.com/TheCSir/TerminalStart / SearchWidget

Function SearchWidget

src/components/widgets/SearchWidget.tsx:14–84  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12];
13
14export const SearchWidget: React.FC = () => {
15 const [query, setQuery] = useState('');
16 const [engineIndex, setEngineIndex] = useState(0);
17
18 const inputRef = useRef<HTMLInputElement>(null);
19
20 // Persist engine selection
21 useEffect(() => {
22 const savedEngine = localStorage.getItem('tui-search-engine');
23 if (savedEngine) {
24 const index = ENGINES.findIndex(e => e.id === savedEngine);
25 if (index !== -1) setEngineIndex(index);
26 }
27 }, []);
28
29 const cycleEngine = () => {
30 const nextIndex = (engineIndex + 1) % ENGINES.length;
31 setEngineIndex(nextIndex);
32 localStorage.setItem('tui-search-engine', ENGINES[nextIndex].id);
33 inputRef.current?.focus();
34 };
35
36 const handleSearch = (e: React.FormEvent) => {
37 e.preventDefault();
38 if (!query.trim()) return;
39
40 const currentEngine = ENGINES[engineIndex];
41 window.open(currentEngine.url + encodeURIComponent(query), '_blank', 'noopener,noreferrer');
42 setQuery('');
43 inputRef.current?.blur();
44 };
45
46 const currentEngine = ENGINES[engineIndex];
47
48 return (
49 <div
50 className="h-full flex flex-col justify-center px-2 relative"
51 >
52 <form onSubmit={handleSearch} className="flex items-center gap-2 w-full z-20">
53 <button
54 type="button"
55 onClick={cycleEngine}
56 className="shrink-0 text-[var(--color-accent)] hover:text-[var(--color-fg)] font-bold font-mono transition-colors select-none"
57 title="Click to switch search engine"
58 >
59 [{currentEngine.label}]
60 </button>
61 <div className="flex-1 relative group">
62 <span className="absolute left-0 top-1/2 -translate-y-1/2 text-[var(--color-muted)] font-bold pointer-events-none">
63 &gt;
64 </span>
65 <input
66 ref={inputRef}
67 type="text"
68 value={query}
69 onChange={(e) => setQuery(e.target.value)}
70 className="w-full bg-transparent border-none outline-none text-[var(--color-fg)] placeholder-[var(--color-muted)] font-mono pl-4 focus:placeholder-opacity-50 h-full py-1"
71 placeholder="search..."

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected