mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-18 20:09:25 +00:00
feat: dynamically get chapters
This commit is contained in:
parent
c2b3e51ad0
commit
ee69cb7e58
2 changed files with 23 additions and 21 deletions
|
|
@ -20,12 +20,12 @@ function CourseEdit() {
|
||||||
const courseChapters = await getCourseChaptersMetadata(courseid);
|
const courseChapters = await getCourseChaptersMetadata(courseid);
|
||||||
setData(courseChapters);
|
setData(courseChapters);
|
||||||
console.log(courseChapters);
|
console.log(courseChapters);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (router.isReady) {
|
||||||
|
getCourseChapters();
|
||||||
|
}
|
||||||
|
|
||||||
setwinReady(true);
|
setwinReady(true);
|
||||||
}, [router.isReady]);
|
}, [router.isReady]);
|
||||||
|
|
@ -34,7 +34,12 @@ function CourseEdit() {
|
||||||
const getChapters = () => {
|
const getChapters = () => {
|
||||||
return data.chapterOrder.map((chapterId: any) => {
|
return data.chapterOrder.map((chapterId: any) => {
|
||||||
const chapter = data.chapters[chapterId];
|
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 {
|
return {
|
||||||
list: {
|
list: {
|
||||||
chapter: chapter,
|
chapter: chapter,
|
||||||
|
|
@ -68,7 +73,7 @@ function CourseEdit() {
|
||||||
chapterOrder: newChapterOrder,
|
chapterOrder: newChapterOrder,
|
||||||
};
|
};
|
||||||
console.log(newState);
|
console.log(newState);
|
||||||
|
|
||||||
setData(newState);
|
setData(newState);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -82,7 +87,7 @@ function CourseEdit() {
|
||||||
if (start === finish) {
|
if (start === finish) {
|
||||||
// create new arrays for chapters and elements
|
// create new arrays for chapters and elements
|
||||||
const chapter = data.chapters[source.droppableId];
|
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
|
// remove the element from the old position
|
||||||
newElementIds.splice(source.index, 1);
|
newElementIds.splice(source.index, 1);
|
||||||
|
|
@ -150,18 +155,17 @@ function CourseEdit() {
|
||||||
{winReady && (
|
{winReady && (
|
||||||
<ChapterlistWrapper>
|
<ChapterlistWrapper>
|
||||||
<DragDropContext onDragEnd={onDragEnd}>
|
<DragDropContext onDragEnd={onDragEnd}>
|
||||||
<Droppable droppableId="chapters" type="chapter">
|
<Droppable droppableId="chapters" type="chapter">
|
||||||
{(provided) => (
|
{(provided) => (
|
||||||
<div key={"chapters"} {...provided.droppableProps} ref={provided.innerRef}>
|
<div key={"chapters"} {...provided.droppableProps} ref={provided.innerRef}>
|
||||||
{getChapters().map((info: any, index: any) => (
|
{getChapters().map((info: any, index: any) => (
|
||||||
<Chapter key={index} info={info} index={index}></Chapter>
|
<Chapter key={index} info={info} index={index}></Chapter>
|
||||||
|
))}
|
||||||
))}
|
{provided.placeholder}
|
||||||
{provided.placeholder}
|
</div>
|
||||||
</div>
|
)}
|
||||||
)}
|
</Droppable>
|
||||||
</Droppable>
|
</DragDropContext>
|
||||||
</DragDropContext>
|
|
||||||
</ChapterlistWrapper>
|
</ChapterlistWrapper>
|
||||||
)}
|
)}
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,6 @@ from fastapi import FastAPI, HTTPException, status, Request, Response, Backgroun
|
||||||
|
|
||||||
class CourseElement(BaseModel):
|
class CourseElement(BaseModel):
|
||||||
element_id: str
|
element_id: str
|
||||||
content: str
|
|
||||||
content_type: str
|
|
||||||
|
|
||||||
|
|
||||||
class CourseChapter(BaseModel):
|
class CourseChapter(BaseModel):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue