Skip to content

Commit e7dc028

Browse files
rotate hint every 7 seconds
1 parent 3913b3f commit e7dc028

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Diff for: src/components/search/SearchBar/searchBar.tsx

+17-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ const SearchBar = ({
7474
}
7575
}, [router.isReady, router.query.searchTerms]); // useEffect is called every time the query changes
7676

77+
const searchBarHints = [
78+
'ex. GOVT 2306, Sara Johnson',
79+
'ex. CS 1200, CS 2337',
80+
'ex. MATH 2418',
81+
'ex. John Cole, Jason Smith',
82+
];
83+
const [searchBarHintIndex, setSearchBarHintIndex] = useState<number>(1);
84+
85+
useEffect(() => {
86+
const interval = setInterval(() => {
87+
setSearchBarHintIndex(Math.floor(Math.random() * 4));
88+
}, 7000);
89+
90+
return () => clearInterval(interval); // Cleanup when component unmounts
91+
}, []); // run on mount
92+
7793
// updateValue -> onSelect_internal -> updateQueries - clicking enter on an autocomplete suggestion in topMenu Searchbar
7894
// updateValue -> onSelect_internal -> onSelect (custom function) - clicking enter on an autocomplete suggestion in home page SearchBar
7995
// params.inputProps.onKeyDown -> handleKeyDown -> onSelect_internal -> updateQueries/onSelect - clicking enter in the SearchBar
@@ -263,7 +279,7 @@ const SearchBar = ({
263279
{...params}
264280
variant="outlined"
265281
className={input_className}
266-
placeholder="ex. GOVT 2306 Sara Johnson"
282+
placeholder={searchBarHints[searchBarHintIndex]}
267283
//eslint-disable-next-line jsx-a11y/no-autofocus
268284
autoFocus={autoFocus}
269285
/>

0 commit comments

Comments
 (0)