From 0d468cc8c158f884b7f63a9bdcf351726e934171 Mon Sep 17 00:00:00 2001
From: Santo Cariotti <santo@dcariotti.me>
Date: Fri, 13 Sep 2024 11:54:07 +0200
Subject: Add alert text on homepage

---
 app/(tabs)/index.tsx | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

(limited to 'app/(tabs)/index.tsx')

diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx
index 47663a8..d45f1ac 100644
--- a/app/(tabs)/index.tsx
+++ b/app/(tabs)/index.tsx
@@ -44,9 +44,18 @@ TaskManager.defineTask(LOCATION_TASK_NAME, async ({ data, error }) => {
 interface NotificationPositionData {
   movingActivity: string;
 }
+
+interface NotificationAlertData {
+  text1: string;
+  text2: string;
+  text3: string;
+}
+
 interface NotificationData {
   id: string;
   createdAt: string;
+  level: string;
+  alert: NotificationAlertData;
   position: NotificationPositionData;
 }
 
@@ -369,7 +378,7 @@ export default function HomeScreen() {
               "Content-Type": "application/json",
             },
             body: JSON.stringify({
-              query: `{ notifications(seen: false) { id, createdAt, position { movingActivity } } }`,
+              query: `{ notifications(seen: false) { id, createdAt, level, alert { text1 text2 text3 } position { movingActivity } } }`,
             }),
           },
         );
@@ -394,7 +403,7 @@ export default function HomeScreen() {
 
       return () => clearInterval(intervalId);
     } else {
-      setNotification("");
+      setNotification(null);
     }
   }, [token, userId]);
 
@@ -473,6 +482,13 @@ export default function HomeScreen() {
                     Oh no, you are (or have been) in an alerted area in{" "}
                     {formatDate(notification.createdAt)}!
                   </Text>
+                  <View style={styles.notificationDelimiter} />
+                  <Text style={[styles.notificationBoxText, { fontStyle: 'italic' }]}>"
+                    {notification.level == 'ONE' ?
+                      notification.alert.text1 : notification.level == 'TWO' ?
+                        notification.alert.text2 : notification.alert.text3}
+                    "</Text>
+                  <View style={styles.notificationDelimiter} />
                   <Text style={styles.notificationBoxText}>
                     Click this banner to know more!
                   </Text>
@@ -481,7 +497,8 @@ export default function HomeScreen() {
             </View>
           ) : (
             <></>
-          )}
+          )
+          }
           <ThemedView>
             <Pressable onPress={handleLogout} style={styles.formButton}>
               <Text style={{ color: "white", textAlign: "center" }}>
@@ -585,4 +602,10 @@ const styles = StyleSheet.create({
     textAlign: "center",
     fontWeight: "bold",
   },
+  notificationDelimiter: {
+    marginVertical: 30,
+    width: '100%',
+    height: 1,
+    backgroundColor: '#B2171B'
+  }
 });
-- 
cgit v1.2.3-71-g8e6c

