From b1b5c8720cc0ab5026ce8050e33224dc47d54081 Mon Sep 17 00:00:00 2001 From: Laurian-Dufrechou Date: Thu, 18 May 2023 17:12:15 +0200 Subject: [PATCH] fix(error merge): fixed error induced with wrong merge --- src/pages/map.tsx | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/src/pages/map.tsx b/src/pages/map.tsx index 3a8c695..4090d99 100644 --- a/src/pages/map.tsx +++ b/src/pages/map.tsx @@ -17,7 +17,11 @@ const MapWithNoSSR = dynamic( ); export default function Map() { - const [location, setLocation] = useState([]); + const [location, setLocation] = useState([ + null as unknown as number, + null as unknown as number, + ]); + const [geolocationError, setGeolocationError] = useState(false); const { data: session, status } = useSession(); const [listBars, setListBars] = useState({} as unknown as any); @@ -112,19 +116,10 @@ export default function Map() { }; useEffect(() => { - if (!session?.user) return; - navigator.geolocation.getCurrentPosition( - (position: GeolocationPosition) => { - setLocation([position.coords.latitude, position.coords.longitude]); - setGeolocationError(false); - }, - () => setGeolocationError(true), - { - enableHighAccuracy: true, - timeout: 5000, - maximumAge: 0, - }, + successPosition, + errorPosition, + geolocationOptions ); }, [loggedUser]); @@ -139,22 +134,15 @@ export default function Map() { setLocation([position.coords.latitude, position.coords.longitude]); setGeolocationError(false); - for (const [key, val] of Object.entries(params)) { - urlBars.searchParams.append(key, val); - } + if (!loggedUser) return; + userSetLocation.mutate( + `${position.coords.latitude},${position.coords.longitude}` + ); + } - fetch(urlBars) - .then(res => res.json()) - .then(data => { - const filteredBars = data.filter((bar: any) => bar.name !== null); - setListBars(filteredBars); - }) - .catch(err => console.error(err)); - } - }, [session?.user]); - - if (status === 'loading') return ; - const {user} = session as unknown as Session; + function errorPosition(error: GeolocationPositionError) { + setGeolocationError(true); + } return ( <>