Skip to content

Commit a0aa6fb

Browse files
committed
Fix bug where turning off token counter would not work in repl
1 parent 76ee585 commit a0aa6fb

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

src/commons/assessmentWorkspace/AssessmentWorkspace.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import {
7676
changeExecTime,
7777
changeSideContentHeight,
7878
clearReplOutput,
79+
disableTokenCounter,
7980
enableTokenCounter,
8081
evalEditor,
8182
evalRepl,
@@ -152,7 +153,8 @@ const AssessmentWorkspace: React.FC<AssessmentWorkspaceProps> = props => {
152153
handleReplEval,
153154
handleSave,
154155
handleUpdateHasUnsavedChanges,
155-
handleEnableTokenCounter
156+
handleEnableTokenCounter,
157+
handleDisableTokenCounter
156158
} = useMemo(() => {
157159
return {
158160
handleTestcaseEval: (id: number) => dispatch(evalTestcase(workspaceLocation, id)),
@@ -178,7 +180,9 @@ const AssessmentWorkspace: React.FC<AssessmentWorkspaceProps> = props => {
178180
handleUpdateHasUnsavedChanges: (hasUnsavedChanges: boolean) =>
179181
dispatch(updateHasUnsavedChanges(workspaceLocation, hasUnsavedChanges)),
180182
handleEnableTokenCounter: () =>
181-
dispatch(enableTokenCounter(workspaceLocation))
183+
dispatch(enableTokenCounter(workspaceLocation)),
184+
handleDisableTokenCounter: () =>
185+
dispatch(disableTokenCounter(workspaceLocation))
182186
};
183187
}, [dispatch]);
184188

@@ -244,13 +248,15 @@ const AssessmentWorkspace: React.FC<AssessmentWorkspaceProps> = props => {
244248
});
245249

246250
/**
247-
* Handles toggling enabling token counter depending on assessment properties
251+
* Handles toggling enabling and disabling token counter depending on assessment properties
248252
*/
249253
useEffect(() => {
250254
if (props.assessmentConfiguration.hasTokenCounter) {
251255
handleEnableTokenCounter();
256+
} else {
257+
handleDisableTokenCounter();
252258
}
253-
}, [props, handleEnableTokenCounter]);
259+
}, [props, handleEnableTokenCounter, handleDisableTokenCounter]);
254260

255261
/**
256262
* Handles toggling of relevant SideContentTabs when mobile breakpoint it hit

src/commons/workspace/WorkspaceActions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
CLEAR_REPL_INPUT,
2929
CLEAR_REPL_OUTPUT,
3030
CLEAR_REPL_OUTPUT_LAST,
31+
DISABLE_TOKEN_COUNTER,
3132
EditorTabState,
3233
ENABLE_TOKEN_COUNTER,
3334
END_CLEAR_CONTEXT,
@@ -186,6 +187,9 @@ export const runAllTestcases = (workspaceLocation: WorkspaceLocation) =>
186187
export const enableTokenCounter = (workspaceLocation: WorkspaceLocation) =>
187188
action(ENABLE_TOKEN_COUNTER, { workspaceLocation });
188189

190+
export const disableTokenCounter = (workspaceLocation: WorkspaceLocation) =>
191+
action(DISABLE_TOKEN_COUNTER, { workspaceLocation });
192+
189193
export const toggleFolderMode = (workspaceLocation: WorkspaceLocation) =>
190194
action(TOGGLE_FOLDER_MODE, { workspaceLocation });
191195

src/commons/workspace/WorkspaceReducer.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
CLEAR_REPL_INPUT,
4646
CLEAR_REPL_OUTPUT,
4747
CLEAR_REPL_OUTPUT_LAST,
48+
DISABLE_TOKEN_COUNTER,
4849
EditorTabState,
4950
ENABLE_TOKEN_COUNTER,
5051
END_CLEAR_CONTEXT,
@@ -354,7 +355,15 @@ export const WorkspaceReducer: Reducer<WorkspaceManagerState> = (
354355
...state[workspaceLocation],
355356
hasTokenCounter: true
356357
}
357-
}
358+
};
359+
case DISABLE_TOKEN_COUNTER:
360+
return {
361+
...state,
362+
[workspaceLocation]: {
363+
...state[workspaceLocation],
364+
hasTokenCounter: false
365+
}
366+
};
358367
case EVAL_EDITOR:
359368
return {
360369
...state,

src/commons/workspace/WorkspaceTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const CLEAR_REPL_OUTPUT = 'CLEAR_REPL_OUTPUT';
2323
export const CLEAR_REPL_OUTPUT_LAST = 'CLEAR_REPL_OUTPUT_LAST';
2424
export const END_CLEAR_CONTEXT = 'END_CLEAR_CONTEXT';
2525
export const ENABLE_TOKEN_COUNTER = 'ENABLE_TOKEN_COUNTER';
26+
export const DISABLE_TOKEN_COUNTER = 'DISABLE_TOKEN_COUNTER';
2627
export const EVAL_EDITOR = 'EVAL_EDITOR';
2728
export const EVAL_REPL = 'EVAL_REPL';
2829
export const PROMPT_AUTOCOMPLETE = 'PROMPT_AUTOCOMPLETE';

0 commit comments

Comments
 (0)