diff --git a/src/components/assessment/assessmentShape.ts b/src/components/assessment/assessmentShape.ts index 24598638f2..928b19d976 100644 --- a/src/components/assessment/assessmentShape.ts +++ b/src/components/assessment/assessmentShape.ts @@ -82,6 +82,7 @@ export interface IMCQQuestion extends IQuestion { export interface IQuestion { answer: string | number | null; + editorValue?: string | null; comment: string | null; content: string; id: number; diff --git a/src/components/incubator/EditingWorkspace.tsx b/src/components/incubator/EditingWorkspace.tsx index fb86e128f7..81e08fbeba 100644 --- a/src/components/incubator/EditingWorkspace.tsx +++ b/src/components/incubator/EditingWorkspace.tsx @@ -214,7 +214,6 @@ class AssessmentWorkspace extends React.Component { const assessment = retrieveLocalAssessment()!; - this.handleRefreshLibrary(); this.setState({ assessment, hasUnsavedChanges: false, @@ -222,6 +221,8 @@ class AssessmentWorkspace extends React.Component { - if (!this.state.editorPersist) { + private resetEditorValue = (checkPersist: boolean = true) => { + if (checkPersist || !this.state.editorPersist) { const question: IQuestion = this.state.assessment!.questions[this.formatedQuestionId()]; - const editorValue = - question.type === QuestionTypes.programming - ? ((question as IProgrammingQuestion).solutionTemplate as string) - : '//If you see this, this is a bug. Please report bug.'; + let editorValue: string; + if (question.type === QuestionTypes.programming) { + if (question.editorValue) { + editorValue = question.editorValue; + } else { + editorValue = (question as IProgrammingQuestion).solutionTemplate as string; + } + } else { + editorValue = '//If you see this, this is a bug. Please report bug.'; + } + this.props.handleResetWorkspace({ editorValue }); this.props.handleEditorValueChange(editorValue); } }; private handleSave = () => { + const assessment = this.state.assessment!; + assessment.questions[this.formatedQuestionId()].editorValue = this.props.editorValue; this.setState({ + assessment, hasUnsavedChanges: false }); - storeLocalAssessment(this.state.assessment!); + storeLocalAssessment(assessment); // this.handleRefreshLibrary(); this.handleSaveGradeAndXp(); }; @@ -371,11 +374,11 @@ class AssessmentWorkspace extends React.Component { - this.setState({ - editorPersist: !this.state.editorPersist - }); - }; + // private toggleEditorPersist = () => { + // this.setState({ + // editorPersist: !this.state.editorPersist + // }); + // }; /** Pre-condition: IAssessment has been loaded */ private sideContentProps: (p: AssessmentWorkspaceProps, q: number) => SideContentProps = ( @@ -561,9 +564,9 @@ class AssessmentWorkspace extends React.Component { IconNames.CONFIRM, this.confirmSave(this.makeQuestion(mcqTemplate, index)) )} -
- {index > 0 - ? controlButton( - 'Shift Question Left', - IconNames.CARET_LEFT, - this.confirmSave(this.shiftQuestion(-1)) - ) - : undefined} - {index < this.props.assessment.questions.length - 1 - ? controlButton( - 'Shift Question Right', - IconNames.CARET_RIGHT, - this.confirmSave(this.shiftQuestion(1)) - ) - : undefined} ); }; diff --git a/src/components/workspace/ControlBar.tsx b/src/components/workspace/ControlBar.tsx index d982a595bf..c712ec2244 100644 --- a/src/components/workspace/ControlBar.tsx +++ b/src/components/workspace/ControlBar.tsx @@ -147,7 +147,7 @@ class ControlBar extends React.PureComponent { ? controlButton('Reset', IconNames.REPEAT, this.props.onClickReset) : undefined; const editorPersistSwitch = - this.props.handleToggleEditorPersist !== null + this.props.handleToggleEditorPersist !== undefined ? controlButton( 'Editor Persistence ' + (this.props.isEditorPersist ? 'Enabled' : 'Disabled'), this.props.isEditorPersist ? IconNames.TICK : IconNames.CROSS, @@ -205,7 +205,11 @@ class ControlBar extends React.PureComponent { ' editing mode.' } > - {controlButton('Switch editing mode', IconNames.REFRESH, this.props.toggleEditMode)} + {controlButton( + this.props.editingMode + ' editing mode', + IconNames.REFRESH, + this.props.toggleEditMode + )} ) : ( undefined