Skip to content

Commit

Permalink
Merge pull request #283 from Aar-if/status
Browse files Browse the repository at this point in the history
Issue #PS-1623: Status update for topic-subtopic and progress update for subject API integration
  • Loading branch information
itsvick authored Sep 23, 2024
2 parents f8ec55a + 62b5955 commit 7254ee5
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/pages/course-planner-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,25 @@ const CoursePlannerDetail = () => {
const calculateProgress = (tasks: any[]) => {
let totalSubtasks = 0;
let completedSubtasks = 0;

tasks.forEach((task: any) => {
totalSubtasks += task.children.length ?? 0;
completedSubtasks += task?.children?.filter(
(subtask: any) => subtask.status === 'completed'
).length;
if (task.status === AssessmentStatus.COMPLETED) {
completedSubtasks += 1;
}

const subtasks = task.children || [];
totalSubtasks += subtasks.length;
completedSubtasks += subtasks.filter((subtask: any) => subtask.status === AssessmentStatus.COMPLETED).length;
});
setCompletionPercentage(totalSubtasks ? Number(((completedSubtasks / totalSubtasks) * 100).toFixed()) : 0);

const totalTasks = tasks.length;
const totalItems = totalTasks + totalSubtasks;
const completedItems = completedSubtasks;

const completionPercentage = totalItems ? Number(((completedItems / totalItems) * 100).toFixed()) : 0;
setCompletionPercentage(completionPercentage);
};

if (userProjectDetails?.tasks?.length) {
calculateProgress(userProjectDetails.tasks);
}
Expand Down

0 comments on commit 7254ee5

Please sign in to comment.