diff --git a/frontend/task/index.ts b/frontend/task/index.ts index abad5802..ae5e18c2 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 acb42669..69347ac2 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 52198e83..434d2f61 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 b918c71e..b604d552 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)); }, }; }