From 6da8d263f68f3632ab949287614595776450efbb Mon Sep 17 00:00:00 2001 From: Laurian-Dufrechou Date: Fri, 28 Apr 2023 18:31:34 +0200 Subject: [PATCH] fix(BUG Carte): error first load map --- src/components/layout/map/MapComponent.tsx | 2 +- src/pages/map.tsx | 11 ++----- src/pages/userProfile.tsx | 34 +++++++++++----------- 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src/components/layout/map/MapComponent.tsx b/src/components/layout/map/MapComponent.tsx index 5ad7778..985d01d 100644 --- a/src/components/layout/map/MapComponent.tsx +++ b/src/components/layout/map/MapComponent.tsx @@ -7,7 +7,7 @@ import "@christopherpickering/react-leaflet-markercluster/dist/styles.min.css"; import MarkerBar from "./MarkerBar"; import "leaflet/dist/leaflet.css"; -export default function MapComponent(props) { +export default function MapComponent(props: any) { const { location, listBars } = props; const toast = useToast({ position: "top" }); diff --git a/src/pages/map.tsx b/src/pages/map.tsx index aa60cc6..4287850 100644 --- a/src/pages/map.tsx +++ b/src/pages/map.tsx @@ -18,13 +18,6 @@ export default function Map() { const idSaveToast = "saved_location"; const { data: session, status } = useSession(); - //faire un useQuery pour récupérer les bars et restaurants et en meme temps regarder si l'user a une location - //Si oui, faire une mutation avec navigator.geolocation.getCurrentPosition pour mettre à jour la location de l'user dans la bdd - - // cet url : https://data.opendatasoft.com/api/v2/catalog/datasets/osm-fr-bars%40babel/records?limit=100&offset=0&lang=fr&timezone=UTC - - // ou : https://data.opendatasoft.com/api/v2/catalog/datasets/osm-fr-bars%40babel/exports/json?limit=-1&offset=0&lang=fr&timezone=UTC MAIS RENVOI UN file - const { isLoading, isError, @@ -79,7 +72,6 @@ export default function Map() { const userSetLocation = useMutation({ mutationKey: "userSetLocation", - enabled: !isLoading && !loggedUser, mutationFn: async (position: string) => { const pos = { location: position, @@ -112,11 +104,12 @@ export default function Map() { useEffect(() => { navigator.geolocation.getCurrentPosition((position) => { setLocation([position.coords.latitude, position.coords.longitude]); + if (!loggedUser) return; userSetLocation.mutate( `${position.coords.latitude},${position.coords.longitude}` ); }); - }, []); + }, [loggedUser]); const MapWithNoSSR = dynamic( () => import("../components/layout/map/MapComponent"), diff --git a/src/pages/userProfile.tsx b/src/pages/userProfile.tsx index 02467de..e032b45 100644 --- a/src/pages/userProfile.tsx +++ b/src/pages/userProfile.tsx @@ -362,23 +362,6 @@ export default function UserProfile() { - - - - Centre d'intéret : - - - - - - - - @@ -419,6 +402,23 @@ export default function UserProfile() { + + + + Centre d'intéret : + + + + + + + +