1- import {
2- Button ,
3- ButtonGroup ,
4- Card ,
5- Classes ,
6- Dialog ,
7- Intent ,
8- NonIdealState ,
9- Spinner
10- } from '@blueprintjs/core'
1+ import { Button , Card , Dialog , NonIdealState , Spinner } from '@blueprintjs/core'
112import { IconNames } from '@blueprintjs/icons'
123import * as React from 'react'
134
145import { InterpreterOutput , IWorkspaceState } from '../../reducers/states'
156import { beforeNow } from '../../utils/dateHelpers'
167import { history } from '../../utils/history'
178import { assessmentCategoryLink } from '../../utils/paramParseHelpers'
18- import { controlButton } from '../commons'
199import Markdown from '../commons/Markdown'
2010import Workspace , { WorkspaceProps } from '../workspace'
2111import { ControlBarProps } from '../workspace/ControlBar'
@@ -77,15 +67,13 @@ export type DispatchProps = {
7767
7868class AssessmentWorkspace extends React . Component <
7969 AssessmentWorkspaceProps ,
80- { showOverlay : boolean ; showResetOverlay : boolean }
70+ { showOverlay : boolean }
8171> {
8272 public constructor ( props : AssessmentWorkspaceProps ) {
8373 super ( props )
8474 this . state = {
85- showOverlay : false ,
86- showResetOverlay : false
75+ showOverlay : false
8776 }
88- this . props . handleEditorValueChange ( '' )
8977 }
9078
9179 /**
@@ -98,20 +86,6 @@ class AssessmentWorkspace extends React.Component<
9886 if ( this . props . questionId === 0 && this . props . notAttempted ) {
9987 this . setState ( { showOverlay : true } )
10088 }
101- if ( this . props . assessment ) {
102- const question : IQuestion = this . props . assessment . questions [
103- this . props . questionId >= this . props . assessment . questions . length
104- ? this . props . assessment . questions . length - 1
105- : this . props . questionId
106- ]
107- this . props . handleEditorValueChange (
108- question . type === QuestionTypes . programming
109- ? question . answer !== null
110- ? ( ( question as IProgrammingQuestion ) . answer as string )
111- : ( question as IProgrammingQuestion ) . solutionTemplate
112- : ''
113- )
114- }
11589 }
11690
11791 /**
@@ -145,53 +119,24 @@ class AssessmentWorkspace extends React.Component<
145119 </ Card >
146120 </ Dialog >
147121 )
148-
149- const resetOverlay = (
150- < Dialog
151- className = "assessment-reset"
152- icon = { IconNames . ERROR }
153- isCloseButtonShown = { false }
154- isOpen = { this . state . showResetOverlay }
155- title = "Confirmation: Reset editor?"
156- >
157- < div className = { Classes . DIALOG_BODY } >
158- < Markdown content = "Are you sure you want to reset the template?" />
159- < Markdown content = "*Note this will not affect the saved copy of your code, unless you save over it.*" />
160- </ div >
161- < div className = { Classes . DIALOG_FOOTER } >
162- < ButtonGroup >
163- { controlButton ( 'Cancel' , null , ( ) => this . setState ( { showResetOverlay : false } ) , {
164- minimal : false
165- } ) }
166- { controlButton (
167- 'Confirm' ,
168- null ,
169- ( ) => {
170- this . setState ( { showResetOverlay : false } )
171- this . props . handleEditorValueChange (
172- ( this . props . assessment ! . questions [ questionId ] as IProgrammingQuestion )
173- . solutionTemplate
174- )
175- this . props . handleUpdateHasUnsavedChanges ( true )
176- } ,
177- { minimal : false , intent : Intent . DANGER }
178- ) }
179- </ ButtonGroup >
180- </ div >
181- </ Dialog >
182- )
183122 /* If questionId is out of bounds, set it to the max. */
184123 const questionId =
185124 this . props . questionId >= this . props . assessment . questions . length
186125 ? this . props . assessment . questions . length - 1
187126 : this . props . questionId
188127 const question : IQuestion = this . props . assessment . questions [ questionId ]
128+ const editorValue =
129+ question . type === QuestionTypes . programming
130+ ? question . answer !== null
131+ ? ( ( question as IProgrammingQuestion ) . answer as string )
132+ : ( question as IProgrammingQuestion ) . solutionTemplate
133+ : null
189134 const workspaceProps : WorkspaceProps = {
190135 controlBarProps : this . controlBarProps ( this . props , questionId ) ,
191136 editorProps :
192137 question . type === QuestionTypes . programming
193138 ? {
194- editorValue : this . props . editorValue ! ,
139+ editorValue : editorValue ! ,
195140 handleEditorEval : this . props . handleEditorEval ,
196141 handleEditorValueChange : this . props . handleEditorValueChange ,
197142 handleUpdateHasUnsavedChanges : this . props . handleUpdateHasUnsavedChanges
@@ -220,7 +165,6 @@ class AssessmentWorkspace extends React.Component<
220165 return (
221166 < div className = "WorkspaceParent pt-dark" >
222167 { overlay }
223- { resetOverlay }
224168 < Workspace { ...workspaceProps } />
225169 </ div >
226170 )
@@ -250,7 +194,7 @@ class AssessmentWorkspace extends React.Component<
250194 ? question . answer !== null
251195 ? ( ( question as IProgrammingQuestion ) . answer as string )
252196 : ( question as IProgrammingQuestion ) . solutionTemplate
253- : ''
197+ : null
254198 this . props . handleUpdateCurrentAssessmentId ( assessmentId , questionId )
255199 this . props . handleResetWorkspace ( { editorValue } )
256200 this . props . handleClearContext ( question . library )
@@ -341,9 +285,6 @@ class AssessmentWorkspace extends React.Component<
341285 this . props . assessment ! . questions [ questionId ] . id ,
342286 this . props . editorValue !
343287 ) ,
344- onClickReset : ( ) => {
345- this . setState ( { showResetOverlay : true } )
346- } ,
347288 questionProgress : [ questionId + 1 , this . props . assessment ! . questions . length ] ,
348289 sourceChapter : this . props . assessment ! . questions [ questionId ] . library . chapter
349290 }
0 commit comments