Updated the eval calls to the backend, passed the navigation logic of level to useExamNavigation hook
This commit is contained in:
@@ -11,9 +11,10 @@ import { convertToUserSolutions } from "@/utils/stats";
|
||||
export type RootActions =
|
||||
{ type: 'INIT_EXAM'; payload: { exams: Exam[], modules: Module[], assignment?: Assignment } } |
|
||||
{ type: 'INIT_SOLUTIONS'; payload: { exams: Exam[], modules: Module[], stats: Stat[], timeSpent?: number, inactivity?: number } } |
|
||||
{ type: 'UPDATE_TIMERS'; payload: { timeSpent: number; inactivity: number; timeSpentCurrentModule: number;} } |
|
||||
{ type: 'UPDATE_TIMERS'; payload: { timeSpent: number; inactivity: number; timeSpentCurrentModule: number; } } |
|
||||
{ type: 'FINALIZE_MODULE'; payload: { updateTimers: boolean } } |
|
||||
{ type: 'FINALIZE_MODULE_SOLUTIONS' }
|
||||
{ type: 'FINALIZE_MODULE_SOLUTIONS' } |
|
||||
{ type: 'UPDATE_EXAMS'}
|
||||
|
||||
|
||||
export type Action = RootActions | SessionActions;
|
||||
@@ -84,19 +85,28 @@ export const rootReducer = (
|
||||
case 'UPDATE_TIMERS': {
|
||||
// Just assigning the timers at once instead of two different calls
|
||||
const { timeSpent, inactivity, timeSpentCurrentModule } = action.payload;
|
||||
return {
|
||||
return {
|
||||
timeSpentCurrentModule,
|
||||
timeSpent,
|
||||
inactivity
|
||||
timeSpent,
|
||||
inactivity
|
||||
}
|
||||
};
|
||||
case 'FINALIZE_MODULE': {
|
||||
const { updateTimers } = action.payload;
|
||||
const solutions = state.userSolutions;
|
||||
const evaluated = state.evaluated;
|
||||
|
||||
const hasUnevaluatedSolutions = solutions.some(solution =>
|
||||
(solution.type === 'speaking' ||
|
||||
solution.type === 'writing' ||
|
||||
solution.type === 'interactiveSpeaking') &&
|
||||
!evaluated.some(evaluation => evaluation.exercise === solution.exercise)
|
||||
);
|
||||
|
||||
// To finalize a module first flag the timers to be updated
|
||||
if (updateTimers) {
|
||||
return {
|
||||
flags: { ...state.flags, finalizeModule: true }
|
||||
flags: { ...state.flags, finalizeModule: true, pendingEvaluation: hasUnevaluatedSolutions }
|
||||
}
|
||||
} else {
|
||||
// then check whether there are more modules in the exam, if there are
|
||||
@@ -119,10 +129,12 @@ export const rootReducer = (
|
||||
// and the Finish view is set there, no need to
|
||||
// dispatch another init
|
||||
return {
|
||||
showSolutions: true,
|
||||
flags: {
|
||||
...state.flags,
|
||||
finalizeModule: false,
|
||||
finalizeExam: true,
|
||||
pendingEvaluation: hasUnevaluatedSolutions,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -155,6 +167,14 @@ export const rootReducer = (
|
||||
}
|
||||
}
|
||||
}
|
||||
case 'UPDATE_EXAMS': {
|
||||
const exams = state.exams.map((e) => updateExamWithUserSolutions(e, state.userSolutions));
|
||||
const exam = updateExamWithUserSolutions(state.exam!, state.userSolutions);
|
||||
return {
|
||||
exams,
|
||||
exam
|
||||
}
|
||||
}
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user