fix: empty lesson title bug (#314)
* finished the lesson title bug * made chnages based on review * Update +page.svelte --------- Co-authored-by: Rotimi Best <[email protected]>
This commit is contained in:
@@ -4,6 +4,7 @@ import { createLesson, updateLesson, deleteLesson } from '$lib/utils/services/co
|
|||||||
import type { Lesson, Course, LessonPage, LessonComment } from '$lib/utils/types';
|
import type { Lesson, Course, LessonPage, LessonComment } from '$lib/utils/types';
|
||||||
import { LOCALE } from '$lib/utils/types';
|
import { LOCALE } from '$lib/utils/types';
|
||||||
import { snackbar } from '$lib/components/Snackbar/store';
|
import { snackbar } from '$lib/components/Snackbar/store';
|
||||||
|
import { lessonValidation } from '$lib/utils/functions/validator';
|
||||||
|
|
||||||
export const uploadCourseVideoStore = writable({
|
export const uploadCourseVideoStore = writable({
|
||||||
isModalOpen: false
|
isModalOpen: false
|
||||||
@@ -68,6 +69,12 @@ export async function handleDelete(lessonId: Lesson['id'] | undefined) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function handleSaveLesson(lesson: Lesson, course_id: Course['id']) {
|
export async function handleSaveLesson(lesson: Lesson, course_id: Course['id']) {
|
||||||
|
const result = lessonValidation(lesson);
|
||||||
|
|
||||||
|
if (Object.keys(result).length) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`handleSaveLesson lesson`, lesson);
|
console.log(`handleSaveLesson lesson`, lesson);
|
||||||
const newLesson = {
|
const newLesson = {
|
||||||
title: lesson.title,
|
title: lesson.title,
|
||||||
|
|||||||
@@ -280,7 +280,7 @@
|
|||||||
size="sm"
|
size="sm"
|
||||||
shape="rounded-full"
|
shape="rounded-full"
|
||||||
/>
|
/>
|
||||||
<span>{item.title}</span>
|
<span class="w-[70%] text-ellipsis line-clamp-2">{item.title}</span>
|
||||||
<span class="grow" />
|
<span class="grow" />
|
||||||
{#if !item.is_unlocked}
|
{#if !item.is_unlocked}
|
||||||
<span class="text-md ml-2" title="This lesson is locked.">
|
<span class="text-md ml-2" title="This lesson is locked.">
|
||||||
|
|||||||
@@ -11,6 +11,18 @@ const getSiteNameValidation = () =>
|
|||||||
const getNewsfeedValidation = () =>
|
const getNewsfeedValidation = () =>
|
||||||
z.string().min(5, { message: 'Field must contain 5 or more characters' });
|
z.string().min(5, { message: 'Field must contain 5 or more characters' });
|
||||||
|
|
||||||
|
const lessonSchema = z.object({
|
||||||
|
title: z.string().nonempty({ message: 'Title cannot be empty' }),
|
||||||
|
lesson_at: z.string().optional(),
|
||||||
|
call_url: z.string().nullable().optional(),
|
||||||
|
profile: z
|
||||||
|
.object({
|
||||||
|
id: z.string().optional()
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
|
is_unlocked: z.boolean()
|
||||||
|
});
|
||||||
|
|
||||||
const createQuizValidationSchema = z.object({
|
const createQuizValidationSchema = z.object({
|
||||||
title: z.string().min(6, {
|
title: z.string().min(6, {
|
||||||
message: 'Must be 6 or more characters long',
|
message: 'Must be 6 or more characters long',
|
||||||
@@ -143,7 +155,11 @@ export const processErrors = (error, mapToId) => {
|
|||||||
|
|
||||||
export const authValidation = (fields = {}) => {
|
export const authValidation = (fields = {}) => {
|
||||||
const { error } = authValidationSchema.safeParse(fields);
|
const { error } = authValidationSchema.safeParse(fields);
|
||||||
|
return processErrors(error);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const lessonValidation = (lesson = {}) => {
|
||||||
|
const { error } = lessonSchema.safeParse(lesson);
|
||||||
return processErrors(error);
|
return processErrors(error);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -237,7 +237,6 @@
|
|||||||
$: initNewsFeed(data.courseId);
|
$: initNewsFeed(data.courseId);
|
||||||
|
|
||||||
$: setAuthor($group, $profile.id);
|
$: setAuthor($group, $profile.id);
|
||||||
|
|
||||||
$: $newsFeed = $newsFeed.sort((a, b) => Number(b.isPinned) - Number(a.isPinned));
|
$: $newsFeed = $newsFeed.sort((a, b) => Number(b.isPinned) - Number(a.isPinned));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
import Avatar from '$lib/components/Apps/components/Poll/components/Avatar.svelte';
|
import Avatar from '$lib/components/Apps/components/Poll/components/Avatar.svelte';
|
||||||
import { course, group } from '$lib/components/Course/store';
|
import { course, group } from '$lib/components/Course/store';
|
||||||
import DateField from '$lib/components/Form/Date.svelte';
|
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 { t } from '$lib/utils/functions/translations.js';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
|
|
||||||
@@ -41,6 +41,19 @@
|
|||||||
|
|
||||||
const flipDurationMs = 300;
|
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() {
|
function addLesson() {
|
||||||
$handleAddLessonWidget.open = true;
|
$handleAddLessonWidget.open = true;
|
||||||
}
|
}
|
||||||
@@ -181,7 +194,12 @@
|
|||||||
<div class="w-4/5">
|
<div class="w-4/5">
|
||||||
<!-- Lesson Title -->
|
<!-- Lesson Title -->
|
||||||
{#if lessonEditing === lesson.id}
|
{#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}
|
{:else}
|
||||||
<h3 class="m-0 flex items-center text-lg dark:text-white">
|
<h3 class="m-0 flex items-center text-lg dark:text-white">
|
||||||
<a
|
<a
|
||||||
@@ -293,8 +311,7 @@
|
|||||||
: $t('course.navItem.lessons.add_lesson.edit')}
|
: $t('course.navItem.lessons.add_lesson.edit')}
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
if (lessonEditing === lesson.id) {
|
if (lessonEditing === lesson.id) {
|
||||||
lessonEditing = undefined;
|
saveLesson(lesson, $course.id);
|
||||||
handleSaveLesson(lesson, $course.id);
|
|
||||||
} else {
|
} else {
|
||||||
lessonEditing = lesson.id;
|
lessonEditing = lesson.id;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user