Skip to content

Commit

Permalink
Merge pull request #451 from rotimi-best/pathway/pathway_progress
Browse files Browse the repository at this point in the history
fix: worked on the settings
  • Loading branch information
tunny17 committed Aug 28, 2024
2 parents ab87a0a + 959a4c3 commit 2d78d62
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 54 deletions.
2 changes: 2 additions & 0 deletions apps/dashboard/src/lib/components/Org/Pathway/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export async function fetchPathways(profileId: string | undefined, orgId: string
}

// Step 2: Fetch courses for each pathway
console.log();
const pathwayIds = allPathways.map((pathway: any) => pathway.id);

const { data: allCourses, error: courseError } = await supabase
Expand Down Expand Up @@ -103,6 +104,7 @@ export async function fetchPathways(profileId: string | undefined, orgId: string
// Step 3: Attach courses to their respective pathways and rename pathway_course to courses
const pathwaysWithCourses = allPathways.map((pathway: any) => {
const courses = allCourses.filter((course: any) => course.pathway_id === pathway.id);
console.log('pathwaywthcourse', courses);
return {
...pathway,
pathway_course: courses // Rename pathway_course to courses
Expand Down
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
29 changes: 1 addition & 28 deletions apps/dashboard/src/lib/utils/services/pathways/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export async function fetchPathway(pathwayId?: Pathway['id'], slug?: Pathway['sl
};
}

export async function updatePathway (
export async function updatePathway(
pathwayId: Pathway['id'],
avatar: string | undefined,
pathway: Partial<Pathway>
Expand Down Expand Up @@ -194,30 +194,3 @@ export async function uploadAvatar(pathwayId: string, avatar: string) {

return logo;
}

export async function updatePathways(
pathwayId: Pathway['id'],
avatar: string | undefined,
pathway: Partial<Pathway>
) {
if (avatar && pathwayId) {
const filename = `course/${pathwayId + Date.now()}.webp`;

const { data } = await supabase.storage.from('avatars').upload(filename, avatar, {
cacheControl: '3600',
upsert: false
});

if (data) {
const { data: response } = supabase.storage.from('avatars').getPublicUrl(filename);

if (!response.publicUrl) return;

pathway.logo = response.publicUrl;
}
}

await supabase.from('pathway').update(pathway).match({ id: pathwayId });

return pathway.logo;
}
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
20 changes: 6 additions & 14 deletions apps/dashboard/src/routes/pathways/[id]/settings/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,24 @@
isSaving = true;
// try catch block to save to supabase
try {
const {
title,
logo,
description,
prerequisite,
is_published,
lms_certificate,
courses_certificate
} = $pathwaySettings;
const { title, logo, description, prerequisite, is_published, lms_certificate } =
$pathwaySettings;
await updatePathways($pathway.id, avatar, {
await updatePathway($pathway.id, avatar, {
title: title,
logo: logo,
description: description,
prerequisite: prerequisite,
is_published: is_published,
lms_certificate: lms_certificate,
courses_certificate: courses_certificate,
slug: $pathway.slug
});
$pathway.title = title;
$pathway.description = description;
$pathway.logo = logo;
$pathway.is_published = is_published;
$pathway.courses_certificate = courses_certificate;
$pathway.prerequisite = prerequisite;
$pathway.lms_certificate = lms_certificate;
Expand Down Expand Up @@ -273,7 +265,7 @@
<span slot="labelB" style="color: gray">{$t('pathway.pages.settings.disabled')}</span>
</Toggle>
</Column>
<Column class="flex w-full flex-col md:flex-row items-start md:items-center gap-5">
<!-- <Column class="flex w-full flex-col md:flex-row items-start md:items-center gap-5">
<p>{$t('pathway.pages.settings.issue_two')}</p>
<div>
<RadioButtonGroup hideLegend bind:selected={$pathwaySettings.courses_certificate}>
Expand All @@ -287,7 +279,7 @@
/>
</RadioButtonGroup>
</div>
</Column>
</Column> -->
</Row>
</Row>

Expand Down

0 comments on commit 2d78d62

Please sign in to comment.