@@ -15,7 +15,7 @@ import classNames from 'classnames';
15
15
import { Chapter , Variant } from 'js-slang/dist/types' ;
16
16
import { isEqual } from 'lodash' ;
17
17
import React , { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
18
- import { useDispatch , useStore } from 'react-redux' ;
18
+ import { useDispatch } from 'react-redux' ;
19
19
import { useNavigate } from 'react-router' ;
20
20
import { showSimpleConfirmDialog } from 'src/commons/utils/DialogHelper' ;
21
21
import { onClickProgress } from 'src/features/assessments/AssessmentUtils' ;
@@ -31,7 +31,7 @@ import {
31
31
SelectionRange
32
32
} from '../../features/sourceRecorder/SourceRecorderTypes' ;
33
33
import SessionActions from '../application/actions/SessionActions' ;
34
- import { defaultWorkspaceManager , OverallState } from '../application/ApplicationTypes' ;
34
+ import { defaultWorkspaceManager } from '../application/ApplicationTypes' ;
35
35
import {
36
36
AssessmentConfiguration ,
37
37
AutogradingResult ,
@@ -86,6 +86,7 @@ export type AssessmentWorkspaceProps = {
86
86
notAttempted : boolean ;
87
87
canSave : boolean ;
88
88
assessmentConfiguration : AssessmentConfiguration ;
89
+ fromContestLeaderboard : boolean ;
89
90
} ;
90
91
91
92
const workspaceLocation : WorkspaceLocation = 'assessment' ;
@@ -187,25 +188,16 @@ const AssessmentWorkspace: React.FC<AssessmentWorkspaceProps> = props => {
187
188
} ;
188
189
} , [ dispatch ] ) ;
189
190
190
- const code = useTypedSelector ( store => store . leaderboard . code ) || 'Initial code' ;
191
- const state = useStore < OverallState > ( ) ;
192
- useEffect ( ( ) => {
193
- console . log ( 'CODE: ' , code ) ;
194
- const timeoutId = setTimeout ( ( ) => {
195
- if ( code !== 'Initial code' ) {
196
- console . log ( 'UPDATING' ) ;
197
- dispatch ( WorkspaceActions . updateEditorValue ( workspaceLocation , 0 , code ) ) ;
198
- console . log (
199
- 'UPDATED EDITOR VALUE WORKSPACE: ' ,
200
- state . getState ( ) . workspaces [ workspaceLocation ] . editorTabs [ 0 ] . value
201
- ) ;
202
- }
191
+ const code = useTypedSelector ( store => store . leaderboard . code ) ;
192
+ const initialRunCompleted = useTypedSelector ( store => store . leaderboard . initialRun ) ;
193
+ const votingId = props . assessmentId ;
203
194
204
- // Clear the code after the delay
195
+ useEffect ( ( ) => {
196
+ if ( initialRunCompleted [ votingId ] && props . fromContestLeaderboard && code != '' ) {
197
+ dispatch ( WorkspaceActions . updateEditorValue ( workspaceLocation , 0 , code ) ) ;
205
198
dispatch ( LeaderboardActions . clearCode ( ) ) ;
206
- } , 0 ) ;
207
- return ( ) => clearTimeout ( timeoutId ) ;
208
- } , [ dispatch , code ] ) ;
199
+ }
200
+ } , [ dispatch ] ) ;
209
201
210
202
useEffect ( ( ) => {
211
203
if ( assessmentOverview && assessmentOverview . maxTeamSize > 1 ) {
@@ -237,29 +229,6 @@ const AssessmentWorkspace: React.FC<AssessmentWorkspaceProps> = props => {
237
229
if ( ! assessment ) {
238
230
return ;
239
231
}
240
- // ------------- PLEASE NOTE, EVERYTHING BELOW THIS SEEMS TO BE UNUSED -------------
241
- // checkWorkspaceReset does exactly the same thing.
242
- let questionId = props . questionId ;
243
- if ( props . questionId >= assessment . questions . length ) {
244
- questionId = assessment . questions . length - 1 ;
245
- }
246
-
247
- const question = assessment . questions [ questionId ] ;
248
-
249
- let answer = '' ;
250
- if ( question . type === QuestionTypes . programming ) {
251
- if ( question . answer ) {
252
- answer = ( question as IProgrammingQuestion ) . answer as string ;
253
- } else {
254
- answer = ( question as IProgrammingQuestion ) . solutionTemplate ;
255
- }
256
- } else if ( question . type === QuestionTypes . voting && code !== 'Initial code' ) {
257
- answer = code ;
258
- }
259
-
260
- // TODO: Hardcoded to make use of the first editor tab. Refactoring is needed for this workspace to enable Folder mode.
261
- handleEditorValueChange ( 0 , answer ) ;
262
- // eslint-disable-next-line react-hooks/exhaustive-deps
263
232
} , [ ] ) ;
264
233
265
234
/**
@@ -268,7 +237,10 @@ const AssessmentWorkspace: React.FC<AssessmentWorkspaceProps> = props => {
268
237
*/
269
238
useEffect ( ( ) => {
270
239
checkWorkspaceReset ( ) ;
271
- } ) ;
240
+ if ( assessment != undefined && question . type == "voting" ) {
241
+ dispatch ( LeaderboardActions . setWorkspaceInitialRun ( votingId ) ) ;
242
+ }
243
+ } , [ dispatch , assessment ] ) ;
272
244
273
245
/**
274
246
* Handles toggling enabling and disabling token counter depending on assessment properties
@@ -410,6 +382,7 @@ const AssessmentWorkspace: React.FC<AssessmentWorkspaceProps> = props => {
410
382
case QuestionTypes . voting :
411
383
const votingQuestionData : IContestVotingQuestion = question ;
412
384
options . programPrependValue = votingQuestionData . prepend ;
385
+ if ( props . fromContestLeaderboard ) options . editorValue = code ;
413
386
options . programPostpendValue = votingQuestionData . postpend ;
414
387
break ;
415
388
case QuestionTypes . mcq :
0 commit comments