WIP backup before merge

This commit is contained in:
Teodor
2026-04-22 00:07:35 +02:00
parent 473ba75e3e
commit 16a56fa8ab
17 changed files with 1434 additions and 82 deletions

View File

@@ -33,8 +33,10 @@ export default function TabLayout() {
return (
<Tabs>
<Tabs.Screen name="index" options={{title: "Today"}} />
<Tabs.Screen name="index" options={{title: "Index"}} />
<Tabs.Screen name="tasks" options={{title: "Tasks"}} />
<Tabs.Screen name="assignments" options={{title: "Assignments"}} />
<Tabs.Screen name="subjects" options={{title: "Subjects"}} />
</Tabs>
);
}

147
app/(tabs)/assignments.tsx Normal file
View File

@@ -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<Assignment[]>([])
const [session, SetSession] = useState<Session | null>(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 (
<View style={defaultStyles.container}>
<Stack.Screen
options={{
title: "Assignments",
headerTitleStyle: defaultStyles.title,
headerRight: () => {
return (
<View style={defaultStyles.buttonContainer}>
<Pressable style={defaultStyles.circularButton} onPress={GetAssignments}>
<Ionicons name="refresh" size={22} color="#333" />
</Pressable>
<Button title="Logout" onPress={async () => await supabase.auth.signOut()} />
</View>
)
},
}}
/>
<View style={defaultStyles.buttonContainer}>
<Button title="Create Assignment" onPress={() => router.push("/assignment/createAssignment")} />
</View>
<SectionList
sections={assignmentSections}
keyExtractor={(item) => item.aId}
renderSectionHeader={({ section: { title } }) => <Text style={defaultStyles.subtitle}>{title}</Text>}
renderItem={({ item }) => {
const isOwner = session?.user.id === item.uId;
return (
<View style={defaultStyles.container}>
<Pressable style={defaultStyles.container} onPress={() => router.push({pathname: "/assignment/viewDetailsAssignment", params: { aId: item.aId }})}>
<Text style={defaultStyles.boldBody}>{item.title}</Text>
<Text style={defaultStyles.body}>{item.deadline}</Text>
<View style={defaultStyles.checkbox}>
{item.isCompleted && <Text style={defaultStyles.checkboxMark}></Text>}
</View>
</Pressable>
{isOwner && (
<View style={defaultStyles.buttonContainer}>
<Button title="Edit" onPress={() => router.push({pathname: "/assignment/editAssignment", params: { aId: item.aId }})} />
<Button title="Delete" onPress={() => DeleteAssignment(item.aId)} />
</View>
)}
</View>
);
}}
renderSectionFooter={({ section }) =>
section.data.length === 0 ? (
<View style={defaultStyles.container}>
<Text style={defaultStyles.body}>{section.emptyMessage}</Text>
<View style={defaultStyles.separator} />
</View>
) : (
<View style={defaultStyles.separator} />
)
}
/>
</View>
)
}

View File

@@ -1,110 +0,0 @@
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 (
<>
<Stack.Screen
options={{
title: "Create Task",
headerTitleStyle: defaultStyles.title
}}
/>
<View style={defaultStyles.container}>
<Text style={defaultStyles.title}>Create New Task</Text>
<KeyboardAvoidingView style={{ flex: 1 }} behavior={Platform.OS === "ios" ? "padding" : "height"}>
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View style={defaultStyles.container}>
<TextInput
style={defaultStyles.inputText}
placeholder="Enter title"
value={title}
onChangeText={SetTitle}
/>
<TextInput
style={defaultStyles.inputText}
placeholder="Enter description"
value={description}
onChangeText={SetDescription}
/>
<TextInput
style={defaultStyles.inputText}
placeholder="Deadline (YYYY-MM-DD)"
value={deadline}
onChangeText={SetDeadline}
/>
<Pressable
onPress={() => SetIsCompleted(state => !state)}
style={defaultStyles.checkboxContainer}
>
<View style={defaultStyles.checkbox}>
{isCompleted && <Text style={defaultStyles.checkboxMark}></Text>}
</View>
<Text style={defaultStyles.checkboxLabel}>{isCompleted ? 'Completed' : 'Not completed'}</Text>
</Pressable>
<Button title={isSaving ? "Saving..." : "Save"} onPress={AddNote} disabled={isSaving} />
{isSaving && (
<ActivityIndicator size="large" />
)}
<Button title="Cancel" onPress={() => router.back()} />
</View>
</TouchableWithoutFeedback>
</KeyboardAvoidingView>
</View>
</>
)
}

View File

@@ -1,133 +0,0 @@
import { defaultStyles } from '@/constants/defaultStyles';
import { supabase } from '@/lib/supabase';
import { router, Stack, useFocusEffect, useLocalSearchParams } from 'expo-router';
import { useCallback, useState } from 'react';
import { ActivityIndicator, Alert, Button, Keyboard, KeyboardAvoidingView, Platform, Pressable, Text, TextInput, TouchableWithoutFeedback, View } from 'react-native';
export default function EditTask() {
const [title, SetTitle] = useState('');
const [description, SetDescription] = useState('');
const [isCompleted, SetIsCompleted] = useState(false);
const [deadline, SetDeadline] = useState('');
const [isSaving, SetIsSaving] = useState(false);
const { tId } = useLocalSearchParams();
useFocusEffect(
useCallback(() => {
const GetTask = async () => {
if (!tId) return;
const { data, error } = await supabase.from("tasks").select("*").eq("tId", tId).single();
if (error) {
Alert.alert("Task not found");
return;
}
if (data) {
SetTitle(data.title);
SetDescription(data.description);
SetIsCompleted(data.isCompleted);
SetDeadline(data.deadline);
}
}
GetTask();
}, [tId])
);
const EditTask = 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").update({
title,
description,
isCompleted,
lastChanged: new Date().toISOString(),
deadline,
uId: data.user.id,
}).eq("tId", tId);
if (dbError) {
Alert.alert("Task could not be edited, please try again");
return;
}
Alert.alert("Task successfully edited!");
SetTitle('');
SetDescription('');
SetIsCompleted(false);
SetDeadline('');
SetIsSaving(false);
router.back();
}
return (
<>
<Stack.Screen
options={{
title: "Edit Task",
headerTitleStyle: defaultStyles.title
}}
/>
<View style={defaultStyles.container}>
<Text style={defaultStyles.title}>Edit Task</Text>
<KeyboardAvoidingView style={{ flex: 1 }} behavior={Platform.OS === "ios" ? "padding" : "height"}>
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View style={defaultStyles.container}>
<TextInput
style={defaultStyles.inputText}
placeholder="Title"
value={title}
onChangeText={SetTitle}
/>
<TextInput
style={defaultStyles.inputText}
placeholder="Text"
value={description}
onChangeText={SetDescription}
/>
<TextInput
style={defaultStyles.inputText}
placeholder="Deadline (YYYY-MM-DD)"
value={deadline}
onChangeText={SetDeadline}
/>
<Pressable
onPress={() => SetIsCompleted(state => !state)}
style={defaultStyles.checkboxContainer}
>
<View style={defaultStyles.checkbox}>
{isCompleted && <Text style={defaultStyles.checkboxMark}></Text>}
</View>
<Text style={defaultStyles.checkboxLabel}>{isCompleted ? 'Completed' : 'Not completed'}</Text>
</Pressable>
<Button title={isSaving ? "Saving..." : "Save"} onPress={EditTask} disabled={isSaving} />
{isSaving && (
<ActivityIndicator size="large" />
)}
<Button title="Cancel" onPress={() => router.back()} />
</View>
</TouchableWithoutFeedback>
</KeyboardAvoidingView>
</View>
</>
)
}

View File

@@ -8,7 +8,7 @@ export default function HomeScreen() {
<View style={defaultStyles.container}>
<Stack.Screen
options={{
title: "Tasks",
title: "Home",
headerTitleStyle: defaultStyles.title,
headerRight: () => {
return (

144
app/(tabs)/subjects.tsx Normal file
View File

@@ -0,0 +1,144 @@
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 Subject = {
sId: string;
title: string;
description: string;
isActive: boolean;
lastChanged: string;
uId: string;
}
export default function Subjects() {
const [subjects, SetSubject] = useState<Subject[]>([])
const [session, SetSession] = useState<Session | null>(null)
const subjectSections = [
{ title: "Active Subjects", data: subjects.filter((subject) => !subject.isActive), emptyMessage: "No active subjects" },
{ title: "Inactive Subjects", data: subjects.filter((subject) => subject.isActive), emptyMessage: "No inactive subjects" },
];
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 GetSubjects = async () => {
const { data, error } = await supabase.from("subjects").select("*");
if (error) {
Alert.alert("Subjects could not be fetched, please try again");
return;
}
SetSubject(data ?? []);
}
useFocusEffect(
useCallback(() => {
if (session) {
GetSubjects();
}
}, [session])
);
const DeleteSubject = async (sId: string) => {
Alert.alert(
"Delete Subject",
"Are you sure you want to delete this subject?",
[
{
text: "Cancel",
style: "cancel"
},
{
text: "Delete",
style: "destructive",
onPress: async () => {
const { error } = await supabase.from("subjects").delete().eq("sId", sId);
if (error) {
Alert.alert("Subject could not be deleted, please try again");
return;
}
Alert.alert("Subject deleted successfully!");
GetSubjects();
}
}
]
)
}
return (
<View style={defaultStyles.container}>
<Stack.Screen
options={{
title: "Subjects",
headerTitleStyle: defaultStyles.title,
headerRight: () => {
return (
<View style={defaultStyles.buttonContainer}>
<Pressable style={defaultStyles.circularButton} onPress={GetSubjects}>
<Ionicons name="refresh" size={22} color="#333" />
</Pressable>
<Button title="Logout" onPress={async () => await supabase.auth.signOut()} />
</View>
)
},
}}
/>
<View style={defaultStyles.buttonContainer}>
<Button title="Create Subject" onPress={() => router.push("/subject/createSubject")} />
</View>
<SectionList
sections={subjectSections}
keyExtractor={(item) => item.sId}
renderSectionHeader={({ section: { title } }) => <Text style={defaultStyles.subtitle}>{title}</Text>}
renderItem={({ item }) => {
const isOwner = session?.user.id === item.uId;
return (
<View style={defaultStyles.container}>
<Pressable style={defaultStyles.buttonContainer} onPress={() => router.push({pathname: "/subject/viewDetailsSubject", params: { sId: item.sId }})}>
<Text style={defaultStyles.title}>{item.title}</Text>
<View style={defaultStyles.checkbox}>
{item.isActive && <Text style={defaultStyles.checkboxMark}></Text>}
</View>
</Pressable>
{isOwner && (
<View style={defaultStyles.buttonContainer}>
<Button title="Edit" onPress={() => router.push({pathname: "/subject/editSubject", params: { sId: item.sId }})} />
<Button title="Delete" onPress={() => DeleteSubject(item.sId)} />
</View>
)}
</View>
);
}}
renderSectionFooter={({ section }) =>
section.data.length === 0 ? (
<View style={defaultStyles.container}>
<Text style={defaultStyles.body}>{section.emptyMessage}</Text>
<View style={defaultStyles.separator} />
</View>
) : (
<View style={defaultStyles.separator} />
)
}
/>
</View>
)
}

View File

@@ -12,8 +12,8 @@ type Task = {
description: string;
isCompleted: boolean;
lastChanged: string;
deadline: string;
uId: string;
aId: string;
}
export default function Tasks() {
@@ -34,6 +34,17 @@ export default function Tasks() {
},
[])
const GetTasks = async () => {
const { data, error } = await supabase.from("tasks").select("*");
if (error) {
Alert.alert("Tasks could not be fetched, please try again");
return;
}
SetTasks(data ?? []);
}
useFocusEffect(
useCallback(() => {
if (session) {
@@ -42,17 +53,6 @@ export default function Tasks() {
}, [session])
);
const GetTasks = async () => {
const { data, error } = await supabase.from("tasks").select("tId, title, description, isCompleted,lastChanged, deadline, uId").order("deadline", { ascending: false });
if (error) {
Alert.alert("Task could not be fetched, please try again");
return;
}
SetTasks(data ?? []);
}
const DeleteTask = async (tId: string) => {
Alert.alert(
"Delete Task",
@@ -101,7 +101,7 @@ export default function Tasks() {
/>
<View style={defaultStyles.buttonContainer}>
<Button title="Create Task" onPress={() => router.push("/createTask")} />
<Button title="Create Task" onPress={() => router.push("/task/createTask")} />
</View>
<SectionList
@@ -113,12 +113,16 @@ export default function Tasks() {
return (
<View style={defaultStyles.container}>
<Text style={defaultStyles.boldBody}>{item.title}</Text>
<Text style={defaultStyles.body}>{item.deadline}</Text>
<Pressable style={defaultStyles.container} onPress={() => router.push({pathname: "/task/viewDetailsTask", params: { tId: item.tId }})}>
<Text style={defaultStyles.boldBody}>{item.title}</Text>
<View style={defaultStyles.checkbox}>
{item.isCompleted && <Text style={defaultStyles.checkboxMark}></Text>}
</View>
</Pressable>
{isOwner && (
<View style={defaultStyles.buttonContainer}>
<Button title="Edit" onPress={() => router.push({pathname: "/editTask", params: { tId: item.tId }})} />
<Button title="Edit" onPress={() => router.push({pathname: "/task/editTask", params: { tId: item.tId }})} />
<Button title="Delete" onPress={() => DeleteTask(item.tId)} />
</View>
)}