From 473ba75e3ebe6b7b379928c5da6a9927ffd9bd28 Mon Sep 17 00:00:00 2001 From: Teodor Date: Mon, 20 Apr 2026 01:05:29 +0200 Subject: [PATCH] crud for tasks + auth --- app/(tabs)/_layout.tsx | 40 ++++++++ app/(tabs)/createTask.tsx | 110 ++++++++++++++++++++ app/(tabs)/editTask.tsx | 133 ++++++++++++++++++++++++ app/(tabs)/index.tsx | 28 ++++++ app/(tabs)/tasks.tsx | 141 ++++++++++++++++++++++++++ app/createUser.tsx | 69 +++++++++++++ app/index.tsx | 9 -- app/login.tsx | 66 ++++++++++++ constants/defaultStyles.ts | 105 +++++++++++++++++++ lib/supabase.ts | 31 +++++- notes/work-report-2026-04-20.md | 173 ++++++++++++++++++++++++++++++++ package-lock.json | 23 +++++ package.json | 2 + 13 files changed, 916 insertions(+), 14 deletions(-) create mode 100644 app/(tabs)/_layout.tsx create mode 100644 app/(tabs)/createTask.tsx create mode 100644 app/(tabs)/editTask.tsx create mode 100644 app/(tabs)/index.tsx create mode 100644 app/(tabs)/tasks.tsx create mode 100644 app/createUser.tsx delete mode 100644 app/index.tsx create mode 100644 app/login.tsx create mode 100644 constants/defaultStyles.ts create mode 100644 notes/work-report-2026-04-20.md 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'} + + +