Skip to content

Commit 4e24010

Browse files
committed
[*not working] Support redirecting to contest voting workspace for code display
1 parent 8ce5de4 commit 4e24010

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/commons/assessmentWorkspace/AssessmentWorkspace.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import classNames from 'classnames';
1515
import { Chapter, Variant } from 'js-slang/dist/types';
1616
import { isEqual } from 'lodash';
1717
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
18-
import { useDispatch } from 'react-redux';
18+
import { useDispatch, useStore } from 'react-redux';
1919
import { useNavigate } from 'react-router';
2020
import { showSimpleConfirmDialog } from 'src/commons/utils/DialogHelper';
2121
import { onClickProgress } from 'src/features/assessments/AssessmentUtils';
@@ -29,7 +29,7 @@ import {
2929
SelectionRange
3030
} from '../../features/sourceRecorder/SourceRecorderTypes';
3131
import SessionActions from '../application/actions/SessionActions';
32-
import { defaultWorkspaceManager } from '../application/ApplicationTypes';
32+
import { defaultWorkspaceManager, OverallState } from '../application/ApplicationTypes';
3333
import {
3434
AssessmentConfiguration,
3535
AutogradingResult,
@@ -76,6 +76,7 @@ import Workspace, { WorkspaceProps } from '../workspace/Workspace';
7676
import WorkspaceActions from '../workspace/WorkspaceActions';
7777
import { WorkspaceLocation, WorkspaceState } from '../workspace/WorkspaceTypes';
7878
import AssessmentWorkspaceGradingResult from './AssessmentWorkspaceGradingResult';
79+
import LeaderboardActions from 'src/features/leaderboard/LeaderboardActions';
7980

8081
export type AssessmentWorkspaceProps = {
8182
assessmentId: number;
@@ -190,6 +191,23 @@ const AssessmentWorkspace: React.FC<AssessmentWorkspaceProps> = props => {
190191
// eslint-disable-next-line react-hooks/exhaustive-deps
191192
}, []);
192193

194+
const code = useTypedSelector(store =>store.leaderboard.code) || "Initial code";
195+
const state = useStore<OverallState>();
196+
useEffect(() => {
197+
console.log("CODE: ", code);
198+
const timeoutId = setTimeout(() => {
199+
if (code !== "Initial code") {
200+
console.log("UPDATING");
201+
dispatch(WorkspaceActions.updateEditorValue(workspaceLocation, 0, code));
202+
console.log("UPDATED EDITOR VALUE WORKSPACE: ", state.getState().workspaces[workspaceLocation].editorTabs[0].value);
203+
}
204+
205+
// Clear the code after the delay
206+
dispatch(LeaderboardActions.clearCode());
207+
}, 0);
208+
return () => clearTimeout(timeoutId);
209+
}, [dispatch, code]);
210+
193211
useEffect(() => {
194212
if (assessmentOverview && assessmentOverview.maxTeamSize > 1) {
195213
handleTeamOverviewFetch(props.assessmentId);
@@ -236,6 +254,8 @@ const AssessmentWorkspace: React.FC<AssessmentWorkspaceProps> = props => {
236254
} else {
237255
answer = (question as IProgrammingQuestion).solutionTemplate;
238256
}
257+
} else if (question.type === QuestionTypes.voting && code !== "Initial code") {
258+
answer = code;
239259
}
240260

241261
// TODO: Hardcoded to make use of the first editor tab. Refactoring is needed for this workspace to enable Folder mode.

0 commit comments

Comments
 (0)