Skip to content

Redesign/improvement/submit inline questions in sequence #1467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/app/components/content/IsaacInlineRegion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,21 @@ export const useInlineRegionPart = (pageQuestions: AppQuestionDTO[] | undefined)
};
};

export const submitInlineRegion = (inlineContext: ContextType<typeof InlineContext>, currentGameboard: GameboardDTO | undefined, currentUser: any, pageQuestions: AppQuestionDTO[] | undefined, dispatch: any, hidingAttempts : boolean) => {
export const submitInlineRegion = async (inlineContext: ContextType<typeof InlineContext>, 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);
}
};

Expand Down
7 changes: 5 additions & 2 deletions src/app/services/questions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ export function useCurrentQuestionAttempt<T extends ChoiceDTO>(questionId: strin
};
}

export const submitCurrentAttempt = (questionPart: AppQuestionDTO | undefined, docId: string, questionType: string, currentGameboard: GameboardDTO | undefined, currentUser: any, dispatch: any, inlineContext?: ContextType<typeof InlineContext>) => {
export const submitCurrentAttempt = (questionPart: AppQuestionDTO | undefined, docId: string, questionType: string, currentGameboard: GameboardDTO | undefined, currentUser: any, dispatch: any, inlineContext?: ContextType<typeof InlineContext>): Promise<void> => {
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))) {
persistence.save(KEY.INITIAL_DAILY_QUESTION_ATTEMPT_TIME, new Date().toString());
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({
Expand All @@ -199,7 +199,10 @@ export const submitCurrentAttempt = (questionPart: AppQuestionDTO | undefined, d
redirectOnSuccess: false
}));
}

return attempt;
}
return Promise.resolve();
};

export const getMostRecentCorrectAttemptDate = (questions: AppQuestionDTO[] | undefined) => {
Expand Down
Loading