Skip to content

Commit

Permalink
fix: Renamed a couple of things and removed unneeded check
Browse files Browse the repository at this point in the history
  • Loading branch information
rijuma committed Feb 23, 2024
1 parent 5a19192 commit 4cf4dca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/data/slice.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSlice } from '@reduxjs/toolkit';
import { aggregateActiveAttemptData } from '../helpers';
import { appendTimerEnd } from '../helpers';

/* eslint-disable no-param-reassign */
export const examSlice = createSlice({
Expand Down Expand Up @@ -77,10 +77,10 @@ export const examSlice = createSlice({
},
setExamState: (state, { payload }) => {
state.exam = payload.exam;
state.activeAttempt = aggregateActiveAttemptData(payload.activeAttempt);
state.activeAttempt = appendTimerEnd(payload.activeAttempt);
},
setActiveAttempt: (state, { payload }) => {
state.activeAttempt = aggregateActiveAttemptData(payload.activeAttempt);
state.activeAttempt = appendTimerEnd(payload.activeAttempt);
state.apiErrorMsg = '';
},
setProctoringSettings: (state, { payload }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const generateHumanizedTime = (timeRemainingSeconds) => {
// The only information we get on the remaining time on the active exam attempt
// from the endpoint is the remaining seconds. We need to have a fixed time reference
// on the time limit to be able to calculate the remaining time accurately.
export const aggregateActiveAttemptData = (activeAttempt) => {
export const appendTimerEnd = (activeAttempt) => {
if (!activeAttempt?.time_remaining_seconds) {
return activeAttempt;
}
Expand Down
9 changes: 4 additions & 5 deletions src/timer/TimerProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ const TimerProvider = ({

const pollExam = useCallback(() => {
// poll url may be null if this is an LTI exam
if (attempt?.exam_started_poll_url) {
dispatch(pollAttempt(attempt.exam_started_poll_url));
}
dispatch(pollAttempt(attempt.exam_started_poll_url));
}, [attempt.exam_started_poll_url, dispatch]);

const processTimeLeft = useCallback(() => (secondsLeft) => {
const criticalLowTime = timeLimitMins * 60 * TIME_LIMIT_CRITICAL_PCT;
const lowTime = timeLimitMins * 60 * TIME_LIMIT_LOW_PCT;
Expand Down Expand Up @@ -107,8 +106,8 @@ const TimerProvider = ({
dispatch(pingAttempt(pingInterval, workerUrl));
}

const keepRunning = processTimeLeft(secondsLeft);
if (!keepRunning) {
const keepTimerRunning = processTimeLeft(secondsLeft);
if (!keepTimerRunning) {
clearInterval(timerHandler);
}
}, 1000);
Expand Down

0 comments on commit 4cf4dca

Please sign in to comment.