feat: add "Previous Test" functionality with button and state management (@abhaychandra123)#7698
feat: add "Previous Test" functionality with button and state management (@abhaychandra123)#7698abhaychandra123 wants to merge 2 commits intomonkeytypegame:masterfrom
Conversation
|
Continuous integration check(s) failed. Please review the failing check's logs and make the necessary changes. |
There was a problem hiding this comment.
Pull request overview
Adds session-scoped “Previous Test” navigation for quote mode and aligns the Restart/Previous action buttons in the test UI.
Changes:
- Introduces quote history state + “load previous quote” generation path, wired through restart/init flow.
- Adds Previous Test UI button + commandline command, with visibility gated by quote mode + history cursor.
- Refactors test action button layout/styling to keep Restart/Previous consistent across pointer types.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/ts/test/words-generator.ts | Adds generation options and previous-quote selection/history updates in quote generation. |
| frontend/src/ts/test/test-ui.ts | Updates Previous button visibility on restart and relevant config changes. |
| frontend/src/ts/test/test-state.ts | Adds quote history array + cursor and helper functions (peek/commit/push/reset). |
| frontend/src/ts/test/test-logic.ts | Extends restart/init flow to request loading the previous quote. |
| frontend/src/ts/event-handlers/test.ts | Adds click handler for #previousTestButton to restart in “previous” mode. |
| frontend/src/ts/config/setters.ts | Resets quote history when leaving quote mode or when language changes. |
| frontend/src/ts/commandline/lists/navigation.ts | Adds previousTest command gated by quote mode + history. |
| frontend/src/styles/test.scss | Wraps action buttons in a flex container and adds shared button styling. |
| frontend/src/styles/media-queries-blue.scss | Ensures Previous/Restart buttons display consistently on coarse pointers. |
| frontend/src/html/pages/test.html | Adds Previous button and groups it with Restart under a shared container. |
| if (options.loadPreviousQuote) { | ||
| const prevQuoteId = TestState.peekPreviousQuoteId(); | ||
| if (prevQuoteId !== null) { | ||
| const targetQuote = QuotesController.getQuoteById(prevQuoteId); | ||
| if (targetQuote === undefined) { | ||
| setQuoteLengthAll(); | ||
| throw new WordGenError(`Quote ${prevQuoteId} does not exist`); | ||
| } | ||
| TestState.commitPreviousNavigation(); | ||
| rq = targetQuote; | ||
| wasPrevious = true; |
There was a problem hiding this comment.
commitPreviousNavigation() mutates quote history inside generateWords flow. init() retries on any WordGenError/Error (calls init(loadPreviousQuote) again), so if a later step throws (e.g. funbox withWords, getNextWord, etc.), the history cursor will already be decremented and the retry will skip an extra quote / lose the ability to navigate back. Safer: only commit the cursor after full word generation + init succeeds, or add rollback on failure.
| practiseMissed?: boolean; | ||
| noAnim?: boolean; | ||
| isQuickRestart?: boolean; | ||
| isPrevious?: boolean; | ||
| }; |
There was a problem hiding this comment.
restart({ isPrevious: true }) can be overridden by existing logic that forces options.withSameWordset = true when repeatQuotes === "typing" (and in repeated tests). In that case TestState.isRepeated short-circuits quote selection, so “Previous Test” won’t actually navigate back. Consider explicitly disabling withSameWordset when isPrevious is set (or otherwise ensuring the previous-quote path wins).
|
btw what my Motivation is, In quote mode, restarting a test always fetches a new quote. In practice, users often restart multiple times to find a quote they like or are in the mood to type. However, this leads to a small but frustrating UX issue |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
frontend/src/ts/test/words-generator.ts:516
getQuoteWordListshort-circuits onTestState.isRepeatedbefore checkingoptions.loadPreviousQuote, so "Previous Test" navigation won't work when the current test is in repeated mode (it just reuses the current wordset/quote). Consider handlingloadPreviousQuotebefore the repeated early-return, or explicitly bypassing repeat behavior whenloadPreviousQuoteis true.
async function getQuoteWordList(
language: LanguageObject,
wordOrder: FunboxWordOrder | undefined,
options: GenerateWordsOptions,
): Promise<string[]> {
if (TestState.isRepeated) {
if (currentWordset === null) {
throw new WordGenError("Current wordset is null");
}
TestWords.setCurrentQuote(previousRandomQuote);
// need to re-reverse the words if the test is repeated
// because it will be reversed again in the generateWords function
if (wordOrder === "reverse") {
return currentWordset.words.reverse();
} else {
return currentWordset.words;
}
}
|
Im not sure i see the point here? You can already use the repeat test button to type the same quote again. |
You're right that the repeat test button allows retyping the same quote. This feature is solving a slightly different problem: When browsing quotes, it's common to restart multiple times to find a quote that feels interesting or comfortable to type. In that process, it's easy to accidentally skip over a quote you actually wanted to type. The current behavior only allows:
There is no way to go back to a previously shown quote after a restart. This change introduces a lightweight history (only for quote mode) so users can:
So it complements the repeat functionality rather than replacing it. |
Title
feat(frontend): add previous quote navigation + align test action buttons (@abhaychandra123)
Summary
This PR adds session-based previous-quote navigation in quote mode and refactors test action button layout so Previous and Restart are consistently sized, aligned, and centered.
What changed
Behavior details
Checks