diff --git a/front/pages/org/[orgslug]/course/[courseid]/edit/index.tsx b/front/pages/org/[orgslug]/course/[courseid]/edit/index.tsx index c705b041..a995575c 100644 --- a/front/pages/org/[orgslug]/course/[courseid]/edit/index.tsx +++ b/front/pages/org/[orgslug]/course/[courseid]/edit/index.tsx @@ -20,12 +20,12 @@ function CourseEdit() { const courseChapters = await getCourseChaptersMetadata(courseid); setData(courseChapters); console.log(courseChapters); - } - - useEffect(() => { - + useEffect(() => { + if (router.isReady) { + getCourseChapters(); + } setwinReady(true); }, [router.isReady]); @@ -34,7 +34,12 @@ function CourseEdit() { const getChapters = () => { return data.chapterOrder.map((chapterId: any) => { const chapter = data.chapters[chapterId]; - const elements = chapter.elementIds.map((elementId: any) => data.elements[elementId]); + let elements = []; + if (data.elements) { + elements = chapter.elementIds.map((elementId: any) => data.elements[elementId]) + ? chapter.elementIds.map((elementId: any) => data.elements[elementId]) + : null; + } return { list: { chapter: chapter, @@ -68,7 +73,7 @@ function CourseEdit() { chapterOrder: newChapterOrder, }; console.log(newState); - + setData(newState); return; } @@ -82,7 +87,7 @@ function CourseEdit() { if (start === finish) { // create new arrays for chapters and elements const chapter = data.chapters[source.droppableId]; - const newElementIds = Array.from(chapter.elements.element_id); + const newElementIds = Array.from(chapter.elementIds); // remove the element from the old position newElementIds.splice(source.index, 1); @@ -150,18 +155,17 @@ function CourseEdit() { {winReady && ( - - {(provided) => ( -
- {getChapters().map((info: any, index: any) => ( - - - ))} - {provided.placeholder} -
- )} -
-
+ + {(provided) => ( +
+ {getChapters().map((info: any, index: any) => ( + + ))} + {provided.placeholder} +
+ )} +
+
)} diff --git a/src/services/chapters.py b/src/services/chapters.py index f0006a44..93d68a94 100644 --- a/src/services/chapters.py +++ b/src/services/chapters.py @@ -13,8 +13,6 @@ from fastapi import FastAPI, HTTPException, status, Request, Response, Backgroun class CourseElement(BaseModel): element_id: str - content: str - content_type: str class CourseChapter(BaseModel):