@@ -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
0 commit comments