Skip to content

Commit

Permalink
Calculate interrupted & non-interrupted wrong answers differently (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubk authored Nov 9, 2023
1 parent 40021fb commit bba266d
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 10 deletions.
179 changes: 179 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"dev:api:start": "npx wrangler pages dev /functions --compatibility-date=2023-09-22",
"dev:tunnel": "../ngrok http --domain=causal-magpie-closing.ngrok-free.app 5173",
"test:api": "npx vitest --dir functions/",
"test:api:coverage:": "npx vitest run --dir functions/ --coverage",
"test:frontend": "npx vitest --dir src/",
"test:frontend:coverage": "npx vitest run --dir src/ --coverage",
"prod:api:logs": "npx wrangler pages deployment tail",
"prod:deploy": "npx wrangler pages publish functions --project-name=memo-card"
},
Expand Down Expand Up @@ -45,6 +47,7 @@
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vitejs/plugin-react": "^4.0.3",
"@vitest/coverage-v8": "^0.34.6",
"eslint": "^8.45.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
Expand Down
15 changes: 9 additions & 6 deletions src/store/deck-form-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class DeckFormStore {
}

openNewCardForm() {
assert(this.form, 'openNewCardForm: form is empty');
assert(this.form, "openNewCardForm: form is empty");
this.cardFormIndex = this.form.cards.length;
this.form.cards.push({
front: createCardSideField(""),
Expand All @@ -101,7 +101,7 @@ export class DeckFormStore {
}

async onCardBack() {
assert(this.cardForm, 'onCardBack: cardForm is empty');
assert(this.cardForm, "onCardBack: cardForm is empty");
if (isFormEmpty(this.cardForm)) {
this.quitCardForm();
return;
Expand All @@ -114,7 +114,7 @@ export class DeckFormStore {
}

async onDeckBack() {
assert(this.form, 'onDeckBack: form is empty');
assert(this.form, "onDeckBack: form is empty");
if (isFormEmpty(this.form) || !isFormTouched(this.form)) {
screenStore.navigateToMain();
return;
Expand All @@ -127,7 +127,7 @@ export class DeckFormStore {
}

onDeckSave() {
assert(this.form, 'onDeckSave: form is empty');
assert(this.form, "onDeckSave: form is empty");

if (this.form.cards.length === 0) {
showAlert("Please add at least 1 card to create a deck");
Expand Down Expand Up @@ -161,8 +161,11 @@ export class DeckFormStore {
}

quitCardForm() {
assert(this.cardFormIndex !== undefined, 'quitCardForm: cardFormIndex is empty');
assert(this.form, 'quitCardForm: form is empty');
assert(
this.cardFormIndex !== undefined,
"quitCardForm: cardFormIndex is empty",
);
assert(this.form, "quitCardForm: form is empty");
this.form.cards.splice(this.cardFormIndex, 1);
this.cardFormIndex = undefined;
}
Expand Down
5 changes: 4 additions & 1 deletion src/store/quick-add-card-form-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export class QuickAddCardFormStore {
return;
}

assert(screenStore.cardQuickAddDeckId, "cardQuickAddDeckId should not be empty");
assert(
screenStore.cardQuickAddDeckId,
"cardQuickAddDeckId should not be empty",
);

this.isSending = true;

Expand Down
9 changes: 7 additions & 2 deletions src/store/review-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { assert } from "../lib/typescript/assert.ts";
import { reviewCardsRequest } from "../api/api.ts";
import { ReviewOutcome } from "../../functions/services/review-card.ts";
import { screenStore } from "./screen-store.ts";
import { deckListStore } from "./deck-list-store.ts";

type ReviewResult = {
forgotIds: number[];
Expand Down Expand Up @@ -70,7 +71,10 @@ export class ReviewStore {

changeState(cardState: CardState) {
const currentCard = this.currentCard;
assert(currentCard, "currentCard should not be null while changing state in review");
assert(
currentCard,
"currentCard should not be null while changing state in review",
);
currentCard.changeState(cardState);

const currentCardIdx = this.cardsToReview.findIndex(
Expand Down Expand Up @@ -116,7 +120,7 @@ export class ReviewStore {
return;
}

return reviewCardsRequest({ cards: this.cardsToSend });
return reviewCardsRequest({ cards: this.cardsToSend, isInterrupted: true });
}

get cardsToSend(): Array<{ id: number; outcome: ReviewOutcome }> {
Expand All @@ -142,6 +146,7 @@ export class ReviewStore {

return reviewCardsRequest({ cards: this.cardsToSend }).finally(
action(() => {
deckListStore.load();
this.isReviewSending = false;
}),
);
Expand Down
8 changes: 7 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@ export default defineConfig({
rewrite: (path) => path.replace(/^\/api/, ''),
},
}
}
},
// @ts-expect-error
test: {
coverage: {
reporter: ['text'],
},
},
})

0 comments on commit bba266d

Please sign in to comment.