diff --git a/app/assignment/upsertAssignment.tsx b/app/assignment/upsertAssignment.tsx index f022ae4..284b6f7 100644 --- a/app/assignment/upsertAssignment.tsx +++ b/app/assignment/upsertAssignment.tsx @@ -1,6 +1,5 @@ import { defaultStyles } from '@/constants/defaultStyles'; import * as AsyncStorage from '@/lib/asyncStorage'; -import { CheckSubjectCompletion } from '@/lib/progress'; import { supabase } from '@/lib/supabase'; import * as Notifications from 'expo-notifications'; import { router, Stack, useLocalSearchParams } from 'expo-router'; @@ -189,12 +188,6 @@ export default function UpsertAssignment() { savedAssignment.isCompleted ); - try { - await CheckSubjectCompletion(subjectId); - } catch { - Alert.alert('Failed to update subject status'); - } - SetIsSaving(false); if (!isEditMode && isSetupFlow) { diff --git a/app/assignment/viewDetailsAssignment.tsx b/app/assignment/viewDetailsAssignment.tsx index 554b09a..56bab5c 100644 --- a/app/assignment/viewDetailsAssignment.tsx +++ b/app/assignment/viewDetailsAssignment.tsx @@ -1,5 +1,5 @@ import { formatDate, formatDateTime } from '@/lib/date'; -import { CheckAssignmentCompletion, CheckSubjectCompletion } from '@/lib/progress'; +import { CheckAssignmentCompletion } from '@/lib/progress'; import { getSubjectColorSet, type SubjectColor } from '@/lib/subjectColors'; import { supabase } from '@/lib/supabase'; import type { Assignment, Task } from '@/lib/types'; @@ -124,16 +124,6 @@ export default function ViewDetailsAssignment() { Alert.alert("Assignment deleted successfully!"); - const sId = assignment?.sId; - - if (sId) { - try { - await CheckSubjectCompletion(sId); - } catch { - Alert.alert("Failed to update subject status"); - } - } - router.back(); } } diff --git a/app/subject/viewDetailsSubject.tsx b/app/subject/viewDetailsSubject.tsx index cf27a22..c399c1f 100644 --- a/app/subject/viewDetailsSubject.tsx +++ b/app/subject/viewDetailsSubject.tsx @@ -1,5 +1,4 @@ import { formatDate, formatDateTime } from '@/lib/date'; -import { CheckSubjectCompletion } from '@/lib/progress'; import { SUBJECT_COLORS, type SubjectColor } from '@/lib/subjectColors'; import { supabase } from '@/lib/supabase'; import type { Assignment } from '@/lib/types'; @@ -102,12 +101,6 @@ export default function ViewDetailsSubject() { return; } - try { - await CheckSubjectCompletion(assignment.sId); - } catch { - Alert.alert('Failed to update subject status'); - } - await GetAssignments(assignment.sId); await GetSubject(assignment.sId); }; @@ -181,14 +174,6 @@ export default function ViewDetailsSubject() { return; } - if (subjectId) { - try { - await CheckSubjectCompletion(subjectId); - } catch { - Alert.alert('Failed to update subject status'); - } - } - await GetAssignments(subjectId); await GetSubject(subjectId); diff --git a/lib/progress.ts b/lib/progress.ts index 7ab2507..0198d36 100644 --- a/lib/progress.ts +++ b/lib/progress.ts @@ -13,17 +13,3 @@ export async function CheckAssignmentCompletion(aId: string) { if (updateError) throw updateError; } - -export async function CheckSubjectCompletion(sId: string) { - const { data, error } = await supabase.from("assignments").select("aId, isCompleted").eq("sId", sId); - - if (error) throw error; - - const assignments = data ?? []; - - const allCompleted = assignments.length > 0 && assignments.every((assignment) => assignment.isCompleted === true); - - const { error: updateError } = await supabase.from("subjects").update({ isActive: allCompleted, lastChanged: new Date().toISOString()}).eq("sId", sId); - - if (updateError) throw updateError; -} \ No newline at end of file