@@ -23,7 +23,8 @@ type Props = {
2323// Homepage and 404 should be `isStandalone`, all others not
2424// `updateSearchParams` should be false on the GraphQL explorer page
2525export function Search ( { isStandalone = false , updateSearchParams = true , children } : Props ) {
26- const [ query , setQuery ] = useState ( '' )
26+ const router = useRouter ( )
27+ const [ query , setQuery ] = useState ( router . query . query || '' )
2728 const [ results , setResults ] = useState < Array < SearchResult > > ( [ ] )
2829 const [ activeHit , setActiveHit ] = useState ( 0 )
2930 const inputRef = useRef < HTMLInputElement > ( null )
@@ -32,18 +33,14 @@ export function Search({ isStandalone = false, updateSearchParams = true, childr
3233
3334 // Figure out language and version for index
3435 const { languages, searchVersions, nonEnterpriseDefaultVersion } = useMainContext ( )
35- const router = useRouter ( )
3636 // fall back to the non-enterprise default version (FPT currently) on the homepage, 404 page, etc.
3737 const version = searchVersions [ currentVersion ] || searchVersions [ nonEnterpriseDefaultVersion ]
3838 const language = ( Object . keys ( languages ) . includes ( router . locale || '' ) && router . locale ) || 'en'
3939
4040 // If the user shows up with a query in the URL, go ahead and search for it
4141 useEffect ( ( ) => {
42- const params = new URLSearchParams ( location . search )
43- if ( params . has ( 'query' ) ) {
44- const xquery = params . get ( 'query' ) ?. trim ( ) || ''
45- setQuery ( xquery )
46- /* await */ fetchSearchResults ( xquery )
42+ if ( router . query . query ) {
43+ /* await */ fetchSearchResults ( ( router . query . query as string ) . trim ( ) )
4744 }
4845 } , [ ] )
4946
@@ -183,7 +180,7 @@ export function Search({ isStandalone = false, updateSearchParams = true, childr
183180 </ div >
184181 { /* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */ }
185182 < div
186- className = { 'search-overlay-desktop' + ( ! isStandalone && query ? ' js-open' : '' ) }
183+ className = { cx ( 'search-overlay-desktop' , ! isStandalone && query ? 'js-open' : '' ) }
187184 onClick = { closeSearch }
188185 > </ div >
189186 </ >
0 commit comments