Skip to content

Commit 1adb732

Browse files
committed
Add work in progress commit
1 parent 7f5595f commit 1adb732

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

frontend/src/components/module-editor/SideBar.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const Sidebar = (): React.ReactElement => {
6969
refetchQueries: [
7070
{
7171
query: GET_COURSE,
72+
variables: { id: courseID }
7273
},
7374
],
7475
},
@@ -124,42 +125,45 @@ const Sidebar = (): React.ReactElement => {
124125
oldID: string,
125126
changedLesson: LessonRequest,
126127
) => {
128+
console.log(oldID);
127129
const { data } = await createLesson({
128130
variables: { lesson: changedLesson },
129131
});
130132
if (!data) throw Error("Failed to create new lesson");
131-
const lesson = data.createLesson;
132-
const { id: newID } = lesson;
133+
// const lesson = data.createLesson;
134+
// const { id: newID } = lesson;
133135
// Update lesson ID in state with response
134-
dispatch({ type: "update-lesson-id", value: { oldID, newID } });
136+
dispatch({ type: "update-lesson-id", value: { oldID, newID: 'test' } });
135137
};
136138

137139
const saveChanges = async (changeObj: EditorChangeStatuses) => {
140+
console.log(changeObj);
138141
Object.entries(changeObj).forEach(async ([doc_id, action]) => {
139-
if (action === "COURSE-UPDATE") {
140-
// Nothing happens because the updateCourse mutation is already called at the end anyway
141-
return;
142-
}
143-
const changedLesson = formatLessonRequest(state.lessons[doc_id]);
142+
144143
switch (action) {
145144
case "CREATE":
146145
// Await required so we can get a new ID
147-
await createNewLesson(doc_id, changedLesson);
146+
await createNewLesson(doc_id, formatLessonRequest(state.lessons[doc_id]));
148147
break;
149148
case "UPDATE":
150-
updateLesson({ variables: { id: doc_id, lesson: changedLesson } });
149+
updateLesson({ variables: { id: doc_id, lesson: formatLessonRequest(state.lessons[doc_id]) } });
151150
break;
152151
case "DELETE":
153152
deleteLesson({ variables: { id: doc_id } });
154153
break;
154+
case "COURSE-UPDATE":
155+
// Nothing happens because the updateCourse mutation is already called at the end anyway
156+
break;
155157
// Make compiler happy
156158
default:
157159
break;
158-
}
160+
}
159161
});
162+
return;
160163
updateCourse({
161164
variables: { id: courseID, course: state.course },
162165
});
166+
163167
state.hasChanged = {};
164168
};
165169

frontend/src/reducers/ModuleEditorContextReducer.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ const reorderLessons = (
108108
return state;
109109
}
110110

111-
const { id: courseID } = state.course; // id refers to the course document id
112-
113111
const oldModule = state.course.modules[moduleID];
114112

115113
console.assert(oldIndex >= 0, "Old lesson index must be positive");
@@ -137,7 +135,7 @@ const reorderLessons = (
137135
};
138136
newState.hasChanged = updateChangeStatus(
139137
state.hasChanged,
140-
courseID,
138+
"<REORDER-LESSONS>",
141139
"COURSE-UPDATE",
142140
);
143141
return newState;

0 commit comments

Comments
 (0)