diff --git a/app.json b/app.json index b7c46f2..e1b0afe 100644 --- a/app.json +++ b/app.json @@ -38,7 +38,8 @@ "backgroundColor": "#000000" } } - ] + ], + "expo-secure-store" ], "experiments": { "typedRoutes": true, diff --git a/app/(tabs)/_layout.tsx b/app/(tabs)/_layout.tsx index a028b63..ef2b145 100644 --- a/app/(tabs)/_layout.tsx +++ b/app/(tabs)/_layout.tsx @@ -33,8 +33,10 @@ export default function TabLayout() { return ( - + + + ); } \ No newline at end of file diff --git a/app/(tabs)/assignments.tsx b/app/(tabs)/assignments.tsx new file mode 100644 index 0000000..6cc5358 --- /dev/null +++ b/app/(tabs)/assignments.tsx @@ -0,0 +1,147 @@ +import { defaultStyles } from "@/constants/defaultStyles"; +import { supabase } from "@/lib/supabase"; +import { Ionicons } from '@expo/vector-icons'; +import { Session } from "@supabase/supabase-js"; +import { router, Stack, useFocusEffect } from "expo-router"; +import { useCallback, useEffect, useState } from "react"; +import { Alert, Button, Pressable, SectionList, Text, View } from "react-native"; + +type Assignment = { + aId: string; + title: string; + description: string; + deadline: string; + isCompleted: boolean; + lastChanged: string; + uId: string; + sId: string; +} + +export default function Assignments() { + const [assignments, SetAssignments] = useState([]) + const [session, SetSession] = useState(null) + + const assignmentSections = [ + { title: "Upcoming Assignments", data: assignments.filter((assignment) => !assignment.isCompleted), emptyMessage: "No upcoming assignments" }, + { title: "Completed Assignments", data: assignments.filter((assignment) => assignment.isCompleted), emptyMessage: "No completed assignments" }, + ]; + + useEffect(() => { + supabase.auth.getSession().then(({ data }) => SetSession(data.session ?? null)) + const { data: sub } = supabase.auth.onAuthStateChange((_event, newSession) => { + SetSession(newSession) + }) + return () => sub.subscription.unsubscribe() + }, + []) + + const GetAssignments = async () => { + const { data, error } = await supabase.from("assignments").select("*").order("deadline", { ascending: false }); + + if (error) { + Alert.alert("Assignments could not be fetched, please try again"); + return; + } + + SetAssignments(data ?? []); + } + + useFocusEffect( + useCallback(() => { + if (session) { + GetAssignments(); + } + }, [session]) + ); + + const DeleteAssignment = async (aId: string) => { + Alert.alert( + "Delete Assignment", + "Are you sure you want to delete this assignment?", + [ + { + text: "Cancel", + style: "cancel" + }, + { + text: "Delete", + style: "destructive", + onPress: async () => { + const { error } = await supabase.from("assignments").delete().eq("aId", aId); + + if (error) { + Alert.alert("Assignment could not be deleted, please try again"); + return; + } + + Alert.alert("Assignment deleted successfully!"); + GetAssignments(); + } + } + ] + ) + } + + return ( + + { + return ( + + + + +