fix: empty lesson title bug (#314)

* finished the lesson title bug

* made chnages based on review

* Update +page.svelte

---------

Co-authored-by: Rotimi Best <best@classroomio.com>
This commit is contained in:
Em_Dev
2024-05-20 17:26:43 +01:00
committed by GitHub
co-authored by Rotimi Best
parent 018602f7b7
commit b9bb568f98
5 changed files with 45 additions and 6 deletions
@@ -237,7 +237,6 @@
$: initNewsFeed(data.courseId);
$: setAuthor($group, $profile.id);
$: $newsFeed = $newsFeed.sort((a, b) => Number(b.isPinned) - Number(a.isPinned));
</script>
@@ -25,7 +25,7 @@
import Avatar from '$lib/components/Apps/components/Poll/components/Avatar.svelte';
import { course, group } from '$lib/components/Course/store';
import DateField from '$lib/components/Form/Date.svelte';
import type { Lesson } from '$lib/utils/types';
import type { Course, Lesson } from '$lib/utils/types';
import { t } from '$lib/utils/functions/translations.js';
import { goto } from '$app/navigation';
@@ -41,6 +41,19 @@
const flipDurationMs = 300;
let errors: Record<string, string> = {};
async function saveLesson(lesson: Lesson, courseId: Course['id']) {
const validationRes = await handleSaveLesson(lesson, courseId);
if (validationRes && Object.keys(validationRes).length) {
errors = validationRes;
} else {
errors = {};
lessonEditing = undefined;
}
}
function addLesson() {
$handleAddLessonWidget.open = true;
}
@@ -181,7 +194,12 @@
<div class="w-4/5">
<!-- Lesson Title -->
{#if lessonEditing === lesson.id}
<TextField bind:value={lesson.title} autoFocus={true} className="max-w-lg" />
<TextField
bind:value={lesson.title}
autoFocus={true}
className="max-w-lg"
errorMessage={errors?.title}
/>
{:else}
<h3 class="m-0 flex items-center text-lg dark:text-white">
<a
@@ -293,8 +311,7 @@
: $t('course.navItem.lessons.add_lesson.edit')}
on:click={() => {
if (lessonEditing === lesson.id) {
lessonEditing = undefined;
handleSaveLesson(lesson, $course.id);
saveLesson(lesson, $course.id);
} else {
lessonEditing = lesson.id;
}