@@ -64,10 +64,15 @@ class GradingWorkspace extends React.Component<GradingWorkspaceProps> {
6464 )
6565 }
6666
67+ /* If questionId is out of bounds, set it to the max. */
68+ const questionId =
69+ this . props . questionId >= this . props . grading . length
70+ ? this . props . grading . length - 1
71+ : this . props . questionId
6772 /* Get the question to be graded */
68- const question = this . props . grading [ this . props . questionId ] . question as IQuestion
73+ const question = this . props . grading [ questionId ] . question as IQuestion
6974 const workspaceProps : WorkspaceProps = {
70- controlBarProps : this . controlBarProps ( this . props ) ,
75+ controlBarProps : this . controlBarProps ( this . props , questionId ) ,
7176 editorProps :
7277 question . type === QuestionTypes . programming
7378 ? {
@@ -84,7 +89,7 @@ class GradingWorkspace extends React.Component<GradingWorkspaceProps> {
8489 handleSideContentHeightChange : this . props . handleSideContentHeightChange ,
8590 mcq : question as IMCQQuestion ,
8691 sideContentHeight : this . props . sideContentHeight ,
87- sideContentProps : this . sideContentProps ( this . props ) ,
92+ sideContentProps : this . sideContentProps ( this . props , questionId ) ,
8893 replProps : {
8994 output : this . props . output ,
9095 replValue : this . props . replValue ,
@@ -100,29 +105,31 @@ class GradingWorkspace extends React.Component<GradingWorkspaceProps> {
100105 }
101106
102107 /** Pre-condition: Grading has been loaded */
103- private sideContentProps : ( p : GradingWorkspaceProps ) => SideContentProps = (
104- props : GradingWorkspaceProps
108+ private sideContentProps : ( p : GradingWorkspaceProps , q : number ) => SideContentProps = (
109+ props : GradingWorkspaceProps ,
110+ questionId : number
105111 ) => ( {
106112 activeTab : props . activeTab ,
107113 handleChangeActiveTab : props . handleChangeActiveTab ,
108114 tabs : [
109115 {
110- label : `Grading: Question ${ props . questionId } ` ,
116+ label : `Grading: Question ${ questionId } ` ,
111117 icon : IconNames . TICK ,
112118 /* Render an editor with the xp given to the current question. */
113- body : < GradingEditor maximumXP = { props . grading ! [ props . questionId ] . maximumXP } />
119+ body : < GradingEditor maximumXP = { props . grading ! [ questionId ] . maximumXP } />
114120 } ,
115121 {
116- label : `Task ${ props . questionId } ` ,
122+ label : `Task ${ questionId } ` ,
117123 icon : IconNames . NINJA ,
118- body : < Text > { props . grading ! [ props . questionId ] . question . content } </ Text >
124+ body : < Text > { props . grading ! [ questionId ] . question . content } </ Text >
119125 }
120126 ]
121127 } )
122128
123129 /** Pre-condition: Grading has been loaded */
124- private controlBarProps : ( p : GradingWorkspaceProps ) => ControlBarProps = (
125- props : GradingWorkspaceProps
130+ private controlBarProps : ( p : GradingWorkspaceProps , q : number ) => ControlBarProps = (
131+ props : GradingWorkspaceProps ,
132+ questionId : number
126133 ) => {
127134 const listingPath = `/academy/grading`
128135 const gradingWorkspacePath = listingPath + `/${ this . props . submissionId } `
@@ -133,18 +140,16 @@ class GradingWorkspace extends React.Component<GradingWorkspaceProps> {
133140 handleReplEval : this . props . handleReplEval ,
134141 handleReplOutputClear : this . props . handleReplOutputClear ,
135142 hasChapterSelect : false ,
136- hasNextButton : this . props . questionId < this . props . grading ! . length - 1 ,
137- hasPreviousButton : this . props . questionId > 0 ,
143+ hasDoneButton : questionId === this . props . grading ! . length - 1 ,
144+ hasNextButton : questionId < this . props . grading ! . length - 1 ,
145+ hasPreviousButton : questionId > 0 ,
138146 hasSaveButton : false ,
139147 hasShareButton : false ,
140- hasSubmitButton : this . props . questionId === this . props . grading ! . length - 1 ,
141148 isRunning : this . props . isRunning ,
142- onClickNext : ( ) =>
143- history . push ( gradingWorkspacePath + `/${ ( this . props . questionId + 1 ) . toString ( ) } ` ) ,
144- onClickPrevious : ( ) =>
145- history . push ( gradingWorkspacePath + `/${ ( this . props . questionId - 1 ) . toString ( ) } ` ) ,
146- onClickSubmit : ( ) => history . push ( listingPath ) ,
147- sourceChapter : 2 // TODO dynamic library changing
149+ onClickDone : ( ) => history . push ( listingPath ) ,
150+ onClickNext : ( ) => history . push ( gradingWorkspacePath + `/${ ( questionId + 1 ) . toString ( ) } ` ) ,
151+ onClickPrevious : ( ) => history . push ( gradingWorkspacePath + `/${ ( questionId - 1 ) . toString ( ) } ` ) ,
152+ sourceChapter : this . props . grading ! [ questionId ] . question . library . chapter
148153 }
149154 }
150155}
0 commit comments