WIP backup before merge
This commit is contained in:
3
app.json
3
app.json
@@ -38,7 +38,8 @@
|
|||||||
"backgroundColor": "#000000"
|
"backgroundColor": "#000000"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"expo-secure-store"
|
||||||
],
|
],
|
||||||
"experiments": {
|
"experiments": {
|
||||||
"typedRoutes": true,
|
"typedRoutes": true,
|
||||||
|
|||||||
@@ -33,8 +33,10 @@ export default function TabLayout() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Tabs>
|
<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="tasks" options={{title: "Tasks"}} />
|
||||||
|
<Tabs.Screen name="assignments" options={{title: "Assignments"}} />
|
||||||
|
<Tabs.Screen name="subjects" options={{title: "Subjects"}} />
|
||||||
</Tabs>
|
</Tabs>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
147
app/(tabs)/assignments.tsx
Normal file
147
app/(tabs)/assignments.tsx
Normal 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>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ export default function HomeScreen() {
|
|||||||
<View style={defaultStyles.container}>
|
<View style={defaultStyles.container}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
title: "Tasks",
|
title: "Home",
|
||||||
headerTitleStyle: defaultStyles.title,
|
headerTitleStyle: defaultStyles.title,
|
||||||
headerRight: () => {
|
headerRight: () => {
|
||||||
return (
|
return (
|
||||||
|
|||||||
144
app/(tabs)/subjects.tsx
Normal file
144
app/(tabs)/subjects.tsx
Normal 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>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -12,8 +12,8 @@ type Task = {
|
|||||||
description: string;
|
description: string;
|
||||||
isCompleted: boolean;
|
isCompleted: boolean;
|
||||||
lastChanged: string;
|
lastChanged: string;
|
||||||
deadline: string;
|
|
||||||
uId: string;
|
uId: string;
|
||||||
|
aId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Tasks() {
|
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(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
if (session) {
|
if (session) {
|
||||||
@@ -42,17 +53,6 @@ export default function Tasks() {
|
|||||||
}, [session])
|
}, [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) => {
|
const DeleteTask = async (tId: string) => {
|
||||||
Alert.alert(
|
Alert.alert(
|
||||||
"Delete Task",
|
"Delete Task",
|
||||||
@@ -101,7 +101,7 @@ export default function Tasks() {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<View style={defaultStyles.buttonContainer}>
|
<View style={defaultStyles.buttonContainer}>
|
||||||
<Button title="Create Task" onPress={() => router.push("/createTask")} />
|
<Button title="Create Task" onPress={() => router.push("/task/createTask")} />
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<SectionList
|
<SectionList
|
||||||
@@ -113,12 +113,16 @@ export default function Tasks() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={defaultStyles.container}>
|
<View style={defaultStyles.container}>
|
||||||
<Text style={defaultStyles.boldBody}>{item.title}</Text>
|
<Pressable style={defaultStyles.container} onPress={() => router.push({pathname: "/task/viewDetailsTask", params: { tId: item.tId }})}>
|
||||||
<Text style={defaultStyles.body}>{item.deadline}</Text>
|
<Text style={defaultStyles.boldBody}>{item.title}</Text>
|
||||||
|
<View style={defaultStyles.checkbox}>
|
||||||
|
{item.isCompleted && <Text style={defaultStyles.checkboxMark}>✓</Text>}
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
|
|
||||||
{isOwner && (
|
{isOwner && (
|
||||||
<View style={defaultStyles.buttonContainer}>
|
<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)} />
|
<Button title="Delete" onPress={() => DeleteTask(item.tId)} />
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,43 +1,20 @@
|
|||||||
import { defaultStyles } from '@/constants/defaultStyles';
|
import { defaultStyles } from '@/constants/defaultStyles';
|
||||||
import { supabase } from '@/lib/supabase';
|
import { supabase } from '@/lib/supabase';
|
||||||
import { router, Stack, useFocusEffect, useLocalSearchParams } from 'expo-router';
|
import { router, Stack, useLocalSearchParams } from 'expo-router';
|
||||||
import { useCallback, useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { ActivityIndicator, Alert, Button, Keyboard, KeyboardAvoidingView, Platform, Pressable, Text, TextInput, TouchableWithoutFeedback, View } from 'react-native';
|
import { ActivityIndicator, Alert, Button, Keyboard, KeyboardAvoidingView, Platform, Pressable, Text, TextInput, TouchableWithoutFeedback, View } from 'react-native';
|
||||||
|
|
||||||
export default function EditTask() {
|
export default function CreateAssignment() {
|
||||||
|
const sId = (useLocalSearchParams().sId as string) ?? null;
|
||||||
const [title, SetTitle] = useState('');
|
const [title, SetTitle] = useState('');
|
||||||
const [description, SetDescription] = useState('');
|
const [description, SetDescription] = useState('');
|
||||||
const [isCompleted, SetIsCompleted] = useState(false);
|
|
||||||
const [deadline, SetDeadline] = useState('');
|
const [deadline, SetDeadline] = useState('');
|
||||||
|
const [isCompleted, SetIsCompleted] = useState(false);
|
||||||
const [isSaving, SetIsSaving] = useState(false);
|
const [isSaving, SetIsSaving] = useState(false);
|
||||||
const { tId } = useLocalSearchParams();
|
|
||||||
|
|
||||||
useFocusEffect(
|
const CreateAssignment = async () => {
|
||||||
useCallback(() => {
|
if(title.trim() === '' || deadline.trim() === '') {
|
||||||
const GetTask = async () => {
|
Alert.alert("Title and deadline are required!");
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,26 +27,27 @@ export default function EditTask() {
|
|||||||
|
|
||||||
SetIsSaving(true);
|
SetIsSaving(true);
|
||||||
|
|
||||||
const { error: dbError } = await supabase.from("tasks").update({
|
const { error: dbError } = await supabase.from("assignments").insert({
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
|
deadline,
|
||||||
isCompleted,
|
isCompleted,
|
||||||
lastChanged: new Date().toISOString(),
|
lastChanged: new Date().toISOString(),
|
||||||
deadline,
|
|
||||||
uId: data.user.id,
|
uId: data.user.id,
|
||||||
}).eq("tId", tId);
|
sId: sId,
|
||||||
|
});
|
||||||
|
|
||||||
if (dbError) {
|
if (dbError) {
|
||||||
Alert.alert("Task could not be edited, please try again");
|
Alert.alert("Assignment could not be created, please try again");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Alert.alert("Task successfully edited!");
|
Alert.alert("Assignment successfully created!");
|
||||||
|
|
||||||
SetTitle('');
|
SetTitle('');
|
||||||
SetDescription('');
|
SetDescription('');
|
||||||
SetIsCompleted(false);
|
|
||||||
SetDeadline('');
|
SetDeadline('');
|
||||||
|
SetIsCompleted(false);
|
||||||
|
|
||||||
SetIsSaving(false);
|
SetIsSaving(false);
|
||||||
|
|
||||||
@@ -80,25 +58,25 @@ export default function EditTask() {
|
|||||||
<>
|
<>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
title: "Edit Task",
|
title: "Create Assignment",
|
||||||
headerTitleStyle: defaultStyles.title
|
headerTitleStyle: defaultStyles.title
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<View style={defaultStyles.container}>
|
<View style={defaultStyles.container}>
|
||||||
<Text style={defaultStyles.title}>Edit Task</Text>
|
<Text style={defaultStyles.title}>Create New Assignment</Text>
|
||||||
<KeyboardAvoidingView style={{ flex: 1 }} behavior={Platform.OS === "ios" ? "padding" : "height"}>
|
<KeyboardAvoidingView style={{ flex: 1 }} behavior={Platform.OS === "ios" ? "padding" : "height"}>
|
||||||
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
|
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
|
||||||
<View style={defaultStyles.container}>
|
<View style={defaultStyles.container}>
|
||||||
<TextInput
|
<TextInput
|
||||||
style={defaultStyles.inputText}
|
style={defaultStyles.inputText}
|
||||||
placeholder="Title"
|
placeholder="Enter title"
|
||||||
value={title}
|
value={title}
|
||||||
onChangeText={SetTitle}
|
onChangeText={SetTitle}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
style={defaultStyles.inputText}
|
style={defaultStyles.inputText}
|
||||||
placeholder="Text"
|
placeholder="Enter description"
|
||||||
value={description}
|
value={description}
|
||||||
onChangeText={SetDescription}
|
onChangeText={SetDescription}
|
||||||
/>
|
/>
|
||||||
@@ -118,7 +96,7 @@ export default function EditTask() {
|
|||||||
<Text style={defaultStyles.checkboxLabel}>{isCompleted ? 'Completed' : 'Not completed'}</Text>
|
<Text style={defaultStyles.checkboxLabel}>{isCompleted ? 'Completed' : 'Not completed'}</Text>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
|
|
||||||
<Button title={isSaving ? "Saving..." : "Save"} onPress={EditTask} disabled={isSaving} />
|
<Button title={isSaving ? "Saving..." : "Save"} onPress={CreateAssignment} disabled={isSaving} />
|
||||||
{isSaving && (
|
{isSaving && (
|
||||||
<ActivityIndicator size="large" />
|
<ActivityIndicator size="large" />
|
||||||
)}
|
)}
|
||||||
143
app/assignment/editAssignment.tsx
Normal file
143
app/assignment/editAssignment.tsx
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
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';
|
||||||
|
|
||||||
|
type Assignment = {
|
||||||
|
aId: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
deadline: string;
|
||||||
|
isCompleted: boolean;
|
||||||
|
lastChanged: string;
|
||||||
|
uId: string;
|
||||||
|
sId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function EditAssignment() {
|
||||||
|
const { aId } = useLocalSearchParams<{ aId: string }>();
|
||||||
|
const [assignment, SetAssignment] = useState<Assignment | null>(null)
|
||||||
|
const [isSaving, SetIsSaving] = useState(false);
|
||||||
|
|
||||||
|
const GetAssignment = async (aId: string) => {
|
||||||
|
const { data, error } = await supabase.from("assignments").select("*").eq("aId", aId).single();
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
Alert.alert("Assignment could not be fetched, please try again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetAssignment(data ?? null);
|
||||||
|
}
|
||||||
|
|
||||||
|
useFocusEffect(
|
||||||
|
useCallback(() => {
|
||||||
|
if (aId) {
|
||||||
|
GetAssignment(aId);
|
||||||
|
}
|
||||||
|
}, [aId])
|
||||||
|
);
|
||||||
|
|
||||||
|
const EditAssignment = async () => {
|
||||||
|
if (!assignment) return;
|
||||||
|
|
||||||
|
if(assignment.title.trim() === '' || assignment.deadline.trim() === '') {
|
||||||
|
Alert.alert("Title and deadline 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("assignments").update({
|
||||||
|
title: assignment.title,
|
||||||
|
description: assignment.description,
|
||||||
|
deadline: assignment.deadline,
|
||||||
|
isCompleted: assignment.isCompleted,
|
||||||
|
lastChanged: new Date().toISOString(),
|
||||||
|
uId: data.user.id,
|
||||||
|
sId: assignment.sId,
|
||||||
|
}).eq("aId", aId);
|
||||||
|
|
||||||
|
SetIsSaving(false);
|
||||||
|
|
||||||
|
if (dbError) {
|
||||||
|
Alert.alert("Assignment could not be edited, please try again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Alert.alert("Assignment successfully edited!");
|
||||||
|
|
||||||
|
router.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<Stack.Screen
|
||||||
|
options={{
|
||||||
|
title: "Edit Assignment",
|
||||||
|
headerTitleStyle: defaultStyles.title
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{!assignment && (
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<Text style={defaultStyles.title}>Assignment not found</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{assignment && (
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<Text style={defaultStyles.title}>Edit Assignment</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={assignment.title}
|
||||||
|
onChangeText={(text) => SetAssignment(prev => prev ? { ...prev, title: text } : prev)}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
style={defaultStyles.inputText}
|
||||||
|
placeholder="Text"
|
||||||
|
value={assignment.description}
|
||||||
|
onChangeText={(text) => SetAssignment(prev => prev ? { ...prev, description: text } : prev)}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
style={defaultStyles.inputText}
|
||||||
|
placeholder="Text"
|
||||||
|
value={assignment.deadline}
|
||||||
|
onChangeText={(text) => SetAssignment(prev => prev ? { ...prev, deadline: text } : prev)}
|
||||||
|
/>
|
||||||
|
<Pressable
|
||||||
|
onPress={() => SetAssignment(prev => prev ? { ...prev, isCompleted: !prev.isCompleted } : prev)}
|
||||||
|
style={defaultStyles.checkboxContainer}
|
||||||
|
>
|
||||||
|
<View style={defaultStyles.checkbox}>
|
||||||
|
{assignment.isCompleted && <Text style={defaultStyles.checkboxMark}>✓</Text>}
|
||||||
|
</View>
|
||||||
|
<Text style={defaultStyles.checkboxLabel}>{assignment.isCompleted ? 'Completed' : 'Not Completed'}</Text>
|
||||||
|
</Pressable>
|
||||||
|
|
||||||
|
<Button title={isSaving ? "Saving..." : "Save"} onPress={EditAssignment} disabled={isSaving} />
|
||||||
|
{isSaving && (
|
||||||
|
<ActivityIndicator size="large" />
|
||||||
|
)}
|
||||||
|
<Button title="Cancel" onPress={() => router.back()} />
|
||||||
|
</View>
|
||||||
|
</TouchableWithoutFeedback>
|
||||||
|
</KeyboardAvoidingView>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
224
app/assignment/viewDetailsAssignment.tsx
Normal file
224
app/assignment/viewDetailsAssignment.tsx
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
import { defaultStyles } from '@/constants/defaultStyles';
|
||||||
|
import { supabase } from '@/lib/supabase';
|
||||||
|
import { Session } from '@supabase/supabase-js';
|
||||||
|
import { router, Stack, useFocusEffect, useLocalSearchParams } 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
type Task = {
|
||||||
|
tId: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
isCompleted: boolean;
|
||||||
|
lastChanged: string;
|
||||||
|
uId: string;
|
||||||
|
aId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ViewDetailsAssignment() {
|
||||||
|
const { aId } = useLocalSearchParams<{ aId: string }>();
|
||||||
|
const [assignment, SetAssignment] = useState<Assignment | null>(null)
|
||||||
|
const [tasks, SetTasks] = useState<Task[]>([])
|
||||||
|
const [session, SetSession] = useState<Session | null>(null)
|
||||||
|
|
||||||
|
const taskSections = [
|
||||||
|
{ title: "Upcoming Tasks", data: tasks.filter((task) => !task.isCompleted), emptyMessage: "No upcoming tasks" },
|
||||||
|
{ title: "Completed Tasks", data: tasks.filter((task) => task.isCompleted), emptyMessage: "No completed tasks" },
|
||||||
|
];
|
||||||
|
|
||||||
|
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 GetAssignment = async (aId: string) => {
|
||||||
|
const { data, error } = await supabase.from("assignments").select("*").eq("aId", aId).single();
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
Alert.alert("Assignment could not be fetched, please try again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetAssignment(data ?? null);
|
||||||
|
}
|
||||||
|
|
||||||
|
const GetTasks = async (aId: string) => {
|
||||||
|
const { data, error } = await supabase.from("tasks").select("*").eq("aId", aId);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
Alert.alert("Tasks could not be fetched, please try again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetTasks(data ?? []);
|
||||||
|
}
|
||||||
|
|
||||||
|
useFocusEffect(
|
||||||
|
useCallback(() => {
|
||||||
|
if (session && aId) {
|
||||||
|
GetAssignment(aId);
|
||||||
|
GetTasks(aId);
|
||||||
|
}
|
||||||
|
}, [session, aId])
|
||||||
|
);
|
||||||
|
|
||||||
|
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!");
|
||||||
|
router.back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const DeleteTask = async (tId: string, aId: string) => {
|
||||||
|
Alert.alert(
|
||||||
|
"Delete Task",
|
||||||
|
"Are you sure you want to delete this task?",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
text: "Cancel",
|
||||||
|
style: "cancel"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "Delete",
|
||||||
|
style: "destructive",
|
||||||
|
onPress: async () => {
|
||||||
|
const { error } = await supabase.from("tasks").delete().eq("tId", tId);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
Alert.alert("Task could not be deleted, please try again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Alert.alert("Task deleted successfully!");
|
||||||
|
GetTasks(aId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<Stack.Screen
|
||||||
|
options={{
|
||||||
|
title: "Details",
|
||||||
|
headerTitleStyle: defaultStyles.title,
|
||||||
|
headerLeft: () => {
|
||||||
|
return (
|
||||||
|
<View style={defaultStyles.buttonContainer}>
|
||||||
|
<Button title="Back" onPress={router.back} />
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
headerRight: () => {
|
||||||
|
return (
|
||||||
|
<View style={defaultStyles.buttonContainer}>
|
||||||
|
<Button title="Logout" onPress={async () => await supabase.auth.signOut()} />
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{!assignment && (
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<Text style={defaultStyles.title}>Assignment not found</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{assignment && (
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<Text style={defaultStyles.title}>{assignment.title}</Text>
|
||||||
|
<Text style={defaultStyles.body}>{assignment.description}</Text>
|
||||||
|
<Text style={defaultStyles.body}>{assignment.deadline}</Text>
|
||||||
|
<View style={defaultStyles.checkbox}>
|
||||||
|
{assignment.isCompleted && <Text style={defaultStyles.checkboxMark}>✓</Text>}
|
||||||
|
</View>
|
||||||
|
<Text style={defaultStyles.body}>{assignment.lastChanged}</Text>
|
||||||
|
|
||||||
|
<Button title="Edit" onPress={() => router.push({pathname: "/assignment/editAssignment", params: { aId: assignment.aId }})} />
|
||||||
|
<Button title="Delete" onPress={() => DeleteAssignment(assignment.aId)} />
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={defaultStyles.buttonContainer}>
|
||||||
|
<Button title="Create Task" onPress={() => router.push({pathname: "/task/createTask", params: { aId: assignment.aId }})} />
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<SectionList
|
||||||
|
sections={taskSections}
|
||||||
|
keyExtractor={(item) => item.tId}
|
||||||
|
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: "/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: "/task/editTask", params: { tId: item.tId }})} />
|
||||||
|
<Button title="Delete" onPress={() => DeleteTask(item.tId, item.tId)} />
|
||||||
|
</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>
|
||||||
|
);
|
||||||
|
}
|
||||||
100
app/subject/createSubject.tsx
Normal file
100
app/subject/createSubject.tsx
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
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 [isActive, SetIsActive] = useState(true);
|
||||||
|
const [isSaving, SetIsSaving] = useState(false);
|
||||||
|
|
||||||
|
const CreateSubject = async () => {
|
||||||
|
if(title.trim() === '') {
|
||||||
|
Alert.alert("Title is 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("subjects").insert({
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
isActive,
|
||||||
|
lastChanged: new Date().toISOString(),
|
||||||
|
uId: data.user.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (dbError) {
|
||||||
|
Alert.alert("Subject could not be created, please try again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Alert.alert("Subject successfully created!");
|
||||||
|
|
||||||
|
SetTitle('');
|
||||||
|
SetDescription('');
|
||||||
|
SetIsActive(false);
|
||||||
|
|
||||||
|
SetIsSaving(false);
|
||||||
|
|
||||||
|
router.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Stack.Screen
|
||||||
|
options={{
|
||||||
|
title: "Create Subject",
|
||||||
|
headerTitleStyle: defaultStyles.title
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<Text style={defaultStyles.title}>Create New Subject</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}
|
||||||
|
/>
|
||||||
|
<Pressable
|
||||||
|
onPress={() => SetIsActive(state => !state)}
|
||||||
|
style={defaultStyles.checkboxContainer}
|
||||||
|
>
|
||||||
|
<View style={defaultStyles.checkbox}>
|
||||||
|
{isActive && <Text style={defaultStyles.checkboxMark}>✓</Text>}
|
||||||
|
</View>
|
||||||
|
<Text style={defaultStyles.checkboxLabel}>{isActive ? 'Active' : 'Inactive'}</Text>
|
||||||
|
</Pressable>
|
||||||
|
|
||||||
|
<Button title={isSaving ? "Saving..." : "Save"} onPress={CreateSubject} disabled={isSaving} />
|
||||||
|
{isSaving && (
|
||||||
|
<ActivityIndicator size="large" />
|
||||||
|
)}
|
||||||
|
<Button title="Cancel" onPress={() => router.back()} />
|
||||||
|
</View>
|
||||||
|
</TouchableWithoutFeedback>
|
||||||
|
</KeyboardAvoidingView>
|
||||||
|
</View>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
133
app/subject/editSubject.tsx
Normal file
133
app/subject/editSubject.tsx
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
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';
|
||||||
|
|
||||||
|
type Subject = {
|
||||||
|
sId: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
isActive: boolean;
|
||||||
|
lastChanged: string;
|
||||||
|
uId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function EditSubject() {
|
||||||
|
const { sId } = useLocalSearchParams<{ sId: string }>();
|
||||||
|
const [subject, SetSubject] = useState<Subject | null>(null)
|
||||||
|
const [isSaving, SetIsSaving] = useState(false);
|
||||||
|
|
||||||
|
const GetSubject = async (sId: string) => {
|
||||||
|
const { data, error } = await supabase.from("subjects").select("*").eq("sId", sId).single();
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
Alert.alert("Subject could not be fetched, please try again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetSubject(data ?? null);
|
||||||
|
}
|
||||||
|
|
||||||
|
useFocusEffect(
|
||||||
|
useCallback(() => {
|
||||||
|
if (sId) {
|
||||||
|
GetSubject(sId);
|
||||||
|
}
|
||||||
|
}, [sId])
|
||||||
|
);
|
||||||
|
|
||||||
|
const EditSubject = async () => {
|
||||||
|
if (!subject) return;
|
||||||
|
|
||||||
|
if(subject.title.trim() === '') {
|
||||||
|
Alert.alert("Title is 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("subjects").update({
|
||||||
|
title: subject.title,
|
||||||
|
description: subject.description,
|
||||||
|
isActive: subject.isActive,
|
||||||
|
lastChanged: new Date().toISOString(),
|
||||||
|
uId: data.user.id,
|
||||||
|
}).eq("sId", sId);
|
||||||
|
|
||||||
|
SetIsSaving(false);
|
||||||
|
|
||||||
|
if (dbError) {
|
||||||
|
Alert.alert("Subject could not be edited, please try again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Alert.alert("Subject successfully edited!");
|
||||||
|
|
||||||
|
router.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<Stack.Screen
|
||||||
|
options={{
|
||||||
|
title: "Edit Subject",
|
||||||
|
headerTitleStyle: defaultStyles.title
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{!subject && (
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<Text style={defaultStyles.title}>Subject not found</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{subject && (
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<Text style={defaultStyles.title}>Edit Subject</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={subject.title}
|
||||||
|
onChangeText={(text) => SetSubject(prev => prev ? { ...prev, title: text } : prev)}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
style={defaultStyles.inputText}
|
||||||
|
placeholder="Text"
|
||||||
|
value={subject.description}
|
||||||
|
onChangeText={(text) => SetSubject(prev => prev ? { ...prev, description: text } : prev)}
|
||||||
|
/>
|
||||||
|
<Pressable
|
||||||
|
onPress={() => SetSubject(prev => prev ? { ...prev, isActive: !prev.isActive } : prev)}
|
||||||
|
style={defaultStyles.checkboxContainer}
|
||||||
|
>
|
||||||
|
<View style={defaultStyles.checkbox}>
|
||||||
|
{subject.isActive && <Text style={defaultStyles.checkboxMark}>✓</Text>}
|
||||||
|
</View>
|
||||||
|
<Text style={defaultStyles.checkboxLabel}>{subject.isActive ? 'Active' : 'inactive'}</Text>
|
||||||
|
</Pressable>
|
||||||
|
|
||||||
|
<Button title={isSaving ? "Saving..." : "Save"} onPress={EditSubject} disabled={isSaving} />
|
||||||
|
{isSaving && (
|
||||||
|
<ActivityIndicator size="large" />
|
||||||
|
)}
|
||||||
|
<Button title="Cancel" onPress={() => router.back()} />
|
||||||
|
</View>
|
||||||
|
</TouchableWithoutFeedback>
|
||||||
|
</KeyboardAvoidingView>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
223
app/subject/viewDetailsSubject.tsx
Normal file
223
app/subject/viewDetailsSubject.tsx
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
import { defaultStyles } from '@/constants/defaultStyles';
|
||||||
|
import { supabase } from '@/lib/supabase';
|
||||||
|
import { Session } from '@supabase/supabase-js';
|
||||||
|
import { router, Stack, useFocusEffect, useLocalSearchParams } 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
type Assignment = {
|
||||||
|
aId: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
deadline: string;
|
||||||
|
isCompleted: boolean;
|
||||||
|
lastChanged: string;
|
||||||
|
uId: string;
|
||||||
|
sId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ViewDetailsSubject() {
|
||||||
|
const { sId } = useLocalSearchParams<{ sId: string }>();
|
||||||
|
const [subject, SetSubject] = useState<Subject | null>(null)
|
||||||
|
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 GetSubject = async (sId: string) => {
|
||||||
|
const { data, error } = await supabase.from("subjects").select("*").eq("sId", sId).single();
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
Alert.alert("Subject could not be fetched, please try again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetSubject(data ?? null);
|
||||||
|
}
|
||||||
|
|
||||||
|
const GetAssignments = async (sId: string) => {
|
||||||
|
const { data, error } = await supabase.from("assignments").select("*").eq("sId", sId).order("deadline", { ascending: true });
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
Alert.alert("Assignments could not be fetched, please try again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetAssignments(data ?? []);
|
||||||
|
}
|
||||||
|
|
||||||
|
useFocusEffect(
|
||||||
|
useCallback(() => {
|
||||||
|
if (session && sId) {
|
||||||
|
GetSubject(sId);
|
||||||
|
GetAssignments(sId);
|
||||||
|
}
|
||||||
|
}, [session, sId])
|
||||||
|
);
|
||||||
|
|
||||||
|
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!");
|
||||||
|
router.back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const DeleteAssignment = async (aId: string, sId: 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(sId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<Stack.Screen
|
||||||
|
options={{
|
||||||
|
title: "Details",
|
||||||
|
headerTitleStyle: defaultStyles.title,
|
||||||
|
headerLeft: () => {
|
||||||
|
return (
|
||||||
|
<View style={defaultStyles.buttonContainer}>
|
||||||
|
<Button title="Back" onPress={router.back} />
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
headerRight: () => {
|
||||||
|
return (
|
||||||
|
<View style={defaultStyles.buttonContainer}>
|
||||||
|
<Button title="Logout" onPress={async () => await supabase.auth.signOut()} />
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{!subject && (
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<Text style={defaultStyles.title}>Subject not found</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{subject && (
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<Text style={defaultStyles.title}>{subject.title}</Text>
|
||||||
|
<Text style={defaultStyles.body}>{subject.description}</Text>
|
||||||
|
<View style={defaultStyles.checkbox}>
|
||||||
|
{subject.isActive && <Text style={defaultStyles.checkboxMark}>✓</Text>}
|
||||||
|
</View>
|
||||||
|
<Text style={defaultStyles.body}>{subject.lastChanged}</Text>
|
||||||
|
|
||||||
|
<Button title="Edit" onPress={() => router.push({pathname: "/subject/editSubject", params: { sId: subject.sId }})} />
|
||||||
|
<Button title="Delete" onPress={() => DeleteSubject(subject.sId)} />
|
||||||
|
|
||||||
|
<View style={defaultStyles.buttonContainer}>
|
||||||
|
<Button title="Create Assignment" onPress={() => router.push({pathname: "/assignment/createAssignment", params: { sId: subject.sId }})} />
|
||||||
|
</View>
|
||||||
|
</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, 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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
import { defaultStyles } from '@/constants/defaultStyles';
|
import { defaultStyles } from '@/constants/defaultStyles';
|
||||||
import { supabase } from '@/lib/supabase';
|
import { supabase } from '@/lib/supabase';
|
||||||
import { router, Stack } from 'expo-router';
|
import { router, Stack, useLocalSearchParams } from 'expo-router';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { ActivityIndicator, Alert, Button, Keyboard, KeyboardAvoidingView, Platform, Pressable, Text, TextInput, TouchableWithoutFeedback, View } from 'react-native';
|
import { ActivityIndicator, Alert, Button, Keyboard, KeyboardAvoidingView, Platform, Pressable, Text, TextInput, TouchableWithoutFeedback, View } from 'react-native';
|
||||||
|
|
||||||
export default function CreateTask() {
|
export default function CreateTask() {
|
||||||
|
const aId = (useLocalSearchParams().aId as string) ?? null;
|
||||||
const [title, SetTitle] = useState('');
|
const [title, SetTitle] = useState('');
|
||||||
const [description, SetDescription] = useState('');
|
const [description, SetDescription] = useState('');
|
||||||
const [isCompleted, SetIsCompleted] = useState(false);
|
const [isCompleted, SetIsCompleted] = useState(false);
|
||||||
const [deadline, SetDeadline] = useState('');
|
|
||||||
const [isSaving, SetIsSaving] = useState(false);
|
const [isSaving, SetIsSaving] = useState(false);
|
||||||
|
|
||||||
const AddNote = async () => {
|
const CreateTask = async () => {
|
||||||
if(title.trim() === '' || description.trim() === '' || deadline.trim() === '') {
|
if(title.trim() === '') {
|
||||||
Alert.alert("All fields are required!");
|
Alert.alert("Title is required!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,22 +31,20 @@ export default function CreateTask() {
|
|||||||
description,
|
description,
|
||||||
isCompleted,
|
isCompleted,
|
||||||
lastChanged: new Date().toISOString(),
|
lastChanged: new Date().toISOString(),
|
||||||
deadline,
|
|
||||||
uId: data.user.id,
|
uId: data.user.id,
|
||||||
|
aId: aId,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (dbError) {
|
if (dbError) {
|
||||||
Alert.alert("Task could not be created, please try again");
|
Alert.alert("Task could not be created, please try again");
|
||||||
SetIsSaving(false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Alert.alert("Task successfully added!");
|
Alert.alert("Task successfully created!");
|
||||||
|
|
||||||
SetTitle('');
|
SetTitle('');
|
||||||
SetDescription('');
|
SetDescription('');
|
||||||
SetIsCompleted(false);
|
SetIsCompleted(false);
|
||||||
SetDeadline('');
|
|
||||||
|
|
||||||
SetIsSaving(false);
|
SetIsSaving(false);
|
||||||
|
|
||||||
@@ -79,12 +77,7 @@ export default function CreateTask() {
|
|||||||
value={description}
|
value={description}
|
||||||
onChangeText={SetDescription}
|
onChangeText={SetDescription}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
|
||||||
style={defaultStyles.inputText}
|
|
||||||
placeholder="Deadline (YYYY-MM-DD)"
|
|
||||||
value={deadline}
|
|
||||||
onChangeText={SetDeadline}
|
|
||||||
/>
|
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={() => SetIsCompleted(state => !state)}
|
onPress={() => SetIsCompleted(state => !state)}
|
||||||
style={defaultStyles.checkboxContainer}
|
style={defaultStyles.checkboxContainer}
|
||||||
@@ -95,7 +88,7 @@ export default function CreateTask() {
|
|||||||
<Text style={defaultStyles.checkboxLabel}>{isCompleted ? 'Completed' : 'Not completed'}</Text>
|
<Text style={defaultStyles.checkboxLabel}>{isCompleted ? 'Completed' : 'Not completed'}</Text>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
|
|
||||||
<Button title={isSaving ? "Saving..." : "Save"} onPress={AddNote} disabled={isSaving} />
|
<Button title={isSaving ? "Saving..." : "Save"} onPress={CreateTask} disabled={isSaving} />
|
||||||
{isSaving && (
|
{isSaving && (
|
||||||
<ActivityIndicator size="large" />
|
<ActivityIndicator size="large" />
|
||||||
)}
|
)}
|
||||||
135
app/task/editTask.tsx
Normal file
135
app/task/editTask.tsx
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
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';
|
||||||
|
|
||||||
|
type Task = {
|
||||||
|
tId: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
isCompleted: boolean;
|
||||||
|
lastChanged: string;
|
||||||
|
uId: string;
|
||||||
|
aId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function EditTask() {
|
||||||
|
const { tId } = useLocalSearchParams<{ tId: string }>();
|
||||||
|
const [task, SetTask] = useState<Task | null>(null)
|
||||||
|
const [isSaving, SetIsSaving] = useState(false);
|
||||||
|
|
||||||
|
const GetTask = async (tId: string) => {
|
||||||
|
const { data, error } = await supabase.from("tasks").select("*").eq("tId", tId).single();
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
Alert.alert("Task could not be fetched, please try again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetTask(data ?? null);
|
||||||
|
}
|
||||||
|
|
||||||
|
useFocusEffect(
|
||||||
|
useCallback(() => {
|
||||||
|
if (tId) {
|
||||||
|
GetTask(tId);
|
||||||
|
}
|
||||||
|
}, [tId])
|
||||||
|
);
|
||||||
|
|
||||||
|
const EditTask = async () => {
|
||||||
|
if (!task) return;
|
||||||
|
|
||||||
|
if(task.title.trim() === '') {
|
||||||
|
Alert.alert("Title is 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: task.title,
|
||||||
|
description: task.description,
|
||||||
|
isCompleted: task.isCompleted,
|
||||||
|
lastChanged: new Date().toISOString(),
|
||||||
|
uId: data.user.id,
|
||||||
|
aId: task.aId,
|
||||||
|
}).eq("tId", tId);
|
||||||
|
|
||||||
|
SetIsSaving(false);
|
||||||
|
|
||||||
|
if (dbError) {
|
||||||
|
Alert.alert("Task could not be edited, please try again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Alert.alert("Task successfully edited!");
|
||||||
|
|
||||||
|
router.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<Stack.Screen
|
||||||
|
options={{
|
||||||
|
title: "Edit Task",
|
||||||
|
headerTitleStyle: defaultStyles.title
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{!task && (
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<Text style={defaultStyles.title}>Task not found</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{task && (
|
||||||
|
<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={task.title}
|
||||||
|
onChangeText={(text) => SetTask(prev => prev ? { ...prev, title: text } : prev)}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
style={defaultStyles.inputText}
|
||||||
|
placeholder="Text"
|
||||||
|
value={task.description}
|
||||||
|
onChangeText={(text) => SetTask(prev => prev ? { ...prev, description: text } : prev)}
|
||||||
|
/>
|
||||||
|
<Pressable
|
||||||
|
onPress={() => SetTask(prev => prev ? { ...prev, isCompleted: !prev.isCompleted } : prev)}
|
||||||
|
style={defaultStyles.checkboxContainer}
|
||||||
|
>
|
||||||
|
<View style={defaultStyles.checkbox}>
|
||||||
|
{task.isCompleted && <Text style={defaultStyles.checkboxMark}>✓</Text>}
|
||||||
|
</View>
|
||||||
|
<Text style={defaultStyles.checkboxLabel}>{task.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>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
125
app/task/viewDetailsTask.tsx
Normal file
125
app/task/viewDetailsTask.tsx
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
import { defaultStyles } from '@/constants/defaultStyles';
|
||||||
|
import { supabase } from '@/lib/supabase';
|
||||||
|
import { Session } from '@supabase/supabase-js';
|
||||||
|
import { router, Stack, useFocusEffect, useLocalSearchParams } from 'expo-router';
|
||||||
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
|
import { Alert, Button, Text, View } from "react-native";
|
||||||
|
|
||||||
|
type Task = {
|
||||||
|
tId: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
isCompleted: boolean;
|
||||||
|
lastChanged: string;
|
||||||
|
uId: string;
|
||||||
|
aId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ViewDetailsTask() {
|
||||||
|
const { tId } = useLocalSearchParams<{ tId: string }>();
|
||||||
|
const [task, SetTask] = useState<Task | null>(null)
|
||||||
|
const [session, SetSession] = useState<Session | null>(null)
|
||||||
|
|
||||||
|
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 GetTask = async (tId: string) => {
|
||||||
|
const { data, error } = await supabase.from("tasks").select("*").eq("tId", tId).single();
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
Alert.alert("Task could not be fetched, please try again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetTask(data ?? null);
|
||||||
|
}
|
||||||
|
|
||||||
|
useFocusEffect(
|
||||||
|
useCallback(() => {
|
||||||
|
if (session && tId) {
|
||||||
|
GetTask(tId);
|
||||||
|
}
|
||||||
|
}, [session, tId])
|
||||||
|
);
|
||||||
|
|
||||||
|
const DeleteTask = async (tId: string) => {
|
||||||
|
Alert.alert(
|
||||||
|
"Delete Task",
|
||||||
|
"Are you sure you want to delete this task?",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
text: "Cancel",
|
||||||
|
style: "cancel"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "Delete",
|
||||||
|
style: "destructive",
|
||||||
|
onPress: async () => {
|
||||||
|
const { error } = await supabase.from("tasks").delete().eq("tId", tId);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
Alert.alert("Task could not be deleted, please try again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Alert.alert("Task deleted successfully!");
|
||||||
|
router.back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<Stack.Screen
|
||||||
|
options={{
|
||||||
|
title: "Details",
|
||||||
|
headerTitleStyle: defaultStyles.title,
|
||||||
|
headerLeft: () => {
|
||||||
|
return (
|
||||||
|
<View style={defaultStyles.buttonContainer}>
|
||||||
|
<Button title="Back" onPress={router.back} />
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
headerRight: () => {
|
||||||
|
return (
|
||||||
|
<View style={defaultStyles.buttonContainer}>
|
||||||
|
<Button title="Logout" onPress={async () => await supabase.auth.signOut()} />
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{!task && (
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<Text style={defaultStyles.title}>Task not found</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{task && (
|
||||||
|
<View style={defaultStyles.container}>
|
||||||
|
<Text style={defaultStyles.title}>{task.title}</Text>
|
||||||
|
<Text style={defaultStyles.body}>{task.description}</Text>
|
||||||
|
<View style={defaultStyles.checkbox}>
|
||||||
|
{task.isCompleted && <Text style={defaultStyles.checkboxMark}>✓</Text>}
|
||||||
|
</View>
|
||||||
|
<Text style={defaultStyles.body}>{task.lastChanged}</Text>
|
||||||
|
|
||||||
|
<View style={defaultStyles.buttonContainer}>
|
||||||
|
<Button title="Edit" onPress={() => router.push({pathname: "/task/editTask", params: { tId: task.tId }})} />
|
||||||
|
<Button title="Delete" onPress={() => DeleteTask(task.tId)} />
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
8
package-lock.json
generated
8
package-lock.json
generated
@@ -20,7 +20,7 @@
|
|||||||
"expo-image": "~3.0.11",
|
"expo-image": "~3.0.11",
|
||||||
"expo-linking": "~8.0.11",
|
"expo-linking": "~8.0.11",
|
||||||
"expo-router": "~6.0.23",
|
"expo-router": "~6.0.23",
|
||||||
"expo-secure-store": "^55.0.13",
|
"expo-secure-store": "~15.0.8",
|
||||||
"expo-splash-screen": "~31.0.13",
|
"expo-splash-screen": "~31.0.13",
|
||||||
"expo-status-bar": "~3.0.9",
|
"expo-status-bar": "~3.0.9",
|
||||||
"expo-symbols": "~1.0.8",
|
"expo-symbols": "~1.0.8",
|
||||||
@@ -6554,9 +6554,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/expo-secure-store": {
|
"node_modules/expo-secure-store": {
|
||||||
"version": "55.0.13",
|
"version": "15.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/expo-secure-store/-/expo-secure-store-55.0.13.tgz",
|
"resolved": "https://registry.npmjs.org/expo-secure-store/-/expo-secure-store-15.0.8.tgz",
|
||||||
"integrity": "sha512-I6r0JNO1Fd4o0Gu7Ixiic7s89lqgdUHq17uBH9y1f/AntoyKn71TdtYJH82RgfsBbu5qNVzrwImmvlANyOlITQ==",
|
"integrity": "sha512-lHnzvRajBu4u+P99+0GEMijQMFCOYpWRO4dWsXSuMt77+THPIGjzNvVKrGSl6mMrLsfVaKL8BpwYZLGlgA+zAw==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"expo": "*"
|
"expo": "*"
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
"expo-image": "~3.0.11",
|
"expo-image": "~3.0.11",
|
||||||
"expo-linking": "~8.0.11",
|
"expo-linking": "~8.0.11",
|
||||||
"expo-router": "~6.0.23",
|
"expo-router": "~6.0.23",
|
||||||
"expo-secure-store": "^55.0.13",
|
"expo-secure-store": "~15.0.8",
|
||||||
"expo-splash-screen": "~31.0.13",
|
"expo-splash-screen": "~31.0.13",
|
||||||
"expo-status-bar": "~3.0.9",
|
"expo-status-bar": "~3.0.9",
|
||||||
"expo-symbols": "~1.0.8",
|
"expo-symbols": "~1.0.8",
|
||||||
|
|||||||
Reference in New Issue
Block a user