From 60c2ec50387aec37958668a52372047532fb54a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Tainon?= Date: Wed, 24 Apr 2024 12:23:06 +0200 Subject: [PATCH] Separate the behavior of saving the score VS showing the result popup to the user. When reloading an answer, save the score but do not show the result popup --- frontend/task/index.ts | 4 ++-- frontend/task/platform/actionTypes.ts | 5 +++-- frontend/task/platform/platform.ts | 17 +++++++++-------- frontend/task/platform/task_channel.ts | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/frontend/task/index.ts b/frontend/task/index.ts index abad58025..ae5e18c2b 100644 --- a/frontend/task/index.ts +++ b/frontend/task/index.ts @@ -521,9 +521,9 @@ function* taskChangeLevelSaga({payload}: ReturnType) { const oldAnswer = selectAnswer(state); yield* put(platformSaveAnswer({level: currentLevel, answer: oldAnswer})); - // Grade old answer + // Grade old answer with updateScore = true and showResult = false const answer = stringify(yield* getTaskAnswerAggregated()); - yield* call(taskGradeAnswerEventSaga, taskGradeAnswerEvent(answer, null, () => {}, () => {}, true)); + yield* call(taskGradeAnswerEventSaga, taskGradeAnswerEvent(answer, null, () => {}, () => {}, true, false)); log.getLogger('task').debug('grading finished'); // Change level diff --git a/frontend/task/platform/actionTypes.ts b/frontend/task/platform/actionTypes.ts index acb42669e..69347ac20 100644 --- a/frontend/task/platform/actionTypes.ts +++ b/frontend/task/platform/actionTypes.ts @@ -67,13 +67,14 @@ export const taskReloadAnswerEvent = createAction('taskEventReloadAnswer', (answ error, }, })); -export const taskGradeAnswerEvent = createAction('taskEventGradeAnswer', (answer, answerToken, success, error, silent) => ({ +export const taskGradeAnswerEvent = createAction('taskEventGradeAnswer', (answer, answerToken, success, error, updateScore: boolean, showResult: boolean) => ({ payload: { answer, answerToken, success, error, - silent, + updateScore, + showResult, }, })); export const taskGetResourcesPost = createAction('taskEventGetResourcesPost', (resources, callback) => ({ diff --git a/frontend/task/platform/platform.ts b/frontend/task/platform/platform.ts index 52198e83e..434d2f614 100644 --- a/frontend/task/platform/platform.ts +++ b/frontend/task/platform/platform.ts @@ -335,7 +335,8 @@ function* taskReloadAnswerEventSaga ({payload: {answer, success, error}}: Return yield* put(platformTaskRefresh()); } } - yield* call(taskGradeAnswerEventSaga, taskGradeAnswerEvent(JSON.stringify(convertedAnswer), null, success, error, true)); + // Grade with updateScore = true and showResult = false + yield* call(taskGradeAnswerEventSaga, taskGradeAnswerEvent(JSON.stringify(convertedAnswer), null, success, error, true, false)); yield* call(taskAnswerReloadedSaga); } else if (answer) { const answerObject = yield* call(backwardCompatibilityConvert, JSON.parse(answer)); @@ -481,7 +482,7 @@ function* taskLoadEventSaga ({payload: {views: _views, success, error}}: ReturnT } } -export function* taskGradeAnswerEventSaga ({payload: {answer, success, error, silent}}: ReturnType) { +export function* taskGradeAnswerEventSaga ({payload: {answer, success, error, updateScore, showResult}}: ReturnType) { try { const taskLevels = yield* appSelect(state => state.platform.levels); log.getLogger('tests').debug('task levels', taskLevels); @@ -513,7 +514,7 @@ export function* taskGradeAnswerEventSaga ({payload: {answer, success, error, si currentScoreToken = scoreToken; } - if (!silent) { + if (updateScore) { yield* put(platformSaveScore({level, score, answer: answerObject[level]})); } } @@ -525,7 +526,7 @@ export function* taskGradeAnswerEventSaga ({payload: {answer, success, error, si const reconciledScore = computeReconciledScore(levelScores); const scoreWithPlatformParameters = minScore + (maxScore - minScore) * reconciledScore; - if (!silent) { + if (showResult) { yield* put(platformAnswerGraded({score: currentScore, message: currentMessage})); } @@ -543,7 +544,7 @@ export function* taskGradeAnswerEventSaga ({payload: {answer, success, error, si const {score, message, scoreToken} = yield* call([taskGrader, taskGrader.gradeAnswer], {answer: answerObject}); const scoreWithPlatformParameters = minScore + (maxScore - minScore) * score; - if (!silent) { + if (showResult) { yield* put(platformAnswerGraded({score, message})); } log.getLogger('tests').debug('[Tests] Evaluation result', {scoreWithPlatformParameters, message}); @@ -552,7 +553,7 @@ export function* taskGradeAnswerEventSaga ({payload: {answer, success, error, si } catch (ex: any) { const message = ex.message === 'Network request failed' ? getMessage('SUBMISSION_RESULTS_CRASHED_NETWORK') : (ex.message ? ex.message : ex.toString()); - if (!silent) { + if (showResult) { yield* put(platformAnswerGraded({error: message})); } console.error(ex); @@ -605,8 +606,8 @@ function* platformValidateEventSaga({payload: {mode}}: ReturnType {}, () => {}, false)); + // Grade with updateScore = true and showResult = true + yield* call(taskGradeAnswerEventSaga, taskGradeAnswerEvent(answer, null, () => {}, () => {}, true, true)); } } diff --git a/frontend/task/platform/task_channel.ts b/frontend/task/platform/task_channel.ts index b918c71ed..b604d5525 100644 --- a/frontend/task/platform/task_channel.ts +++ b/frontend/task/platform/task_channel.ts @@ -69,7 +69,7 @@ function makeTask (emit, state: AppStore) { } else { silent = true; } - emit(taskGradeAnswerEvent(answer, answerToken, success ?? (() => {}), error ?? (() => {}), silent)); + emit(taskGradeAnswerEvent(answer, answerToken, success ?? (() => {}), error ?? (() => {}), !silent, !silent)); }, }; }