From 5a7cd8a34afc4430999a80085c361c6fe2bf6730 Mon Sep 17 00:00:00 2001 From: Rotimi Best Date: Tue, 16 Jul 2024 10:20:56 +0100 Subject: [PATCH] fix: completion state for student in lms --- .../src/lib/utils/services/courses/index.ts | 11 ++++++++++- .../src/routes/courses/[id]/lessons/+page.svelte | 12 ++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/apps/dashboard/src/lib/utils/services/courses/index.ts b/apps/dashboard/src/lib/utils/services/courses/index.ts index 023cd68a..62c2ae72 100644 --- a/apps/dashboard/src/lib/utils/services/courses/index.ts +++ b/apps/dashboard/src/lib/utils/services/courses/index.ts @@ -179,7 +179,16 @@ export function fetchLesson(lessonId: Lesson['id']) { return supabase .from('lesson') .select( - `id, note, videos, slide_url, call_url, totalExercises:exercise(count), totalComments:lesson_comment(count), lesson_completion(id, profile_id, is_complete), lesson_language(id, content, locale)` + `id, + note, + videos, + slide_url, + call_url, + totalExercises:exercise(count), + totalComments:lesson_comment(count), + lesson_completion(id, profile_id, is_complete), + lesson_language(id, content, locale) + ` ) .eq('id', lessonId) .single(); diff --git a/apps/dashboard/src/routes/courses/[id]/lessons/+page.svelte b/apps/dashboard/src/routes/courses/[id]/lessons/+page.svelte index aac86ab0..77e494fc 100644 --- a/apps/dashboard/src/routes/courses/[id]/lessons/+page.svelte +++ b/apps/dashboard/src/routes/courses/[id]/lessons/+page.svelte @@ -31,6 +31,7 @@ import { goto } from '$app/navigation'; import { COURSE_TYPE } from '$lib/utils/types'; import { VARIANTS } from '$lib/components/PrimaryButton/constants.js'; + import { profile } from '$lib/utils/store/user.js'; export let data; @@ -103,20 +104,19 @@ } } + function hasUserCompletedLesson(completion) { + return completion?.find((c) => c.profile_id === $profile.id); + } + function findFirstIncompleteLesson() { - console.log({ lessons: $lessons }); return $lessons.find( - (lesson) => - lesson.lesson_completion && - lesson.lesson_completion.length === 0 && - lesson.is_unlocked === true + (lesson) => !hasUserCompletedLesson(lesson.lesson_completion) && lesson.is_unlocked === true ); } function onNextQuery(lessons) { if (!isFetching && lessons.length > 0) { const incompleteLesson = findFirstIncompleteLesson(); - console.log({ incompleteLesson }); if (incompleteLesson) { goto(`/courses/${data.courseId}/lessons/${incompleteLesson.id}`);