diff --git a/src/lib/components/Course/components/Lesson/AddLessonModal.svelte b/src/lib/components/Course/components/Lesson/AddLessonModal.svelte new file mode 100644 index 00000000..8dd45939 --- /dev/null +++ b/src/lib/components/Course/components/Lesson/AddLessonModal.svelte @@ -0,0 +1,129 @@ + + + (openModal = false)} + bind:open={openModal} + width="w-[60%]" + containerClass="overflow-hidden" + modalHeading="Add New Lesson" +> + + + + + + + + + + { + lesson.is_unlocked = !lesson.is_unlocked; + handleSaveLesson(lesson, $course.id); + }} + class="p-1" + > + {#if lesson.is_unlocked} + + {:else} + + {/if} + + + + + + + + + + + + + + + + + + + + + diff --git a/src/lib/components/Course/components/Lesson/store/lessons.ts b/src/lib/components/Course/components/Lesson/store/lessons.ts index f93e20ae..3a70b23c 100644 --- a/src/lib/components/Course/components/Lesson/store/lessons.ts +++ b/src/lib/components/Course/components/Lesson/store/lessons.ts @@ -78,18 +78,7 @@ export async function handleSaveLesson(lesson: Lesson, course_id: Course['id']) newLessonData = data; } - - lessons.update((l) => - l.map((_lesson) => { - if (!_lesson.id && newLessonData) { - _lesson.id = newLessonData[0].id; - } else if (typeof lesson.id === 'string' && lesson.id === _lesson.id) { - return { ..._lesson, is_complete: lesson.is_complete }; - } - - return _lesson; - }) - ); + return newLessonData; } export async function handleUpdateLessonMaterials(lesson: any, lessonId: Lesson['id']) { diff --git a/src/routes/courses/[id]/lessons/+page.svelte b/src/routes/courses/[id]/lessons/+page.svelte index f4130525..f30b6954 100644 --- a/src/routes/courses/[id]/lessons/+page.svelte +++ b/src/routes/courses/[id]/lessons/+page.svelte @@ -22,7 +22,6 @@ import { profile } from '$lib/utils/store/user'; import { lessons, - handleAddLesson, handleSaveLesson, handleDelete } from '$lib/components/Course/components/Lesson/store/lessons'; @@ -30,13 +29,14 @@ import PageBody from '$lib/components/PageBody/index.svelte'; import TextChip from '$lib/components/Chip/Text.svelte'; import Avatar from '$lib/components/Apps/components/Poll/components/Avatar.svelte'; + import AddLessonModal from '$lib/components/Course/components/Lesson/AddLessonModal.svelte'; import { exerciseMode } from '$lib/components/Course/components/Lesson/Exercise/store'; export let data; const { courseId } = data; let lessonEditing; - let ref; let isStudent = true; + let openModal = false; const flipDurationMs = 300; @@ -52,17 +52,7 @@ // TODO: CRUD of lessons function addLesson() { - handleAddLesson(); - setTimeout(() => { - lessonEditing = $lessons.length - 1; - if (ref) { - ref.scrollIntoView({ - block: 'start', - behavior: 'smooth', - inline: 'nearest' - }); - } - }, 100); + openModal = true; } function handleDndConsider(e) { @@ -115,6 +105,8 @@ } + + @@ -141,7 +133,6 @@ > {#each $lessons as lesson (lesson.id)}