@@ -27,7 +27,7 @@ const fetchSellerCoordinates = async (origin: LatLngTuple, radius: number, searc
27
27
28
28
try {
29
29
const sellersData = await fetchSellers ( formattedOrigin , radius , searchQuery ) ;
30
- const sellersWithCoordinates = sellersData . map ( ( seller : any ) => {
30
+ const sellersWithCoordinates = sellersData ? .map ( ( seller : any ) => {
31
31
const [ lng , lat ] = seller . sell_map_center . coordinates ;
32
32
return {
33
33
...seller ,
@@ -53,7 +53,7 @@ const removeDuplicates = (sellers: ISeller[]): ISeller[] => {
53
53
return Object . values ( uniqueSellers ) ;
54
54
} ;
55
55
56
- const Map = ( { center, zoom, searchQuery } : { center : LatLngExpression , zoom : number , searchQuery : string } ) => {
56
+ const Map = ( { center, zoom, searchQuery, searchResults } : { center : LatLngExpression , zoom : number , searchQuery : string , searchResults : ISeller [ ] } ) => {
57
57
const t = useTranslations ( ) ;
58
58
59
59
const customIcon = L . icon ( {
@@ -87,12 +87,27 @@ const Map = ({ center, zoom, searchQuery }: { center: LatLngExpression, zoom: nu
87
87
}
88
88
} , [ center ] ) ;
89
89
90
- // Update map markers when searchQuery prop changes
91
90
useEffect ( ( ) => {
92
91
if ( searchQuery ) {
93
- fetchInitialCoordinates ( ) ;
92
+ setLoading ( true ) ;
93
+
94
+ const sellersWithCoordinates = searchResults
95
+ . map ( ( seller : any ) => {
96
+ const [ lng , lat ] = seller . sell_map_center . coordinates ;
97
+ return {
98
+ ...seller ,
99
+ coordinates : [ lat , lng ] as LatLngTuple
100
+ } ;
101
+ } ) ;
102
+
103
+ // Remove duplicates
104
+ const uniqueSellers = removeDuplicates ( sellersWithCoordinates ) ;
105
+
106
+ // Update the sellers state
107
+ setSellers ( uniqueSellers ) ;
108
+ setLoading ( false ) ;
94
109
}
95
- } , [ searchQuery , origin , radius ] ) ;
110
+ } , [ searchQuery , searchResults ] ) ;
96
111
97
112
// Log sellers array for debugging
98
113
useEffect ( ( ) => {
@@ -117,7 +132,7 @@ const Map = ({ center, zoom, searchQuery }: { center: LatLngExpression, zoom: nu
117
132
}
118
133
} ;
119
134
120
- // Function to handle map interactions (zoom and move)
135
+ // Function to handle map interactions (zoom and move); lazy-loading implementation
121
136
const handleMapInteraction = async ( newBounds : L . LatLngBounds , mapInstance : L . Map ) => {
122
137
const newCenter = newBounds . getCenter ( ) ;
123
138
const newRadius = calculateRadius ( newBounds , mapInstance ) ;
0 commit comments