fix: completion state for student in lms
This commit is contained in:
@@ -179,7 +179,16 @@ export function fetchLesson(lessonId: Lesson['id']) {
|
|||||||
return supabase
|
return supabase
|
||||||
.from('lesson')
|
.from('lesson')
|
||||||
.select(
|
.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)
|
.eq('id', lessonId)
|
||||||
.single();
|
.single();
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { COURSE_TYPE } from '$lib/utils/types';
|
import { COURSE_TYPE } from '$lib/utils/types';
|
||||||
import { VARIANTS } from '$lib/components/PrimaryButton/constants.js';
|
import { VARIANTS } from '$lib/components/PrimaryButton/constants.js';
|
||||||
|
import { profile } from '$lib/utils/store/user.js';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
|
||||||
@@ -103,20 +104,19 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasUserCompletedLesson(completion) {
|
||||||
|
return completion?.find((c) => c.profile_id === $profile.id);
|
||||||
|
}
|
||||||
|
|
||||||
function findFirstIncompleteLesson() {
|
function findFirstIncompleteLesson() {
|
||||||
console.log({ lessons: $lessons });
|
|
||||||
return $lessons.find(
|
return $lessons.find(
|
||||||
(lesson) =>
|
(lesson) => !hasUserCompletedLesson(lesson.lesson_completion) && lesson.is_unlocked === true
|
||||||
lesson.lesson_completion &&
|
|
||||||
lesson.lesson_completion.length === 0 &&
|
|
||||||
lesson.is_unlocked === true
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onNextQuery(lessons) {
|
function onNextQuery(lessons) {
|
||||||
if (!isFetching && lessons.length > 0) {
|
if (!isFetching && lessons.length > 0) {
|
||||||
const incompleteLesson = findFirstIncompleteLesson();
|
const incompleteLesson = findFirstIncompleteLesson();
|
||||||
console.log({ incompleteLesson });
|
|
||||||
|
|
||||||
if (incompleteLesson) {
|
if (incompleteLesson) {
|
||||||
goto(`/courses/${data.courseId}/lessons/${incompleteLesson.id}`);
|
goto(`/courses/${data.courseId}/lessons/${incompleteLesson.id}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user