@@ -214,14 +214,15 @@ class AssessmentWorkspace extends React.Component<AssessmentWorkspaceProps, ISta
214214 null ,
215215 ( ) => {
216216 const assessment = retrieveLocalAssessment ( ) ! ;
217- this . handleRefreshLibrary ( ) ;
218217 this . setState ( {
219218 assessment,
220219 hasUnsavedChanges : false ,
221220 showResetOverlay : false ,
222221 originalMaxGrade : this . getMaxMarks ( 'maxGrade' ) ,
223222 originalMaxXp : this . getMaxMarks ( 'maxXp' )
224223 } ) ;
224+ this . handleRefreshLibrary ( ) ;
225+ this . resetEditorValue ( ) ;
225226 } ,
226227 { minimal : false , intent : Intent . DANGER }
227228 ) }
@@ -248,24 +249,16 @@ class AssessmentWorkspace extends React.Component<AssessmentWorkspaceProps, ISta
248249 this . props . storedAssessmentId !== assessmentId ||
249250 this . props . storedQuestionId !== questionId
250251 ) {
251- const question = this . state . assessment ! . questions [ questionId ] ;
252- const editorValue =
253- question . type === QuestionTypes . programming
254- ? ( question as IProgrammingQuestion ) . solutionTemplate || ''
255- : null ;
252+ this . resetEditorValue ( false ) ;
256253 this . props . handleUpdateCurrentAssessmentId ( assessmentId , questionId ) ;
257- this . handleRefreshLibrary ( ) ;
258254 this . props . handleUpdateHasUnsavedChanges ( false ) ;
259- if ( editorValue && ! this . state . editorPersist ) {
260- this . props . handleResetWorkspace ( { editorValue } ) ;
261- this . props . handleEditorValueChange ( editorValue ) ;
262- }
263255 if ( this . state . hasUnsavedChanges ) {
264256 this . setState ( {
265257 assessment : retrieveLocalAssessment ( ) ,
266258 hasUnsavedChanges : false
267259 } ) ;
268260 }
261+ this . handleRefreshLibrary ( ) ;
269262 }
270263 }
271264
@@ -291,22 +284,32 @@ class AssessmentWorkspace extends React.Component<AssessmentWorkspaceProps, ISta
291284 this . props . handleClearContext ( library ) ;
292285 } ;
293286
294- private resetEditorValue = ( ) => {
295- if ( ! this . state . editorPersist ) {
287+ private resetEditorValue = ( checkPersist : boolean = true ) => {
288+ if ( checkPersist || ! this . state . editorPersist ) {
296289 const question : IQuestion = this . state . assessment ! . questions [ this . formatedQuestionId ( ) ] ;
297- const editorValue =
298- question . type === QuestionTypes . programming
299- ? ( ( question as IProgrammingQuestion ) . solutionTemplate as string )
300- : '//If you see this, this is a bug. Please report bug.' ;
290+ let editorValue : string ;
291+ if ( question . type === QuestionTypes . programming ) {
292+ if ( question . editorValue ) {
293+ editorValue = question . editorValue ;
294+ } else {
295+ editorValue = ( question as IProgrammingQuestion ) . solutionTemplate as string ;
296+ }
297+ } else {
298+ editorValue = '//If you see this, this is a bug. Please report bug.' ;
299+ }
300+ this . props . handleResetWorkspace ( { editorValue } ) ;
301301 this . props . handleEditorValueChange ( editorValue ) ;
302302 }
303303 } ;
304304
305305 private handleSave = ( ) => {
306+ const assessment = this . state . assessment ! ;
307+ assessment . questions [ this . formatedQuestionId ( ) ] . editorValue = this . props . editorValue ;
306308 this . setState ( {
309+ assessment,
307310 hasUnsavedChanges : false
308311 } ) ;
309- storeLocalAssessment ( this . state . assessment ! ) ;
312+ storeLocalAssessment ( assessment ) ;
310313 // this.handleRefreshLibrary();
311314 this . handleSaveGradeAndXp ( ) ;
312315 } ;
@@ -371,11 +374,11 @@ class AssessmentWorkspace extends React.Component<AssessmentWorkspaceProps, ISta
371374 } ) ;
372375 } ;
373376
374- private toggleEditorPersist = ( ) => {
375- this . setState ( {
376- editorPersist : ! this . state . editorPersist
377- } ) ;
378- } ;
377+ // private toggleEditorPersist = () => {
378+ // this.setState({
379+ // editorPersist: !this.state.editorPersist
380+ // });
381+ // };
379382
380383 /** Pre-condition: IAssessment has been loaded */
381384 private sideContentProps : ( p : AssessmentWorkspaceProps , q : number ) => SideContentProps = (
@@ -561,9 +564,9 @@ class AssessmentWorkspace extends React.Component<AssessmentWorkspaceProps, ISta
561564 questionProgress : [ questionId + 1 , this . state . assessment ! . questions . length ] ,
562565 sourceChapter : this . state . assessment ! . questions [ questionId ] . library . chapter ,
563566 editingMode : this . state . editingMode ,
564- toggleEditMode : this . toggleEditingMode ,
565- isEditorPersist : this . state . editorPersist ,
566- handleToggleEditorPersist : this . toggleEditorPersist
567+ toggleEditMode : this . toggleEditingMode
568+ // isEditorPersist: this.state.editorPersist,
569+ // handleToggleEditorPersist: this.toggleEditorPersist
567570 } ;
568571 } ;
569572}
0 commit comments