diff --git a/src/app/admin/content/[courseId]/[...moduleId]/page.tsx b/src/app/admin/content/[courseId]/[...moduleId]/page.tsx index 4d30c6ea2..61a5e9c0d 100644 --- a/src/app/admin/content/[courseId]/[...moduleId]/page.tsx +++ b/src/app/admin/content/[courseId]/[...moduleId]/page.tsx @@ -13,18 +13,20 @@ export default async function UpdateCourseContent({ const rest = params.moduleId; const course = await getCourse(parseInt(courseId, 10)); const fullCourseContent = await getFullCourseContent(parseInt(courseId, 10)); + const courseContent = findContentById( fullCourseContent, rest.map((x) => parseInt(x, 10)), ); - const contentType = - courseContent?.length === 1 ? courseContent[0]?.type : 'folder'; + const contentType = courseContent?.folder + ? 'folder' + : courseContent?.value?.type; if (contentType === 'video') { return (
{/* @ts-ignore */} - +
); } @@ -49,7 +51,7 @@ export default async function UpdateCourseContent({ ({ + courseContent={courseContent?.value?.map((x: any) => ({ title: x?.title || '', image: x?.thumbnail || '', id: x?.id || 0, diff --git a/src/app/admin/content/[courseId]/page.tsx b/src/app/admin/content/[courseId]/page.tsx index b397c2e3b..b2ca186e9 100644 --- a/src/app/admin/content/[courseId]/page.tsx +++ b/src/app/admin/content/[courseId]/page.tsx @@ -16,8 +16,9 @@ export default async function UpdateCourseContent({ fullCourseContent, rest.map((x) => parseInt(x, 10)), ); - const contentType = - courseContent?.length === 1 ? courseContent[0]?.type : 'folder'; + const contentType = courseContent?.folder + ? 'folder' + : courseContent?.value.type; if (contentType === 'video') { return ( @@ -46,7 +47,7 @@ export default async function UpdateCourseContent({ ({ + courseContent={courseContent?.value.map((x: any) => ({ title: x?.title || '', image: x?.thumbnail || '', id: x?.id || 0, diff --git a/src/app/courses/[courseId]/[...moduleId]/page.tsx b/src/app/courses/[courseId]/[...moduleId]/page.tsx index d16571c23..4e057393d 100644 --- a/src/app/courses/[courseId]/[...moduleId]/page.tsx +++ b/src/app/courses/[courseId]/[...moduleId]/page.tsx @@ -20,15 +20,12 @@ export default async function Course({ fullCourseContent, rest.map((x) => parseInt(x, 10)), ); - const contentType = - courseContent?.length === 1 ? courseContent[0]?.type : 'folder'; const nextContent = null; //await getNextVideo(Number(rest[rest.length - 1])) return ( { + const contentType = courseContent?.folder + ? 'folder' + : courseContent?.value.type; return ( <>
@@ -37,40 +47,42 @@ export const CourseView = ({ rest={rest} />
- {contentType === 'notion' ? ( - + {!courseContent?.folder && courseContent?.value.type === 'notion' ? ( + ) : null} - {contentType === 'video' ? ( + {!courseContent?.folder && contentType === 'video' ? ( ) : null} - {(contentType === 'video' || contentType === 'notion') && ( - - )} - {contentType === 'folder' ? ( + {!courseContent?.folder && + (contentType === 'video' || contentType === 'notion') && ( + + )} + {courseContent?.folder ? ( ({ + courseContent={courseContent?.value.map((x: any) => ({ title: x?.title || '', image: x?.thumbnail || '', type: x?.type || 'folder', @@ -79,6 +91,7 @@ export const CourseView = ({ percentComplete: getFolderPercentCompleted(x?.children), videoFullDuration: x?.videoProgress?.videoFullDuration || 0, duration: x?.videoProgress?.duration || 0, + bookmark: null, }))} courseId={parseInt(course.id, 10)} /> diff --git a/src/db/course.ts b/src/db/course.ts index 1243a25d2..6183cf084 100644 --- a/src/db/course.ts +++ b/src/db/course.ts @@ -256,11 +256,13 @@ interface VideoProgress { videoFullDuration: number | null; } +export type ChildCourseContent = { + videoProgress: VideoProgress | null; + bookmark?: Bookmark; +} & ContentWithMetadata; + export type FullCourseContent = { - children?: ({ - videoProgress: VideoProgress | null; - bookmark?: Bookmark; - } & ContentWithMetadata)[]; + children?: ChildCourseContent[]; videoProgress: VideoProgress | null; bookmark?: Bookmark; } & ContentWithMetadata; diff --git a/src/lib/find-content-by-id.ts b/src/lib/find-content-by-id.ts index 6f929fa19..f5fc5b595 100644 --- a/src/lib/find-content-by-id.ts +++ b/src/lib/find-content-by-id.ts @@ -1,10 +1,25 @@ -import { FullCourseContent } from '@/db/course'; +import { ChildCourseContent, FullCourseContent } from '@/db/course'; +// findContentById +// This is incorrect. +// If the place you are in is a folder +// It returns all the children +// If the place you are in is a video +// It returns an array with that video as the first element. export default function findContentById( contents: FullCourseContent[], ids: number[], -) { - if (ids.length === 0) return contents; +): + | { + folder: true; + value: ChildCourseContent[]; + } + | { + folder: false; + value: ChildCourseContent; + } + | null { + if (ids.length === 0) return { folder: true, value: contents }; const currentId = ids[0]; const remainingIds = ids.slice(1); @@ -15,10 +30,10 @@ export default function findContentById( return null; } else if (remainingIds.length === 0) { if (foundContent.type === 'folder') { - return foundContent.children; + return { folder: true, value: foundContent.children ?? [] }; // [Object] } - return [foundContent]; + return { folder: false, value: foundContent }; } return findContentById(foundContent?.children || [], remainingIds);