diff --git a/app/(tabs)/_layout.tsx b/app/(tabs)/_layout.tsx new file mode 100644 index 0000000..a028b63 --- /dev/null +++ b/app/(tabs)/_layout.tsx @@ -0,0 +1,40 @@ +import { supabase } from "@/lib/supabase"; +import { Session } from "@supabase/supabase-js"; +import { Redirect, Tabs } from "expo-router"; +import { useEffect, useState } from "react"; + +export default function TabLayout() { + const [session, SetSession] = useState(null) + const [loading, SetLoading] = useState(true); + + useEffect(() => { + const loadSession = async () => { + const { data } = await supabase.auth.getSession(); + SetSession(data.session ?? null); + SetLoading(false); + } + loadSession(); + + const { data: sub } = supabase.auth.onAuthStateChange((_event, newSession) => { + SetSession(newSession); + SetLoading(false); + }); + + return () => sub.subscription.unsubscribe(); + }, []); + + if (loading) { + return null; + } + + if (!session) { + return ; + } + + return ( + + + + + ); +} \ No newline at end of file diff --git a/app/(tabs)/createTask.tsx b/app/(tabs)/createTask.tsx new file mode 100644 index 0000000..ed73b7a --- /dev/null +++ b/app/(tabs)/createTask.tsx @@ -0,0 +1,110 @@ +import { defaultStyles } from '@/constants/defaultStyles'; +import { supabase } from '@/lib/supabase'; +import { router, Stack } from 'expo-router'; +import { useState } from 'react'; +import { ActivityIndicator, Alert, Button, Keyboard, KeyboardAvoidingView, Platform, Pressable, Text, TextInput, TouchableWithoutFeedback, View } from 'react-native'; + +export default function CreateTask() { + const [title, SetTitle] = useState(''); + const [description, SetDescription] = useState(''); + const [isCompleted, SetIsCompleted] = useState(false); + const [deadline, SetDeadline] = useState(''); + const [isSaving, SetIsSaving] = useState(false); + + const AddNote = async () => { + if(title.trim() === '' || description.trim() === '' || deadline.trim() === '') { + Alert.alert("All fields are required!"); + return; + } + + const { data, error: userError } = await supabase.auth.getUser(); + + if(userError || !data.user) { + router.replace("../createUser"); + return; + } + + SetIsSaving(true); + + const { error: dbError } = await supabase.from("tasks").insert({ + title, + description, + isCompleted, + lastChanged: new Date().toISOString(), + deadline, + uId: data.user.id, + }); + + if (dbError) { + Alert.alert("Task could not be created, please try again"); + SetIsSaving(false); + return; + } + + Alert.alert("Task successfully added!"); + + SetTitle(''); + SetDescription(''); + SetIsCompleted(false); + SetDeadline(''); + + SetIsSaving(false); + + router.back(); + } + + return ( + <> + + + + Create New Task + + + + + + + SetIsCompleted(state => !state)} + style={defaultStyles.checkboxContainer} + > + + {isCompleted && } + + {isCompleted ? 'Completed' : 'Not completed'} + + +