diff options
author | Santo Cariotti <santo@dcariotti.me> | 2024-10-20 22:23:59 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2024-10-20 22:23:59 +0200 |
commit | 0c5181056d0977bbb63e34df941a3665a65a50b4 (patch) | |
tree | ac3c07a25e824caf7f941074bd69d7fbc33b0362 /app | |
parent | 7c36badf769a3f6e54855dd7f03d25af5434762c (diff) |
New notification fields
Diffstat (limited to 'app')
-rw-r--r-- | app/(tabs)/index.tsx | 25 | ||||
-rw-r--r-- | app/(tabs)/notifications/[id].tsx | 27 |
2 files changed, 25 insertions, 27 deletions
diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx index 8e52ee1..da967c7 100644 --- a/app/(tabs)/index.tsx +++ b/app/(tabs)/index.tsx @@ -37,6 +37,7 @@ TaskManager.defineTask(LOCATION_TASK_NAME, async ({ data, error }) => { if (data) { const { locations } = data; console.log("Received new locations:", locations); + updateLocation(location.coords, location.coords.speed); // Process the locations here } }); @@ -346,7 +347,7 @@ export default function HomeScreen() { movingActivity = "IN_VEHICLE"; } - await fetch( + const response = await fetch( `${process.env.EXPO_PUBLIC_ALERTD_URL}`, { method: "POST", @@ -362,6 +363,10 @@ export default function HomeScreen() { }), }, ); + const data = await response.json(); + if (response.status != 200) { + console.error(data) + } } catch (err) { console.error("Error on updating position"); } @@ -382,7 +387,7 @@ export default function HomeScreen() { "Content-Type": "application/json", }, body: JSON.stringify({ - query: `{ notifications(seen: false) { id, createdAt, level, alert { id, text1 text2 text3 } position { movingActivity } } }`, + query: `{ notifications(seen: false) { id, createdAt, level, alert { id, text1 text2 text3 }, movingActivity } }`, }), }, ); @@ -440,15 +445,20 @@ export default function HomeScreen() { try { const { status } = await Location.requestForegroundPermissionsAsync(); if (status === "granted") { - setInterval(async () => { - const location = await Location.getCurrentPositionAsync({}); - updateLocation(location.coords, location.coords.speed); - }, 2000); + Location.watchPositionAsync( + { + accuracy: Location.Accuracy.Balanced, + distanceInterval: 10, + }, + location => { + updateLocation(location.coords, location.coords.speed); + } + ) await Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, { accuracy: Location.Accuracy.Balanced, // ~100 meters of precision distanceInterval: 10, // Send data only if they moved of >=10 meters - deferredUpdatesInterval: 1000, + deferredUpdatesInterval: 10000, showsBackgroundLocationIndicator: true, foregroundService: { notificationTitle: "CAS4 Location Tracking", @@ -464,7 +474,6 @@ export default function HomeScreen() { console.error("Error starting background location updates:", error); } }; - startBackgroundLocationTracking(); }, []); diff --git a/app/(tabs)/notifications/[id].tsx b/app/(tabs)/notifications/[id].tsx index 4ec6f1a..42e743d 100644 --- a/app/(tabs)/notifications/[id].tsx +++ b/app/(tabs)/notifications/[id].tsx @@ -24,19 +24,11 @@ interface AlertData { areaLevel3: string; } -interface PositionData { - id: string; - userId: string; - createdAt: string; - latitude: number; - longitude: number; - movingActivity: string; -} - interface NotificationData { id: string; alert: AlertData; - position: PositionData; + userId: string; + movingActivity: string; seen: boolean; level: string; createdAt: string; @@ -130,14 +122,11 @@ export default function NotificationIdScreen() { 'Content-Type': 'application/json', }, body: JSON.stringify({ - query: `{ notifications(id: ${id}) { - id, - alert { id, userId, createdAt, area, areaLevel2, areaLevel3, reachedUsers }, - position {id, userId, createdAt, latitude, longitude, movingActivity}, - seen, - level, - createdAt - } }`, + query: `{notifications(id: ${id}) { + id, + alert { id, userId, createdAt, area, areaLevel2, areaLevel3, text1, text2, text3, reachedUsers }, + userId, latitude, longitude, movingActivity, level, seen, createdAt + }}`, }), } ); @@ -176,7 +165,7 @@ export default function NotificationIdScreen() { })); - setCoordinates({ latitude: notificationData.position.latitude, longitude: notificationData.position.longitude }); + setCoordinates({ latitude: notificationData.latitude, longitude: notificationData.longitude }); setNotification(notificationData); setPolygon(coordinates); setLevel2Polygon(level2Coordinates); |