@@ -4,87 +4,74 @@ import { ArtistAutocompleteQuery, useArtistAutocompleteQuery } from "../generate
44import { generateGQLSearchQueryVars } from "../helpers/queryCacheHelper" ;
55import { isEditOrPreviewMode } from "../helpers/urlHelper" ;
66
7- const singleKeyUrl = process . env . REACT_APP_CONTENT_GRAPH_GATEWAY_URL as string
8-
97type CustomString = string | number | readonly string [ ] | undefined
108
11- function SearchButton ( ) : JSX . Element {
9+ function SearchButton ( { filterValue} : any ) : JSX . Element {
10+ const singleKeyUrl = process . env . REACT_APP_CONTENT_GRAPH_GATEWAY_URL as string
11+ const ARTIST = "Artist"
1212 const [ searchParams ] = useSearchParams ( )
1313 const [ token , setToken ] = useState ( "" )
1414 const [ isShown , setIsShown ] = useState ( false )
15- const [ searchValue , setSearchValue ] = useState < CustomString > ( searchParams . get ( "q" ) ?. toString ( ) )
16- const [ orderBy , setOrderBy ] = useState ( "ASC" )
17- let variables : any = generateGQLSearchQueryVars ( token , window . location . pathname , searchValue as string | null , orderBy ) ;
18- const modeEdit = isEditOrPreviewMode ( )
19- let stringArr : ( string | null ) [ ] = [ ]
20-
15+ const [ searchValue , setSearchValue ] = useState < CustomString > ( searchParams . get ( "q" ) ?. toString ( ) ?? "" )
16+ const [ orderBy ] = useState ( "ASC" )
2117 let autocompleteData : ArtistAutocompleteQuery | undefined = undefined
18+
19+ let modeEdit = isEditOrPreviewMode ( )
20+ let variables = generateGQLSearchQueryVars ( token , window . location . pathname , searchValue as string | null , orderBy ) ;
2221 const { data : artistAutocompleteData } = useArtistAutocompleteQuery ( { endpoint : singleKeyUrl } , variables , { staleTime : 2000 , enabled : ! modeEdit || ! ! token } )
2322 autocompleteData = artistAutocompleteData
2423
2524 function search ( event : any , action : string ) {
2625 if ( ( action == "keypress" && event . charCode === 13 ) || action == "buttonclick" ) {
27- window . location . href = `${ window . location . origin } /search?q=${ searchValue } `
26+ window . location . href = `${ window . location . origin } /search?q=${ searchValue } &f= ${ filterValue ?? ARTIST } `
2827 }
2928 }
3029
3130 function onValueChange ( event : any ) {
3231 setSearchValue ( event . target . value ) ;
33- event . target . value != "" && event . target . value != = undefined ? setIsShown ( true ) : setIsShown ( false ) ;
32+ event . target . value !== undefined ? setIsShown ( true ) : setIsShown ( false ) ;
3433 }
3534
3635 function onAutoClick ( event : any ) {
3736 setSearchValue ( event . target . textContent ) ;
38- window . location . href = `${ window . location . origin } /search?q=${ event . target . textContent } `
37+ window . location . href = `${ window . location . origin } /search?q=${ event . target . textContent } &f= ${ filterValue ?? ARTIST } `
3938 }
4039
4140 return (
4241 < div >
43- < div className = "nav-table-cell" >
44- < input className = "search-input" type = "text" id = "search-input" placeholder = "Search"
45- onKeyPress = { ( event ) => { search ( event , 'keypress' ) } } value = { searchValue } onChange = { onValueChange } />
46- < a className = "search-icon" onClick = { ( event ) => { search ( event , 'buttonclick' ) } } >
47- < i className = "fa fa-search" > </ i >
48- </ a >
49-
50- { /* <Autocomplete
51- sx={{
52- display: 'inline-block',
53- '& input': {
54- width: 200,
55- bgcolor: 'background.paper',
56- color: (theme) =>
57- theme.palette.getContrastText(theme.palette.background.paper),
58- },
59- }}
60- id="custom-input-demo"
61- options={stringArr}
62- renderInput={(params) => (
63- <div ref={params.InputProps.ref}>
64- <input className="search-input" type="text" id="search-input" placeholder="Search"
65- onKeyPress={(event) => {search(event, 'keypress')}} value={searchValue} onChange={onValueChange} {...params.inputProps} />
42+ < div className = "nav-table-cell autocomplete" >
43+ < input className = "search-input"
44+ type = "text"
45+ id = "search-input"
46+ placeholder = "Search"
47+ onKeyPress = { ( event ) => { search ( event , 'keypress' ) } }
48+ value = { searchValue }
49+ onChange = { onValueChange }
50+ onFocus = { ( ) => setIsShown ( true ) }
51+ onBlur = { ( ) =>
52+ setTimeout ( ( ) => {
53+ setIsShown ( false ) ;
54+ } , 150 )
55+ } />
6656 < a className = "search-icon" onClick = { ( event ) => { search ( event , 'buttonclick' ) } } >
6757 < i className = "fa fa-search" > </ i >
6858 </ a >
69- </div>
70- )}
71- /> */ }
72- < div className = "autocomplete-block" style = { isShown ? { display : "inherit" } : { display : "none" } } >
73- {
74- autocompleteData ?. ArtistDetailsPage ?. autocomplete ?. ArtistName ?. map ( ( name ) => {
75- return (
76- < div key = { name } onClick = { ( event ) => onAutoClick ( event ) } > { name } </ div >
77- )
78- } )
79- }
80- {
81- autocompleteData ?. ArtistDetailsPage ?. autocomplete ?. StageName ?. map ( ( name ) => {
82- return (
83- < div key = { name } onClick = { ( event ) => onAutoClick ( event ) } > { name } </ div >
84- )
85- } )
86- }
87- </ div >
59+ < div className = "autocomplete-block" style = { isShown ? { display : "inherit" } : { display : "none" } } >
60+ {
61+ autocompleteData ?. ArtistDetailsPage ?. autocomplete ?. ArtistName ?. map ( ( name , idx ) => {
62+ return (
63+ < div key = { idx } onClick = { ( event ) => onAutoClick ( event ) } > { name } </ div >
64+ )
65+ } )
66+ }
67+ {
68+ autocompleteData ?. ArtistDetailsPage ?. autocomplete ?. StageName ?. map ( ( name , idx ) => {
69+ return (
70+ < div key = { idx } onClick = { ( event ) => onAutoClick ( event ) } > { name } </ div >
71+ )
72+ } )
73+ }
74+ </ div >
8875 </ div >
8976 </ div >
9077 ) ;
0 commit comments