Skip to content

Commit 0cb40a5

Browse files
authored
Merge pull request #1466 from isaacphysics/improvement/submit-inline-questions-in-sequence
submit inline questions in a sequence
2 parents f5d95cf + d0d2f6d commit 0cb40a5

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/app/components/content/IsaacInlineRegion.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,21 @@ export const useInlineRegionPart = (pageQuestions: AppQuestionDTO[] | undefined)
8484
};
8585
};
8686

87-
export const submitInlineRegion = (inlineContext: ContextType<typeof InlineContext>, currentGameboard: GameboardDTO | undefined, currentUser: any, pageQuestions: AppQuestionDTO[] | undefined, dispatch: any, hidingAttempts : boolean) => {
87+
export const submitInlineRegion = async (inlineContext: ContextType<typeof InlineContext>, currentGameboard: GameboardDTO | undefined, currentUser: any, pageQuestions: AppQuestionDTO[] | undefined, dispatch: any, hidingAttempts : boolean) => {
8888
if (inlineContext && inlineContext.docId && pageQuestions) {
8989
inlineContext.setSubmitting(true);
90+
inlineContext.canShowWarningToast = true;
91+
if (Object.keys(inlineContext.elementToQuestionMap).length > 1) inlineContext.setFeedbackIndex(0);
92+
9093
const inlineQuestions = pageQuestions.filter(q => inlineContext.docId && q.id?.startsWith(inlineContext.docId) && q.id.includes("|inline-question:"));
9194
// 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
9295
const modifiedInlineQuestions = inlineQuestions.filter(q => (q.id && inlineContext.modifiedQuestionIds.includes(q.id)) || (q.currentAttempt?.value === undefined && (q.bestAttempt === undefined || hidingAttempts)));
9396
for (const inlineQuestion of modifiedInlineQuestions) {
94-
submitCurrentAttempt(
97+
await submitCurrentAttempt(
9598
{currentAttempt: inlineQuestion.currentAttempt},
9699
inlineQuestion.id as string, inlineQuestion.type as string, currentGameboard, currentUser, dispatch, inlineContext
97100
);
98101
}
99-
inlineContext.canShowWarningToast = true;
100-
if (Object.keys(inlineContext.elementToQuestionMap).length > 1) inlineContext.setFeedbackIndex(0);
101102
}
102103
};
103104

src/app/services/questions.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,15 @@ export function useCurrentQuestionAttempt<T extends ChoiceDTO>(questionId: strin
182182
};
183183
}
184184

185-
export const submitCurrentAttempt = (questionPart: AppQuestionDTO | undefined, docId: string, questionType: string, currentGameboard: GameboardDTO | undefined, currentUser: any, dispatch: any, inlineContext?: ContextType<typeof InlineContext>) => {
185+
export const submitCurrentAttempt = (questionPart: AppQuestionDTO | undefined, docId: string, questionType: string, currentGameboard: GameboardDTO | undefined, currentUser: any, dispatch: any, inlineContext?: ContextType<typeof InlineContext>): Promise<void> => {
186186
if (questionPart?.currentAttempt) {
187187
// Notify Plausible that at least one question attempt has taken place today
188188
if (persistence.load(KEY.INITIAL_DAILY_QUESTION_ATTEMPT_TIME) == null || !wasTodayUTC(persistence.load(KEY.INITIAL_DAILY_QUESTION_ATTEMPT_TIME))) {
189189
persistence.save(KEY.INITIAL_DAILY_QUESTION_ATTEMPT_TIME, new Date().toString());
190190
trackEvent("question_attempted");
191191
}
192192

193-
dispatch(attemptQuestion(docId, questionPart?.currentAttempt, questionType, currentGameboard?.id, inlineContext));
193+
const attempt = dispatch(attemptQuestion(docId, questionPart?.currentAttempt, questionType, currentGameboard?.id, inlineContext));
194194

195195
if (isLoggedIn(currentUser) && isNotPartiallyLoggedIn(currentUser) && currentGameboard?.id && !currentGameboard.savedToCurrentUser) {
196196
dispatch(saveGameboard({
@@ -199,7 +199,10 @@ export const submitCurrentAttempt = (questionPart: AppQuestionDTO | undefined, d
199199
redirectOnSuccess: false
200200
}));
201201
}
202+
203+
return attempt;
202204
}
205+
return Promise.resolve();
203206
};
204207

205208
export const getMostRecentCorrectAttemptDate = (questions: AppQuestionDTO[] | undefined) => {

0 commit comments

Comments
 (0)