Skip to content

feat: add "Previous Test" functionality with button and state management (@abhaychandra123)#7698

Open
abhaychandra123 wants to merge 2 commits intomonkeytypegame:masterfrom
abhaychandra123:master
Open

feat: add "Previous Test" functionality with button and state management (@abhaychandra123)#7698
abhaychandra123 wants to merge 2 commits intomonkeytypegame:masterfrom
abhaychandra123:master

Conversation

@abhaychandra123
Copy link

@abhaychandra123 abhaychandra123 commented Mar 22, 2026

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

  • Added a new Previous Test button next to Restart and wrapped both in a shared flex container in frontend/src/html/pages/test.html.
  • Added shared button styling and centered flex layout in frontend/src/styles/test.scss.
  • Updated coarse-pointer media query so both buttons keep consistent behavior on mobile/touch in frontend/src/styles/media-queries-blue.scss.
  • Added a command line command for previous quote navigation in frontend/src/ts/commandline/lists/navigation.ts.
  • Added quote history reset on mode/language transitions in frontend/src/ts/config/setters.ts.
  • Added click handler for Previous Test button in frontend/src/ts/event-handlers/test.ts.
  • Extended restart/init flow to support loading previous quote in frontend/src/ts/test/test-logic.ts.
  • Added quote history state management helpers in frontend/src/ts/test/test-state.ts.
  • Added previous button visibility updates on restart and config changes in frontend/src/ts/test/test-ui.ts.
  • Extended quote generation to support explicit previous-quote loading and safe history updates in frontend/src/ts/test/words-generator.ts.

Behavior details

  • Previous quote navigation is available only in quote mode and only when history exists.
  • History is session-scoped, capped at 50 entries, and cursor-based.
  • History resets when leaving quote mode or changing language.
  • Restart button styling is preserved; Previous now shares the same visual style and dimensions.

Checks

  • Not adding quotes
  • Not adding a language
  • Not adding a theme
  • Not adding a layout
  • Not adding a font
  • [x ] PR title follows Conventional Commits and includes GitHub username
  • Related issues linked below (if applicable)

Copilot AI review requested due to automatic review settings March 22, 2026 00:03
@monkeytypegeorge monkeytypegeorge added the frontend User interface or web stuff label Mar 22, 2026
@github-actions github-actions bot added the waiting for review Pull requests that require a review before continuing label Mar 22, 2026
@github-actions
Copy link
Contributor

Continuous integration check(s) failed. Please review the failing check's logs and make the necessary changes.

@github-actions github-actions bot added waiting for update Pull requests or issues that require changes/comments before continuing and removed waiting for review Pull requests that require a review before continuing labels Mar 22, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +571 to +581
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;
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 169 to 173
practiseMissed?: boolean;
noAnim?: boolean;
isQuickRestart?: boolean;
isPrevious?: boolean;
};
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
@abhaychandra123 abhaychandra123 changed the title feat: add "Previous Test" functionality with button and state management feat: add "Previous Test" functionality with button and state management (@abhaychandra123) Mar 22, 2026
@github-actions github-actions bot removed the waiting for update Pull requests or issues that require changes/comments before continuing label Mar 22, 2026
@abhaychandra123 abhaychandra123 marked this pull request as draft March 22, 2026 00:16
@abhaychandra123 abhaychandra123 marked this pull request as ready for review March 22, 2026 00:18
@github-actions github-actions bot added the waiting for review Pull requests that require a review before continuing label Mar 22, 2026
@abhaychandra123 abhaychandra123 requested a review from Copilot March 22, 2026 00:21
@abhaychandra123
Copy link
Author

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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • getQuoteWordList short-circuits on TestState.isRepeated before checking options.loadPreviousQuote, so "Previous Test" navigation won't work when the current test is in repeated mode (it just reuses the current wordset/quote). Consider handling loadPreviousQuote before the repeated early-return, or explicitly bypassing repeat behavior when loadPreviousQuote is 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;
    }
  }

@Miodec
Copy link
Member

Miodec commented Mar 22, 2026

Im not sure i see the point here? You can already use the repeat test button to type the same quote again.

@abhaychandra123
Copy link
Author

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:

  • repeat → same quote again
  • restart → completely new quote

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:

  • recover a quote they accidentally skipped
  • navigate back one step without repeatedly restarting and hoping it appears again

So it complements the repeat functionality rather than replacing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend User interface or web stuff waiting for review Pull requests that require a review before continuing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants