Skip to content

Commit

Permalink
finished the unlocking of pathway
Browse files Browse the repository at this point in the history
  • Loading branch information
Chifez committed Aug 28, 2024
1 parent 39bfe64 commit 959a4c3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
import { pathway } from '$lib/components/Pathways/store';
import UnlockedCertificate from './UnlockedCertificate.svelte';
import LockedCertificate from './LockedCertificate.svelte';
import { getPathwayCompletedCoursesLength } from '$lib/utils/functions/pathway';
const getIsPathwayComplete = () => {
const completedCourses = getPathwayCompletedCoursesLength($pathway);
return completedCourses === $pathway.pathway_course.length;
};
$: isPathwayComplete = getIsPathwayComplete();
</script>

<div>
{#if $pathway.is_certificate_downloadable}
<UnlockedCertificate />
<UnlockedCertificate bind:isPathwayComplete />
{:else}
<LockedCertificate />
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
import type { ProfilePathwayProgress } from '$lib/utils/types';
import { fetchProfilePathwayProgress } from '$lib/utils/services/pathways';
export let isPathwayComplete = false;
let isLoading = false;
let showCourses = true;
let isPathwayComplete = true;
let progress: ProfilePathwayProgress | undefined;
function toggleCourse() {
Expand Down
5 changes: 5 additions & 0 deletions apps/dashboard/src/lib/utils/functions/pathway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export const getPathwayCompletedCoursesLength = (pathway: Pathway) => {
return completedCourses;
};

export const getIsPathwayComplete = (pathway: Pathway) => {
const completedCourses = getPathwayCompletedCoursesLength(pathway);
return completedCourses === pathway.pathway_course.length;
};

export const courseProgress = (lessons) => {
const totalLesson = lessons.length;
const completedLesson = lessons.filter((lesson) => lesson.is_complete).length;
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/routes/lms/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
const allResults = [...pathwaysWithFlag, ...coursesWithFlag];
console.log('all result', allResults);
lmsCourses.set(allResults);
hasFetched = true;
} catch (error) {
Expand All @@ -56,6 +55,7 @@
}
}
//TODO: we should consider pathway courses too
function calcTotalProgress(courses: LMSCourse[] | any) {
totalCompleted = courses.reduce((acc, cur) => acc + (cur.progress_rate || 0), 0);
totalLessons = courses.reduce((acc, cur) => acc + (cur.total_lessons || 0), 0);
Expand Down
12 changes: 3 additions & 9 deletions apps/dashboard/src/routes/lms/mylearning/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import type { LMSCourse } from '$lib/components/LMS/store';
import { fetchPathways } from '$lib/components/Org/Pathway/api';
import { courseMetaDeta } from '$lib/components/Courses/store';
import { getPathwayCompletedCoursesLength } from '$lib/utils/functions/pathway';
import { getIsPathwayComplete } from '$lib/utils/functions/pathway';
let hasFetched = false;
let selectedId = '0';
Expand Down Expand Up @@ -90,19 +90,14 @@
if (currentTab === '1') {
filteredCoursesInProgress = filteredCourses.filter((course) => {
if (course.isPathway) {
const incompleteCourses = course.pathway_course.filter((pathwayCourse) => {
const lessons = pathwayCourse.course.lesson;
return lessons.length > 0 && !lessons.every((lesson) => lesson.is_complete);
});
return incompleteCourses.length > 0;
return getIsPathwayComplete(course) == false;
}
return course.total_lessons !== course.progress_rate;
});
} else if (currentTab === '2') {
filteredCoursesCompleted = filteredCourses.filter((course) => {
if (course.isPathway) {
const completedCourses = getPathwayCompletedCoursesLength(course);
return completedCourses === course.pathway_course.length;
return getIsPathwayComplete(course);
}
return course.total_lessons === course.progress_rate;
});
Expand All @@ -124,7 +119,6 @@
value: '2'
}
];
// $: currentTab = tabs[0].value;
</script>

<section class="max-w-6xl mx-auto">
Expand Down

0 comments on commit 959a4c3

Please sign in to comment.