diff --git a/frontend/src/components/scripts/ScriptFilterBar.tsx b/frontend/src/components/scripts/ScriptFilterBar.tsx new file mode 100644 index 00000000..3bbfea3d --- /dev/null +++ b/frontend/src/components/scripts/ScriptFilterBar.tsx @@ -0,0 +1,75 @@ +import { useEffect, useRef } from 'react' +import { Search } from 'lucide-react' +import { cn } from '@/lib/utils' +import { useScriptGeneratorStore } from '@/store/scriptGeneratorStore' + +interface Props { + inputValue: string + setInputValue: (value: string) => void +} + +export function ScriptFilterBar({ inputValue, setInputValue }: Props) { + const categories = useScriptGeneratorStore(s => s.categories) + const activeCategoryId = useScriptGeneratorStore(s => s.activeCategoryId) + const setCategory = useScriptGeneratorStore(s => s.setCategory) + const setSearch = useScriptGeneratorStore(s => s.setSearch) + + // Debounce: 300ms after the input value settles, push to store + const debounceRef = useRef | null>(null) + useEffect(() => { + if (debounceRef.current) clearTimeout(debounceRef.current) + debounceRef.current = setTimeout(() => { + setSearch(inputValue) + }, 300) + return () => { + if (debounceRef.current) clearTimeout(debounceRef.current) + } + }, [inputValue, setSearch]) + + return ( +
+ {/* Category pills */} +
+ + {categories.map(cat => ( + + ))} +
+ + {/* Search input */} +
+ + setInputValue(e.target.value)} + placeholder="Search templates…" + className="pl-8 pr-3 py-1.5 text-sm rounded-md border border-border bg-card text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-[rgba(6,182,212,0.3)] focus:ring-1 focus:ring-[rgba(6,182,212,0.2)] w-52" + /> +
+
+ ) +}