Skip to content
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
2 changes: 1 addition & 1 deletion src/components/app/QuizView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
</h1>

<div class="mt-4 flex flex-col gap-3">
{#each q.options as opt (`${q.id}:${opt.id}`)}
{#each game.displayedOptions as opt (`${q.id}:${opt.id}`)}
<button
type="button"
class={optionClass(opt)}
Expand Down
16 changes: 16 additions & 0 deletions src/lib/quiz-state.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
AnswerOutcome,
Difficulty,
LifecycleUnit,
QuizOption,
QuizQuestion,
UnitId,
} from "$lib/far/types";
Expand Down Expand Up @@ -137,6 +138,8 @@ export class QuizGame {

// current question interaction
answeredOptionId = $state<string | null>(null);
/** Shuffled option order for the current question; stable until the next question. */
displayedOptions = $state<QuizOption[]>([]);

summary = $state<SessionSummary | null>(null);

Expand Down Expand Up @@ -222,6 +225,7 @@ export class QuizGame {
this.outcomes = [];
this.requeued = new SvelteSet();
this.answeredOptionId = null;
this.displayedOptions = [];
this.summary = null;
this.chapter = null;
this.chapterKind = null;
Expand All @@ -238,6 +242,7 @@ export class QuizGame {
this.outcomes = [];
this.requeued = new SvelteSet();
this.answeredOptionId = null;
this.displayedOptions = [];
this.summary = null;
this.activeChapterId = null;

Expand Down Expand Up @@ -529,6 +534,12 @@ export class QuizGame {
this.chapterKind = null;
this.shelf = null;
this.view = questions.length > 0 ? "session" : "home";
this.syncDisplayedOptions();
}

private syncDisplayedOptions() {
const q = this.currentQuestion;
this.displayedOptions = q ? shuffle(q.options) : [];
}

get currentQuestion(): QuizQuestion | undefined {
Expand Down Expand Up @@ -617,7 +628,10 @@ export class QuizGame {
}

if (this.queue.length === 0) {
this.displayedOptions = [];
this.finishSession();
} else {
this.syncDisplayedOptions();
}
}

Expand Down Expand Up @@ -694,6 +708,7 @@ export class QuizGame {
this.outcomes = [];
this.requeued = new SvelteSet();
this.answeredOptionId = null;
this.displayedOptions = [];
this.summary = null;
this.activeChapterId = null;
this.openChapter(chapter, "shelf-chapter");
Expand Down Expand Up @@ -743,6 +758,7 @@ export class QuizGame {
this.outcomes = [];
this.requeued = new SvelteSet();
this.answeredOptionId = null;
this.displayedOptions = [];
this.summary = null;
this.activeChapterId = null;
this.chapter = null;
Expand Down