From 72ae8d284aba33daad3e61d9fe06812194a28f33 Mon Sep 17 00:00:00 2001 From: Carissa Knipe Date: Mon, 11 Nov 2024 10:37:38 -0800 Subject: [PATCH] fix: Don't remember last location when permissions are denied --- dev-client/src/screens/BottomTabsScreen.tsx | 2 ++ dev-client/src/screens/SitesScreen/SitesScreen.tsx | 4 +++- .../src/screens/SitesScreen/components/CustomUserLocation.tsx | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/dev-client/src/screens/BottomTabsScreen.tsx b/dev-client/src/screens/BottomTabsScreen.tsx index 2e9835452..33897071e 100644 --- a/dev-client/src/screens/BottomTabsScreen.tsx +++ b/dev-client/src/screens/BottomTabsScreen.tsx @@ -78,6 +78,8 @@ export const BottomTabsScreen = memo(() => { locationManager.addListener(listener); return () => locationManager.removeListener(listener); + } else { + dispatch(updateLocation({coords: null, accuracyM: null})); } }, [dispatch, locationPermissions?.granted]); diff --git a/dev-client/src/screens/SitesScreen/SitesScreen.tsx b/dev-client/src/screens/SitesScreen/SitesScreen.tsx index 3c60aa71b..0ca0a1775 100644 --- a/dev-client/src/screens/SitesScreen/SitesScreen.tsx +++ b/dev-client/src/screens/SitesScreen/SitesScreen.tsx @@ -98,7 +98,9 @@ export const SitesScreen = memo(() => { } }, [dispatch, currentUserID]); - const currentUserCoords = useSelector(state => state.map.userLocation.coords); + const currentUserCoords = useSelector( + state => state.map.userLocation?.coords, + ); const [finishedLoading, setFinishedLoading] = useState(false); const [finishedInitialCameraMove, setFinishedInitialCameraMove] = diff --git a/dev-client/src/screens/SitesScreen/components/CustomUserLocation.tsx b/dev-client/src/screens/SitesScreen/components/CustomUserLocation.tsx index 34eed0f46..ceeb73aba 100644 --- a/dev-client/src/screens/SitesScreen/components/CustomUserLocation.tsx +++ b/dev-client/src/screens/SitesScreen/components/CustomUserLocation.tsx @@ -55,6 +55,7 @@ export const CustomUserLocation = ({ const userLocation = useSelector(state => state.map.userLocation); const feature = useMemo(() => { + // Coords should be null when permissions are not granted if (userLocation.coords === null) { return null; }