Fixed issues with assignment progress tracking + added subject progress tracking

This commit is contained in:
Teodor
2026-04-23 04:37:34 +02:00
parent a35353f45b
commit 9f214a9451
9 changed files with 205 additions and 14 deletions

View File

@@ -1,4 +1,5 @@
import { defaultStyles } from '@/constants/defaultStyles';
import { CheckSubjectCompletion } from '@/lib/progress';
import { supabase } from '@/lib/supabase';
import type { Assignment, Subject } from '@/lib/types';
import { Session } from '@supabase/supabase-js';
@@ -106,6 +107,15 @@ export default function ViewDetailsSubject() {
}
Alert.alert("Assignment deleted successfully!");
if (sId) {
try {
await CheckSubjectCompletion(sId);
} catch {
Alert.alert("Failed to update subject status");
}
}
GetAssignments(sId);
}
}
@@ -113,9 +123,7 @@ export default function ViewDetailsSubject() {
)
}
const CalculateSubjectCompletion = async () => {
}
const progress = assignments.length === 0 ? 0 : Math.round((assignments.filter(assignment => assignment.isCompleted).length / assignments.length) * 100);
return (
<View style={defaultStyles.container}>
@@ -155,6 +163,27 @@ export default function ViewDetailsSubject() {
{subject.isActive && <Text style={defaultStyles.checkboxMark}></Text>}
</View>
<Text style={defaultStyles.body}>{subject.lastChanged}</Text>
<View style={{ marginTop: 10 }}>
<Text style={{ marginBottom: 4 }}>{progress}%</Text>
<View
style={{
width: "100%",
height: 12,
backgroundColor: "#D9D9D9",
borderRadius: 999,
overflow: "hidden",
}}
>
<View
style={{
width: `${progress}%`,
height: "100%",
backgroundColor: "#4CAF50",
}}
/>
</View>
</View>
<Button title="Edit" onPress={() => router.push({pathname: "/subject/editSubject", params: { sId: subject.sId }})} />
<Button title="Delete" onPress={() => DeleteSubject(subject.sId)} />