fix: v1 lesson section creation

This commit is contained in:
Rotimi Best
2024-08-14 11:13:44 +01:00
parent ad421acf8d
commit e18b4ca1b1
4 changed files with 14 additions and 8 deletions
@@ -108,7 +108,7 @@
{#each $lessonSections as section (section.id)} {#each $lessonSections as section (section.id)}
<div class="mb-3 border border-gray-200 rounded-md"> <div class="mb-3 border border-gray-200 rounded-md">
<div <div
class="mb-2 px-3 py-1 border-b bg-gray-50 rounded-tl-md rounded-tr-md flex justify-between items-center" class="mb-2 px-3 py-1 min-h-[50px] border-b bg-gray-50 rounded-tl-md rounded-tr-md flex justify-between items-center"
> >
{#if lessonEditing === section.id} {#if lessonEditing === section.id}
<TextField className="w-4/6" bind:value={section.title} errorMessage={errors?.title} /> <TextField className="w-4/6" bind:value={section.title} errorMessage={errors?.title} />
@@ -57,13 +57,14 @@
title: lesson.title, title: lesson.title,
order: newLessonSection.order, order: newLessonSection.order,
course_id: newLessonSection.course_id, course_id: newLessonSection.course_id,
lessons: [] lessons: [],
created_at: ''
} }
]; ];
}); });
} }
} else { } else {
lesson.section_id = $handleAddLessonWidget.id; lesson.section_id = $handleAddLessonWidget.id || undefined;
const savedLesson = await handleSaveLesson(lesson, $course.id); const savedLesson = await handleSaveLesson(lesson, $course.id);
if (Array.isArray(savedLesson) && savedLesson[0]) { if (Array.isArray(savedLesson) && savedLesson[0]) {
@@ -9,6 +9,7 @@
import { isFreePlan } from '$lib/utils/store/org'; import { isFreePlan } from '$lib/utils/store/org';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { course } from '$lib/components/Course/store'; import { course } from '$lib/components/Course/store';
import { COURSE_VERSION } from '$lib/utils/types';
export let handleClick = () => {}; export let handleClick = () => {};
export let id = ''; export let id = '';
@@ -28,11 +29,14 @@
function addLesson() { function addLesson() {
goto('/courses/' + $course.id + '/lessons'); goto('/courses/' + $course.id + '/lessons');
$handleAddLessonWidget.open = true; $handleAddLessonWidget.open = true;
// If it is section, then add lesson to section
$handleAddLessonWidget.isSection = isSection ? false : true;
if (isSection) { if ($course.version === COURSE_VERSION.V2) {
$handleAddLessonWidget.id = id; // If it is section, then add lesson to section
$handleAddLessonWidget.isSection = isSection ? false : true;
if (isSection) {
$handleAddLessonWidget.id = id;
}
} }
} }
@@ -36,7 +36,8 @@
function addLesson() { function addLesson() {
$handleAddLessonWidget.open = true; $handleAddLessonWidget.open = true;
$handleAddLessonWidget.isSection = true;
$handleAddLessonWidget.isSection = $course.version === COURSE_VERSION.V2;
} }
function hasUserCompletedLesson(completion) { function hasUserCompletedLesson(completion) {