@@ -22,7 +22,8 @@ import * as motion from "motion/react-client";
2222// State Management
2323import { useAtom , useAtomValue } from 'jotai' ;
2424import { bigStateAtom , clientSettingsAtom , clientSettingsInitial } from '../../atoms/settingsState' ;
25- import { alertIsFetchingAtom , alertAtom , alertHowManyAtom , alertSearchTextAtom } from '../../atoms/alertAtom' ;
25+ import { alertIsFetchingAtom , alertAtom , alertHowManyAtom } from '../../atoms/alertAtom' ;
26+ import { useQueryParams } from '../../hooks/useQueryParams' ;
2627
2728import { translate } from '../../helpers/language' ;
2829
@@ -44,13 +45,20 @@ const AlertSection = () => {
4445
4546 //console.log('AlertSection run');
4647
47- const [ alertSearchText , setAlertSearchText ] = useAtom ( alertSearchTextAtom ) ;
48+ const queryParams = useQueryParams ( ) ;
49+ const alertSearchText = queryParams . get ( 'alertSearch' ) || '' ;
4850 const [ localSearchText , setLocalSearchText ] = useState ( alertSearchText ) ;
4951
50- // Debounce updating the shared atom so filtering doesn't run on every keystroke
52+ // Debounce updating the URL query param so it doesn't update on every keystroke
5153 const debouncedSetSearchText = useMemo (
52- ( ) => _ . debounce ( ( value : string ) => setAlertSearchText ( value ) , 300 ) ,
53- [ setAlertSearchText ] ,
54+ ( ) => _ . debounce ( ( value : string ) => {
55+ if ( value ) {
56+ queryParams . set ( { alertSearch : value } ) ;
57+ } else {
58+ queryParams . remove ( 'alertSearch' ) ;
59+ }
60+ } , 300 ) ,
61+ [ queryParams ] ,
5462 ) ;
5563
5664 // Cleanup debounce on unmount
@@ -69,7 +77,7 @@ const AlertSection = () => {
6977 const handleSearchClear = ( ) => {
7078 setLocalSearchText ( '' ) ;
7179 debouncedSetSearchText . cancel ( ) ;
72- setAlertSearchText ( ' ') ;
80+ queryParams . remove ( 'alertSearch ') ;
7381 } ;
7482
7583 // State Management state (this section)
0 commit comments