@@ -4,37 +4,34 @@ import { startTextSearch, clearSearch } from '@/features/searchSlice';
44
55import { Input } from '@/components/ui/input' ;
66import { ThemeSelector } from '@/components/ThemeToggle' ;
7- import { Search } from 'lucide-react' ;
7+ import { Search } from 'lucide-react' ;
88import { selectAvatar , selectName } from '@/features/onboardingSelectors' ;
99import { convertFileSrc } from '@tauri-apps/api/core' ;
1010import { FaceSearchDialog } from '@/components/Dialog/FaceSearchDialog' ;
11+ import { useRef } from 'react' ;
1112
1213export function Navbar ( ) {
1314 const userName = useSelector ( selectName ) ;
1415 const userAvatar = useSelector ( selectAvatar ) ;
15-
16- const searchState = useSelector ( ( state : any ) => state . search ) ;
17- const isSearchActive = searchState . active && searchState . type === 'text' ;
18- const queryImage = searchState . queryImage ;
19-
16+ const queryImage = useSelector ( ( state : any ) => state . search . queryImage ) ;
2017 const dispatch = useDispatch ( ) ;
2118 const [ searchInput , setSearchInput ] = useState ( '' ) ;
19+ const inputRef = useRef < HTMLInputElement > ( null ) ;
2220
2321 // Debounce search
2422 useEffect ( ( ) => {
23+ const trimmed = searchInput . trim ( ) ;
24+
2525 const timer = setTimeout ( ( ) => {
26- if ( searchInput . trim ( ) . length > 0 ) {
27- dispatch ( startTextSearch ( searchInput . trim ( ) ) ) ;
28- } else if ( searchInput . trim ( ) . length === 0 && isSearchActive ) {
26+ if ( trimmed ) {
27+ dispatch ( startTextSearch ( trimmed ) ) ;
28+ } else {
2929 dispatch ( clearSearch ( ) ) ;
3030 }
3131 } , 500 ) ;
3232
3333 return ( ) => clearTimeout ( timer ) ;
34-
35- // use searchState
36- } , [ searchInput , dispatch , searchState . active , searchState . type ] ) ;
37-
34+ } , [ searchInput , dispatch ] ) ;
3835
3936 return (
4037 < div className = "sticky top-0 z-40 flex h-14 w-full items-center justify-between border-b pr-4 backdrop-blur" >
@@ -50,7 +47,6 @@ export function Navbar() {
5047 { /* Search Bar */ }
5148 < div className = "mx-auto flex max-w-md flex-1 justify-center px-4" >
5249 < div className = "dark:bg-muted/50 flex w-full items-center gap-1 rounded-md bg-neutral-100 px-1 py-1" >
53-
5450 { /* Query Image Preview */ }
5551 { queryImage && (
5652 < div className = "relative mr-2 ml-2" >
@@ -86,8 +82,9 @@ export function Navbar() {
8682
8783 { /* Search Icon */ }
8884 < button
89- className = "text-muted-foreground hover:bg-accent dark:hover:bg-accent/50 hover:text-foreground mx-1 cursor-pointer rounded-sm p-2"
90- title = "Search"
85+ onClick = { ( ) => inputRef . current ?. focus ( ) }
86+ className = "text-muted-foreground hover:bg-accent dark:hover:bg-accent/50 hover:text-foreground mx-1 rounded-sm p-2"
87+ title = "Focus search"
9188 >
9289 < Search className = "h-4 w-4" />
9390 </ button >
@@ -112,4 +109,4 @@ export function Navbar() {
112109 </ div >
113110 </ div >
114111 ) ;
115- }
112+ }
0 commit comments