3
3
import './SearchBar.scss' ;
4
4
5
5
import { useTranslations } from 'next-intl' ;
6
- import { useContext , useState , useRef , ChangeEvent , FormEvent } from 'react' ;
6
+ import { useContext , useState , ChangeEvent , FormEvent } from 'react' ;
7
7
import { FormControl , TextField } from '@mui/material' ;
8
8
import SearchIcon from '@mui/icons-material/Search' ;
9
- import { fetchSellers } from '@/services/sellerApi' ;
10
-
11
9
import logger from '../../../../logger.config.mjs' ;
12
10
import { AppContext } from '../../../../context/AppContextProvider' ;
13
11
14
- interface searchBarProps {
15
- onSearch ?: ( query : string , results : any [ ] ) => void ;
12
+ interface SearchBarProps {
13
+ onSearch ?: ( query : string ) => void ;
16
14
page : 'map_center' | 'default' ;
17
15
}
18
16
19
- const SearchBar : React . FC < searchBarProps > = ( { onSearch, page } ) => {
17
+ const SearchBar : React . FC < SearchBarProps > = ( { onSearch, page } ) => {
20
18
const t = useTranslations ( ) ;
21
19
22
20
const [ searchBarValue , setSearchBarValue ] = useState ( '' ) ;
23
- const [ loading , setLoading ] = useState ( false ) ;
24
-
25
21
const { isSigningInUser } = useContext ( AppContext ) ;
26
22
27
- const inputRef = useRef < HTMLInputElement > ( null ) ;
28
-
29
23
const getPlaceholderText = ( page : 'map_center' | 'default' ) : string => {
30
24
return page === 'map_center'
31
25
? t ( 'SHARED.MAP_CENTER.SEARCH_BAR_PLACEHOLDER' )
@@ -39,47 +33,36 @@ const SearchBar: React.FC<searchBarProps> = ({ onSearch, page }) => {
39
33
setSearchBarValue ( event . target . value ) ;
40
34
} ;
41
35
42
- const fetchSearchResults = async ( query : string ) : Promise < any [ ] > => {
43
- setLoading ( true ) ;
44
- try {
45
- logger . debug ( `Fetching search results for query: "${ query } "` ) ;
46
- const data = await fetchSellers ( undefined , undefined , query ) ;
47
- return data || [ ] ; // Return response.data or empty array if undefined
48
- } catch ( error ) {
49
- logger . error ( `Error fetching search results: ${ error } ` ) ;
50
- return [ ] ;
51
- } finally {
52
- setLoading ( false ) ;
53
- }
54
- } ;
55
-
56
- const handleSubmitSearch = async ( event : FormEvent ) => {
36
+ const handleSubmitSearch = ( event : FormEvent ) => {
57
37
event . preventDefault ( ) ;
58
38
const query = searchBarValue . trim ( ) ;
59
39
logger . debug ( `Search query submitted: ${ query } ` ) ;
60
- const results = await fetchSearchResults ( query ) ;
61
40
if ( onSearch ) {
62
- onSearch ( query , results ) ; // notify parent of the search query to update map
41
+ onSearch ( query ) ; // Pass the query to the parent component
63
42
}
64
43
} ;
65
44
66
45
return (
67
46
< div className = "w-[90%] m-auto left-0 right-0 max-w-[504px] fixed top-[120px] z-10 flex" >
68
47
< div className = "w-[100%] m-auto flex items-center" >
69
- < form className = "w-full flex items-center gap-2 justify-between" onSubmit = { handleSubmitSearch } >
48
+ < form
49
+ className = "w-full flex items-center gap-2 justify-between"
50
+ onSubmit = { handleSubmitSearch }
51
+ >
70
52
< FormControl className = "flex-grow mr-3" >
71
53
< TextField
72
- id = "search-input"
73
- type = "text"
74
- variant = "outlined"
75
- color = "success"
76
- className = { `w-full rounded ${ isSigningInUser ? 'bg-gray-200' : 'bg-white hover:bg-gray-100' } ` }
77
- label = { `${ isSigningInUser ? '' : placeholder } ` }
78
- value = { searchBarValue }
79
- onChange = { handleSearchBarChange }
80
- ref = { inputRef }
81
- disabled = { isSigningInUser }
82
- InputLabelProps = { { className : 'custom-label' } }
54
+ id = "search-input"
55
+ type = "text"
56
+ variant = "outlined"
57
+ color = "success"
58
+ className = { `w-full rounded ${
59
+ isSigningInUser ? 'bg-gray-200' : 'bg-white hover:bg-gray-100'
60
+ } `}
61
+ label = { isSigningInUser ? '' : placeholder }
62
+ value = { searchBarValue }
63
+ onChange = { handleSearchBarChange }
64
+ disabled = { isSigningInUser }
65
+ InputLabelProps = { { className : 'custom-label' } }
83
66
/>
84
67
</ FormControl >
85
68
< button
@@ -89,7 +72,7 @@ const SearchBar: React.FC<searchBarProps> = ({ onSearch, page }) => {
89
72
${ isSigningInUser ? 'bg-tertiary' : 'bg-primary hover:bg-gray-500' } ` }
90
73
disabled = { isSigningInUser }
91
74
>
92
- < SearchIcon fontSize = { " large" } className = " text-[#ffc153]" />
75
+ < SearchIcon fontSize = { ' large' } className = "text-[#ffc153]" />
93
76
</ button >
94
77
</ form >
95
78
</ div >
0 commit comments