Skip to content
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

First card of second run of progressive mode wrongly flips #157

Open
hwgilbert16 opened this issue May 12, 2024 · 1 comment
Open

First card of second run of progressive mode wrongly flips #157

hwgilbert16 opened this issue May 12, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@hwgilbert16
Copy link
Owner

After the first run through of a progressive mode, if you start it a second time, the first card is flipped to the wrong side. This mistakenly reveals the answer.

@hwgilbert16 hwgilbert16 added the bug Something isn't working label May 12, 2024
@alan-cho
Copy link

The bug's behavior occurs only when the last card of the set is flipped in progressive mode. Regardless of how you answer (by term or definition), the state, this.side, is not switched before the second progressive run.

The issue lies within the conditional logic in changeCard of apps/front/src/app/study-set/study-set-flashcards/study-set-flashcards.component.ts.

// runs after a progressive mode round has completed
  if (this.index === this.cards.length - 1 && this.flashcardsMode === "progressive") {
    ...
  }

This conditional logic passes immediately after the first progressive run finishes. More precisely once you click either "don't know" or "know" on the last card.

Thus, it never makes it to this conditional right below:

  if (this.answer === "definition") {
    this.side = "term";
  } else {
    this.side = "definition";
  }

So the state (this.side) doesn't change appropriately.

A simple fix is just putting the conditional inside the one that runs after the first round of progressive mode finishes:

// runs after a progressive mode round has completed
    if (this.index === this.cards.length - 1 && this.flashcardsMode === "progressive") {
      // remove any cards that are known
      this.cards = this.cards.filter((c) => !this.knownCardIDs.includes(c.id));

      this.roundCompleted = true;

      // if the entire mode is not completed
      if (this.cards.length > 0) {
        this.index = 0;
        this.updateIndex();

        if (this.shufflingEnabled) this.cards = this.cards.sort(() => 0.5 - Math.random());
        
        // Ensures `this.side` is back to its appropriate state.
        if (this.answer === "definition") {
          this.side = "term";
        } else {
          this.side = "definition";
        }
        this.sideText = this.cards[0][this.side as keyof Card] as string;
      }

      this.flipped = false;
      this.flipInteraction = false;
      this.currentCard = this.cards[0];

      return;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants