@@ -9,15 +9,12 @@ function SearchBarChild({ initialSubjects }: { initialSubjects: string[] }) {
99 const router = useRouter ( ) ;
1010 const [ searchText , setSearchText ] = useState ( "" ) ;
1111 const [ suggestions , setSuggestions ] = useState < string [ ] > ( [ ] ) ;
12- const [ isSearching , setIsSearching ] = useState ( false ) ;
1312 const [ subjects ] = useState < string [ ] > ( initialSubjects ) ;
1413 const suggestionsRef = useRef < HTMLUListElement | null > ( null ) ;
15- const inputRef = useRef < HTMLInputElement | null > ( null ) ;
1614
1715 const handleSearchChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
1816 const text = e . target . value ;
1917 setSearchText ( text ) ;
20- setIsSearching ( true ) ;
2118
2219 if ( text . length > 1 && subjects . length > 0 ) {
2320 const filteredSuggestions = subjects . filter ( ( subject ) =>
@@ -32,18 +29,15 @@ function SearchBarChild({ initialSubjects }: { initialSubjects: string[] }) {
3229 const handleSelectSuggestion = ( suggestion : string ) => {
3330 setSearchText ( suggestion ) ;
3431 setSuggestions ( [ ] ) ;
35- setIsSearching ( false ) ;
3632 router . push ( `/catalogue?subject=${ encodeURIComponent ( suggestion ) } ` ) ;
3733 } ;
3834
3935 const handleClickOutside = ( event : MouseEvent ) => {
4036 if (
4137 suggestionsRef . current &&
42- ! suggestionsRef . current . contains ( event . target as Node ) &&
43- ! inputRef . current ?. contains ( event . target as Node )
38+ ! suggestionsRef . current . contains ( event . target as Node )
4439 ) {
4540 setSuggestions ( [ ] ) ;
46- setIsSearching ( false ) ;
4741 }
4842 } ;
4943
@@ -55,39 +49,35 @@ function SearchBarChild({ initialSubjects }: { initialSubjects: string[] }) {
5549 } , [ ] ) ;
5650
5751 return (
58- < div className = "mx-4 md:mx-0" >
52+ < div className = "mx-4 md:mx-0 play " >
5953 < form
6054 className = "w-full max-w-xl"
6155 onSubmit = { ( e ) => {
6256 e . preventDefault ( ) ;
6357 if ( searchText ) {
64- setIsSearching ( false ) ;
6558 router . push ( `/catalogue?subject=${ encodeURIComponent ( searchText ) } ` ) ;
6659 }
6760 } }
6861 >
6962 < div className = "relative" >
7063 < Input
71- ref = { inputRef }
7264 type = "text"
7365 value = { searchText }
7466 onChange = { handleSearchChange }
75- onFocus = { ( ) => setIsSearching ( true ) }
7667 placeholder = "Search by subject..."
77- className = "text-md w-full rounded-full border bg-[#434dba] px-4 py-6 pr-10 font-sans tracking-wider text-white shadow-sm placeholder:text-white focus:outline-none focus:ring-2"
68+ className = "text-md w-full rounded-lg play bg-[#B2B8FF] dark:bg-[#7480FF66] px-4 py-6 pr-10 font-sans tracking-wider dark: text-white text-black shadow-sm placeholder:dark: text-white placeholder:text-black focus:outline-none focus:ring-2"
7869 />
7970 < button
8071 type = "submit"
8172 className = "absolute inset-y-0 right-0 flex items-center pr-3"
8273 >
83- < Search className = "h-5 w-5 text-white" />
74+ < Search className = "h-5 w-5 text-black dark:text- white" />
8475 </ button >
85- { isSearching &&
86- ( suggestions . length > 0 ||
87- ( searchText . length > 1 && subjects . length > 0 ) ) && (
76+ { ( suggestions . length > 0 ||
77+ ( searchText . length > 1 && subjects . length > 0 ) ) && (
8878 < ul
8979 ref = { suggestionsRef }
90- className = "absolute z-20 mx-0.5 mt-2 w-full max-w-xl rounded-md border border-[#434dba] bg-white text-center shadow-lg dark:bg-[#030712] md:mx-0"
80+ className = "absolute z-20 mx-0.5 mt-2 w-full max-w-xl rounded-md bg-white text-center shadow-lg dark:bg-[#030712] md:mx-0"
9181 >
9282 { suggestions . length > 0 ? (
9383 suggestions . map ( ( suggestion , index ) => (
@@ -112,4 +102,4 @@ function SearchBarChild({ initialSubjects }: { initialSubjects: string[] }) {
112102 ) ;
113103}
114104
115- export default SearchBarChild ;
105+ export default SearchBarChild ;
0 commit comments