CLASSROOMIO-T-168: Mark lesson as complete
This commit is contained in:
@@ -15,19 +15,20 @@
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
export let openModal = false;
|
||||
export let isStudent;
|
||||
let errors = {};
|
||||
export let isStudent = false;
|
||||
let errors = {
|
||||
title: ''
|
||||
};
|
||||
let lesson = {
|
||||
id: null,
|
||||
title: '',
|
||||
profile: undefined,
|
||||
call_url: undefined,
|
||||
lesson_at: new Date(),
|
||||
is_unlocked: false,
|
||||
is_complete: false
|
||||
is_unlocked: false
|
||||
};
|
||||
|
||||
function getLessonOrder(id) {
|
||||
function getLessonOrder(id = '') {
|
||||
const index = $lessons.findIndex((lesson) => lesson.id === id);
|
||||
if (index < 9) {
|
||||
return '0' + (index + 1);
|
||||
|
||||
+11
-2
@@ -1,4 +1,6 @@
|
||||
export function getUniqueValue(label) {
|
||||
import type { LessonCompletion } from '$lib/utils/types';
|
||||
|
||||
export function getUniqueValue(label: string) {
|
||||
return label.toLowerCase().replace(' ', '');
|
||||
}
|
||||
|
||||
@@ -15,9 +17,16 @@ export function generateQuestion(questions) {
|
||||
generatedQuestions.push({
|
||||
...question,
|
||||
name,
|
||||
options,
|
||||
options
|
||||
});
|
||||
}
|
||||
|
||||
return generatedQuestions;
|
||||
}
|
||||
|
||||
export function getIsLessonComplete(completions: LessonCompletion[], profileId: string | null) {
|
||||
if (!Array.isArray(completions)) return false;
|
||||
return completions.find((c) => {
|
||||
return c.is_complete && c.profile_id === profileId;
|
||||
});
|
||||
}
|
||||
@@ -12,15 +12,16 @@ export const lessons: Writable<Lesson[]> = writable([]);
|
||||
export const lesson = writable<LessonPage>({
|
||||
id: null,
|
||||
totalExercises: 0,
|
||||
is_complete: false,
|
||||
isSaving: false,
|
||||
materials: {
|
||||
note: '',
|
||||
slide_url: '',
|
||||
videos: []
|
||||
},
|
||||
exercises: []
|
||||
exercises: [],
|
||||
lesson_completion: []
|
||||
});
|
||||
|
||||
export const isLessonDirty = writable(false);
|
||||
|
||||
export function handleAddLesson() {
|
||||
@@ -33,8 +34,7 @@ export function handleAddLesson() {
|
||||
// profile: undefined,
|
||||
call_url: undefined,
|
||||
lesson_at: new Date(),
|
||||
is_unlocked: false,
|
||||
is_complete: false
|
||||
is_unlocked: false
|
||||
}
|
||||
];
|
||||
}) as Updater<any>);
|
||||
@@ -60,12 +60,11 @@ export async function handleSaveLesson(lesson: Lesson, course_id: Course['id'])
|
||||
console.log(`handleSaveLesson lesson`, lesson);
|
||||
const newLesson = {
|
||||
title: lesson.title,
|
||||
lesson_at: lesson.lesson_at,
|
||||
call_url: lesson.call_url,
|
||||
teacher_id: lesson.profile ? lesson.profile.id : undefined,
|
||||
lesson_at: lesson?.lesson_at,
|
||||
call_url: lesson?.call_url,
|
||||
teacher_id: lesson?.profile ? lesson?.profile.id : undefined,
|
||||
course_id,
|
||||
is_unlocked: lesson.is_unlocked,
|
||||
is_complete: lesson.is_complete
|
||||
is_unlocked: lesson.is_unlocked
|
||||
};
|
||||
|
||||
let newLessonData: any[] | null = null;
|
||||
@@ -85,7 +84,7 @@ export async function handleUpdateLessonMaterials(lesson: any, lessonId: Lesson[
|
||||
const materials = {
|
||||
...lesson.materials
|
||||
};
|
||||
|
||||
delete materials.lesson_completion;
|
||||
delete materials.profile;
|
||||
delete materials.totalExercises;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script>
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { page } from '$app/stores';
|
||||
@@ -11,40 +11,40 @@
|
||||
import TextChip from '$lib/components/Chip/Text.svelte';
|
||||
import { lessons } from '../Lesson/store/lessons';
|
||||
import { course } from '$lib/components/Course/store';
|
||||
import { updateCourse } from '$lib/utils/services/courses';
|
||||
import { NavClasses } from '$lib/utils/constants/reusableClass';
|
||||
import { isMobile } from '$lib/utils/store/useMobile';
|
||||
import { menu } from '$lib/components/Org/store';
|
||||
import { profile } from '$lib/utils/store/user';
|
||||
import { getIsLessonComplete } from '../Lesson/functions';
|
||||
|
||||
export let path;
|
||||
export let isStudent = null;
|
||||
export let path: string;
|
||||
export let isStudent: boolean = false;
|
||||
|
||||
let show = null;
|
||||
interface NavItem {
|
||||
label: string;
|
||||
to: string;
|
||||
hideSortIcon: boolean;
|
||||
isLecture?: boolean;
|
||||
show?: () => boolean;
|
||||
}
|
||||
|
||||
let show: boolean = false;
|
||||
let isLessonActive = false;
|
||||
|
||||
const toggleSidebar = () => {
|
||||
$menu.hidden = !$menu.hidden;
|
||||
};
|
||||
|
||||
function handleMainGroupClick(href) {
|
||||
function handleMainGroupClick(href: string) {
|
||||
return () => {
|
||||
goto(href);
|
||||
toggleSidebar();
|
||||
};
|
||||
}
|
||||
|
||||
let navItems = [];
|
||||
let navItems: NavItem[] = [];
|
||||
|
||||
function getHref(item) {
|
||||
return item.to;
|
||||
// return item.is_unlocked ? item.to : path || $page.url.pathname
|
||||
}
|
||||
|
||||
function handleSaveTitle() {
|
||||
updateCourse($course.id, { title: $course.title });
|
||||
}
|
||||
|
||||
function handleMobileChange(isMobile) {
|
||||
function handleMobileChange(isMobile: boolean) {
|
||||
if (isMobile) show = false;
|
||||
else show = true;
|
||||
}
|
||||
@@ -192,7 +192,7 @@
|
||||
<span class="text-md ml-2" title="This lesson is locked.">
|
||||
<LockedIcon class="carbon-icon dark:text-white" />
|
||||
</span>
|
||||
{:else if item.is_complete}
|
||||
{:else if getIsLessonComplete(item.lesson_completion, $profile.id)}
|
||||
<span class="ml-2" title="You have completed this lesson">
|
||||
<CheckmarkFilled class="carbon-icon dark:text-white" />
|
||||
</span>
|
||||
|
||||
Reference in New Issue
Block a user