Skip to content

Commit

Permalink
Add work in progress commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mslwang committed Aug 1, 2022
1 parent 7f5595f commit 1adb732
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
26 changes: 15 additions & 11 deletions frontend/src/components/module-editor/SideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const Sidebar = (): React.ReactElement => {
refetchQueries: [
{
query: GET_COURSE,
variables: { id: courseID }
},
],
},
Expand Down Expand Up @@ -124,42 +125,45 @@ const Sidebar = (): React.ReactElement => {
oldID: string,
changedLesson: LessonRequest,
) => {
console.log(oldID);
const { data } = await createLesson({
variables: { lesson: changedLesson },
});
if (!data) throw Error("Failed to create new lesson");
const lesson = data.createLesson;
const { id: newID } = lesson;
// const lesson = data.createLesson;
// const { id: newID } = lesson;
// Update lesson ID in state with response
dispatch({ type: "update-lesson-id", value: { oldID, newID } });
dispatch({ type: "update-lesson-id", value: { oldID, newID: 'test' } });
};

const saveChanges = async (changeObj: EditorChangeStatuses) => {
console.log(changeObj);
Object.entries(changeObj).forEach(async ([doc_id, action]) => {
if (action === "COURSE-UPDATE") {
// Nothing happens because the updateCourse mutation is already called at the end anyway
return;
}
const changedLesson = formatLessonRequest(state.lessons[doc_id]);

switch (action) {
case "CREATE":
// Await required so we can get a new ID
await createNewLesson(doc_id, changedLesson);
await createNewLesson(doc_id, formatLessonRequest(state.lessons[doc_id]));
break;
case "UPDATE":
updateLesson({ variables: { id: doc_id, lesson: changedLesson } });
updateLesson({ variables: { id: doc_id, lesson: formatLessonRequest(state.lessons[doc_id]) } });
break;
case "DELETE":
deleteLesson({ variables: { id: doc_id } });
break;
case "COURSE-UPDATE":
// Nothing happens because the updateCourse mutation is already called at the end anyway
break;
// Make compiler happy
default:
break;
}
}
});
return;
updateCourse({
variables: { id: courseID, course: state.course },
});

state.hasChanged = {};
};

Expand Down
4 changes: 1 addition & 3 deletions frontend/src/reducers/ModuleEditorContextReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ const reorderLessons = (
return state;
}

const { id: courseID } = state.course; // id refers to the course document id

const oldModule = state.course.modules[moduleID];

console.assert(oldIndex >= 0, "Old lesson index must be positive");
Expand Down Expand Up @@ -137,7 +135,7 @@ const reorderLessons = (
};
newState.hasChanged = updateChangeStatus(
state.hasChanged,
courseID,
"<REORDER-LESSONS>",
"COURSE-UPDATE",
);
return newState;
Expand Down

0 comments on commit 1adb732

Please sign in to comment.