diff --git a/src/app/components/content/IsaacInlineRegion.tsx b/src/app/components/content/IsaacInlineRegion.tsx index 4b61145b65..342da676a1 100644 --- a/src/app/components/content/IsaacInlineRegion.tsx +++ b/src/app/components/content/IsaacInlineRegion.tsx @@ -84,20 +84,21 @@ export const useInlineRegionPart = (pageQuestions: AppQuestionDTO[] | undefined) }; }; -export const submitInlineRegion = (inlineContext: ContextType, currentGameboard: GameboardDTO | undefined, currentUser: any, pageQuestions: AppQuestionDTO[] | undefined, dispatch: any, hidingAttempts : boolean) => { +export const submitInlineRegion = async (inlineContext: ContextType, currentGameboard: GameboardDTO | undefined, currentUser: any, pageQuestions: AppQuestionDTO[] | undefined, dispatch: any, hidingAttempts : boolean) => { if (inlineContext && inlineContext.docId && pageQuestions) { inlineContext.setSubmitting(true); + inlineContext.canShowWarningToast = true; + if (Object.keys(inlineContext.elementToQuestionMap).length > 1) inlineContext.setFeedbackIndex(0); + const inlineQuestions = pageQuestions.filter(q => inlineContext.docId && q.id?.startsWith(inlineContext.docId) && q.id.includes("|inline-question:")); // we submit all modified answers, and those with undefined values. we must submit this latter group to get a validation response at the same time as the other answers const modifiedInlineQuestions = inlineQuestions.filter(q => (q.id && inlineContext.modifiedQuestionIds.includes(q.id)) || (q.currentAttempt?.value === undefined && (q.bestAttempt === undefined || hidingAttempts))); for (const inlineQuestion of modifiedInlineQuestions) { - submitCurrentAttempt( + await submitCurrentAttempt( {currentAttempt: inlineQuestion.currentAttempt}, inlineQuestion.id as string, inlineQuestion.type as string, currentGameboard, currentUser, dispatch, inlineContext ); } - inlineContext.canShowWarningToast = true; - if (Object.keys(inlineContext.elementToQuestionMap).length > 1) inlineContext.setFeedbackIndex(0); } }; diff --git a/src/app/services/questions.ts b/src/app/services/questions.ts index b9ddf5e299..b975a028d1 100644 --- a/src/app/services/questions.ts +++ b/src/app/services/questions.ts @@ -182,7 +182,7 @@ export function useCurrentQuestionAttempt(questionId: strin }; } -export const submitCurrentAttempt = (questionPart: AppQuestionDTO | undefined, docId: string, questionType: string, currentGameboard: GameboardDTO | undefined, currentUser: any, dispatch: any, inlineContext?: ContextType) => { +export const submitCurrentAttempt = (questionPart: AppQuestionDTO | undefined, docId: string, questionType: string, currentGameboard: GameboardDTO | undefined, currentUser: any, dispatch: any, inlineContext?: ContextType): Promise => { if (questionPart?.currentAttempt) { // Notify Plausible that at least one question attempt has taken place today if (persistence.load(KEY.INITIAL_DAILY_QUESTION_ATTEMPT_TIME) == null || !wasTodayUTC(persistence.load(KEY.INITIAL_DAILY_QUESTION_ATTEMPT_TIME))) { @@ -190,7 +190,7 @@ export const submitCurrentAttempt = (questionPart: AppQuestionDTO | undefined, d trackEvent("question_attempted"); } - dispatch(attemptQuestion(docId, questionPart?.currentAttempt, questionType, currentGameboard?.id, inlineContext)); + const attempt = dispatch(attemptQuestion(docId, questionPart?.currentAttempt, questionType, currentGameboard?.id, inlineContext)); if (isLoggedIn(currentUser) && isNotPartiallyLoggedIn(currentUser) && currentGameboard?.id && !currentGameboard.savedToCurrentUser) { dispatch(saveGameboard({ @@ -199,7 +199,10 @@ export const submitCurrentAttempt = (questionPart: AppQuestionDTO | undefined, d redirectOnSuccess: false })); } + + return attempt; } + return Promise.resolve(); }; export const getMostRecentCorrectAttemptDate = (questions: AppQuestionDTO[] | undefined) => {