From fa0c0a4cb37fe8e856625b5a0d85ddc306980c15 Mon Sep 17 00:00:00 2001 From: Thomas Irvine Date: Mon, 4 Mar 2024 13:38:38 -0600 Subject: [PATCH 1/6] small change forcing fresh time grab on note save --- lib/screens/AddNoteScreen.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/screens/AddNoteScreen.tsx b/lib/screens/AddNoteScreen.tsx index d42aded..cd309a4 100644 --- a/lib/screens/AddNoteScreen.tsx +++ b/lib/screens/AddNoteScreen.tsx @@ -207,6 +207,8 @@ const AddNoteScreen: React.FC = ({ navigation, route }) => { longitude = userLocation.coords.longitude.toString(); } + setTime(new Date()); //force a fresh time date grab on note save + const newNote = { title: titleText, text: bodyText, From aa7c978abcb3d73c0597074051474ca8f92f702e Mon Sep 17 00:00:00 2001 From: Thomas Irvine Date: Sun, 17 Mar 2024 17:44:55 -0500 Subject: [PATCH 2/6] component side changes to location --- lib/components/location.tsx | 56 ++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/lib/components/location.tsx b/lib/components/location.tsx index d96c01b..41239cc 100644 --- a/lib/components/location.tsx +++ b/lib/components/location.tsx @@ -27,12 +27,12 @@ async function getLocation() { let { status } = await Location.requestForegroundPermissionsAsync(); if (status !== "granted") { console.log("Permission to access location was denied"); - return null; // Return null to indicate that location access is denied + return null; } return await Location.getCurrentPositionAsync({}); } catch (error) { console.error("Error getting location:", error); - return null; // Return null to indicate an error occurred while getting location + return null; } } @@ -73,6 +73,7 @@ export default function LocationWindow({ location?.longitude?.toString() || "" ); const [distanceFromEvent, setDistanceFromEvent] = useState(""); + const [isLocationShown, setIsLocationShown] = useState(false); useEffect(() => { const updateDistance = async () => { @@ -103,26 +104,38 @@ export default function LocationWindow({ setLongitude(location?.longitude?.toString() || ""); }, [location]); - const setShownLocation = async () => { - try { - let userLocation = await getLocation(); - - if (userLocation?.coords?.latitude !== undefined && userLocation?.coords?.longitude !== undefined) { - setLocation({ - latitude: userLocation.coords.latitude, - longitude: userLocation.coords.longitude, - }); - - setLatitude(userLocation.coords.latitude.toString()); - setLongitude(userLocation.coords.longitude.toString()); - } else { - console.log("Location data is not available."); + const toggleLocationVisibility = async () => { + if (isLocationShown) { + // Hide Location + setLocation({ + latitude: 0, + longitude: 0, + }); + setLatitude("0"); + setLongitude("0"); + } else { + // Show Location + try { + let userLocation = await getLocation(); + + if (userLocation?.coords?.latitude !== undefined && userLocation?.coords?.longitude !== undefined) { + setLocation({ + latitude: userLocation.coords.latitude, + longitude: userLocation.coords.longitude, + }); + + setLatitude(userLocation.coords.latitude.toString()); + setLongitude(userLocation.coords.longitude.toString()); + } else { + console.log("Location data is not available."); + } + } catch (error) { + console.error("Error setting location:", error); } - } catch (error) { - console.error("Error setting location:", error); } + setIsLocationShown((prev) => !prev); }; - + const getDistance = async () => { const lat1 = location?.latitude || 0; const lon1 = location?.longitude || 0; @@ -151,7 +164,10 @@ export default function LocationWindow({ value={latitude} onChangeText={handleLatitudeChange} /> -