Added progress bar for assignments (UI fix needed)
This commit is contained in:
15
lib/progress.ts
Normal file
15
lib/progress.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { supabase } from '@/lib/supabase';
|
||||
|
||||
export async function CheckAssignmentCompletion(aId: string) {
|
||||
const { data, error } = await supabase.from("tasks").select("tId, isCompleted").eq("aId", aId);
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
const tasks = data ?? [];
|
||||
|
||||
const allCompleted = tasks.length > 0 && tasks.every((task) => task.isCompleted === true);
|
||||
|
||||
const { error: updateError } = await supabase.from("assignments").update({ isCompleted: allCompleted, lastChanged: new Date().toISOString()}).eq("aId", aId);
|
||||
|
||||
if (updateError) throw updateError;
|
||||
}
|
||||
29
lib/types.ts
Normal file
29
lib/types.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
export type Task = {
|
||||
tId: string;
|
||||
title: string;
|
||||
description: string;
|
||||
isCompleted: boolean;
|
||||
lastChanged: string;
|
||||
uId: string;
|
||||
aId: string;
|
||||
};
|
||||
|
||||
export type Assignment = {
|
||||
aId: string;
|
||||
title: string;
|
||||
description: string;
|
||||
deadline: string;
|
||||
isCompleted: boolean;
|
||||
lastChanged: string;
|
||||
uId: string;
|
||||
sId: string;
|
||||
};
|
||||
|
||||
export type Subject = {
|
||||
sId: string;
|
||||
title: string;
|
||||
description: string;
|
||||
isActive: boolean;
|
||||
lastChanged: string;
|
||||
uId: string;
|
||||
};
|
||||
Reference in New Issue
Block a user