fix: define and initialize setSelectedArea to avoid ReferenceError

- Imported useSetRecoilState from Recoil
- Defined and initialized setSelectedArea using useSetRecoilState with selectedAreaState
- Ensured setSelectedArea is used to reset the selected area after moving the map

This resolves the ReferenceError: setSelectedArea is not defined.
This commit is contained in:
ISA
2024-07-12 12:03:37 +02:00
parent 045ad26565
commit 7772b10e9c
2 changed files with 26 additions and 37 deletions

View File

@@ -698,6 +698,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
//------------------------------------------
//------------------------------------------ */
const selectedArea = useRecoilValue(selectedAreaState);
const setSelectedArea = useSetRecoilState(selectedAreaState);
// Combine all markers into a single array
const allMarkers = [
@@ -2038,15 +2039,26 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
//------------------------------------------ */
// Effect to handle navigation to selected area
useEffect(() => {
/* useEffect(() => {
if (selectedArea && map) {
const marker = findMyMarker(selectedArea);
if (marker) {
map.flyTo(marker.getLatLng(), 14); // Adjust zoom level as needed
}
}
}, [selectedArea, map, allMarkers]); // Include allMarkers in the dependencies
}, [selectedArea, map, allMarkers]); // Include allMarkers in the dependencies */
useEffect(() => {
if (selectedArea && map) {
const marker = findMyMarker(selectedArea);
if (marker) {
map.flyTo(marker.getLatLng(), 14);
map.once("moveend", () => {
setSelectedArea("Station wählen");
});
}
}
}, [selectedArea, map]);
//------------------------------------------
useEffect(() => {