@@ -19,14 +19,26 @@ function SearchBarChild({
1919 const [ suggestions , setSuggestions ] = useState < ICourseWithCount [ ] > ( [ ] ) ;
2020 const suggestionsRef = useRef < HTMLUListElement | null > ( null ) ;
2121 const [ fuzzy , setFuzzy ] = useState (
22- ( ) => new Fuse < ICourseWithCount > ( [ ] , { keys : [ "name" ] , threshold : 0.3 } ) ,
22+ ( ) =>
23+ new Fuse < ICourseWithCount > ( [ ] , {
24+ keys : [ "name" ] ,
25+ threshold : 0.3 ,
26+ ignoreLocation : true ,
27+ } ) ,
2328 ) ;
2429 const [ highlightedIndex , setHighlightedIndex ] = useState < number > ( - 1 ) ;
2530
2631 useEffect ( ( ) => {
2732 if ( initialSubjects && initialSubjects . length > 0 ) {
28- setFuzzy ( new Fuse ( initialSubjects , { keys : [ "name" ] , threshold : 0.3 } ) ) ;
33+ setFuzzy (
34+ new Fuse ( initialSubjects , {
35+ keys : [ "name" ] ,
36+ threshold : 0.3 ,
37+ ignoreLocation : true ,
38+ } ) ,
39+ ) ;
2940 }
41+ console . log ( initialSubjects ) ;
3042 } , [ initialSubjects ] ) ;
3143
3244 const handleSearchChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
@@ -95,24 +107,37 @@ function SearchBarChild({
95107 setHighlightedIndex ( ( prev ) => ( prev + 1 ) % suggestions . length ) ;
96108 } else if ( e . key === "ArrowUp" ) {
97109 e . preventDefault ( ) ;
98- setHighlightedIndex ( ( prev ) => ( prev - 1 + suggestions . length ) % suggestions . length ) ;
110+ setHighlightedIndex (
111+ ( prev ) =>
112+ ( prev - 1 + suggestions . length ) % suggestions . length ,
113+ ) ;
99114 } else if ( e . key === "Enter" ) {
100115 e . preventDefault ( ) ;
101- if ( highlightedIndex >= 0 && highlightedIndex < suggestions . length && suggestions [ highlightedIndex ] !== undefined ) {
116+ if (
117+ highlightedIndex >= 0 &&
118+ highlightedIndex < suggestions . length &&
119+ suggestions [ highlightedIndex ] !== undefined
120+ ) {
102121 handleSelectSuggestion ( suggestions [ highlightedIndex ] ) ;
103122 } else {
104- router . push ( `/catalogue?subject=${ encodeURIComponent ( searchText ) } ` ) ;
123+ router . push (
124+ `/catalogue?subject=${ encodeURIComponent ( searchText ) } ` ,
125+ ) ;
105126 setSuggestions ( [ ] ) ;
106127 }
107128 } else if ( e . key === "Tab" ) {
108129 e . preventDefault ( ) ;
109- if ( highlightedIndex == - 1 ) {
130+ if ( highlightedIndex == - 1 ) {
110131 if ( suggestions . length > 0 && suggestions [ 0 ] != undefined ) {
111132 setSearchText ( suggestions [ 0 ] . name || "" ) ;
112133 setSuggestions ( [ ] ) ;
113134 }
114- } else {
115- if ( highlightedIndex >= 0 && highlightedIndex < suggestions . length && suggestions [ highlightedIndex ] !== undefined ) {
135+ } else {
136+ if (
137+ highlightedIndex >= 0 &&
138+ highlightedIndex < suggestions . length &&
139+ suggestions [ highlightedIndex ] !== undefined
140+ ) {
116141 setSearchText ( suggestions [ highlightedIndex ] . name || "" ) ;
117142 setHighlightedIndex ( - 1 ) ;
118143 setSuggestions ( [ ] ) ;
@@ -134,15 +159,16 @@ function SearchBarChild({
134159 className = { `absolute z-20 w-full max-w-xl overflow-y-auto rounded-md rounded-t-none border border-t-0 bg-white text-center shadow-lg dark:bg-[#303771] md:mx-0` }
135160 style = { { maxHeight : "400px" } }
136161 >
137- { suggestions . map ( ( suggestion : ICourseWithCount , index ) => (
162+ { suggestions . map ( ( suggestion : ICourseWithCount , index ) => (
138163 < li
139164 key = { suggestion . _id }
140165 onClick = { ( ) => handleSelectSuggestion ( suggestion ) }
141- className = { `flex cursor-pointer items-center rounded p-2
142- ${ index === highlightedIndex
143- ? "bg-gray-200 dark:bg-gray-800"
144- : "hover:bg-gray-200 dark:hover:bg-gray-800" } `}
145- >
166+ className = { `flex cursor-pointer items-center rounded p-2 ${
167+ index === highlightedIndex
168+ ? "bg-gray-200 dark:bg-gray-800"
169+ : "hover:bg-gray-200 dark:hover:bg-gray-800"
170+ } `}
171+ >
146172 < div
147173 id = "paper_count"
148174 className = "mr-4 flex h-8 w-8 items-center justify-center rounded-md bg-[#171720] text-xs font-semibold text-white"
0 commit comments