diff --git a/src/screens/deck-form/card-form.tsx b/src/screens/deck-form/card-form.tsx index b467c239..3d6182a0 100644 --- a/src/screens/deck-form/card-form.tsx +++ b/src/screens/deck-form/card-form.tsx @@ -9,7 +9,7 @@ import { CardFormView } from "./card-form-view.tsx"; export const CardForm = observer(() => { const deckFormStore = useDeckFormStore(); const cardForm = deckFormStore.cardForm; - assert(cardForm); + assert(cardForm, "Card should not be empty before editing"); useMainButton("Save", () => { deckFormStore.saveCardForm(); diff --git a/src/screens/deck-list/main-screen.tsx b/src/screens/deck-list/main-screen.tsx index 0e2b83c7..f466d8b6 100644 --- a/src/screens/deck-list/main-screen.tsx +++ b/src/screens/deck-list/main-screen.tsx @@ -130,7 +130,7 @@ export const MainScreen = observer(() => { icon={"mdi-call-made"} onClick={() => { const channelLink = import.meta.env.VITE_CHANNEL_LINK; - assert(channelLink); + assert(channelLink, "Channel link env variable is empty"); WebApp.openTelegramLink(channelLink); }} diff --git a/src/screens/deck-review/deck-preview.tsx b/src/screens/deck-review/deck-preview.tsx index 9d01ea20..c11fda74 100644 --- a/src/screens/deck-review/deck-preview.tsx +++ b/src/screens/deck-review/deck-preview.tsx @@ -15,7 +15,7 @@ import { useMainButton } from "../../lib/telegram/use-main-button.tsx"; export const DeckPreview = observer(() => { const reviewStore = useReviewStore(); const deck = deckListStore.selectedDeck; - assert(deck); + assert(deck, "Deck should not be empty before preview"); useBackButton(() => { screenStore.navigateToMain(); diff --git a/src/screens/deck-review/share-deck-button.tsx b/src/screens/deck-review/share-deck-button.tsx index 5dcbfacb..8b636ec6 100644 --- a/src/screens/deck-review/share-deck-button.tsx +++ b/src/screens/deck-review/share-deck-button.tsx @@ -20,7 +20,7 @@ export const ShareDeckButton = (props: Props) => { const onClick = async () => { if (shareId) { const botUrl = import.meta.env.VITE_BOT_APP_URL; - assert(botUrl); + assert(botUrl, "Bot URL is not set"); const botUrlWithDeckId = `${trimEnd(botUrl, "/")}?startapp=${shareId}`; const shareUrl = `https://t.me/share/url?text=&url=${botUrlWithDeckId}`; WebApp.openTelegramLink(shareUrl); diff --git a/src/store/card-form-store.ts b/src/store/card-form-store.ts index da34148e..e69ad815 100644 --- a/src/store/card-form-store.ts +++ b/src/store/card-form-store.ts @@ -27,7 +27,7 @@ export class CardFormStore { } changeState(state: CardState) { - assert(this.isOpened); + assert(this.isOpened, "The card should be opened before changing state"); this.state = state; } } diff --git a/src/store/deck-form-store-context.tsx b/src/store/deck-form-store-context.tsx index 9d1d0d9a..44d21038 100644 --- a/src/store/deck-form-store-context.tsx +++ b/src/store/deck-form-store-context.tsx @@ -14,6 +14,6 @@ export const DeckFormStoreProvider = (props: { children: ReactNode }) => { export const useDeckFormStore = () => { const store = useContext(Context); - assert(store); + assert(store, "DeckFormStoreProvider not found"); return store; }; diff --git a/src/store/deck-form-store.ts b/src/store/deck-form-store.ts index 910a3fdf..b410eac5 100644 --- a/src/store/deck-form-store.ts +++ b/src/store/deck-form-store.ts @@ -55,7 +55,7 @@ export class DeckFormStore { const deck = deckListStore.myDecks.find( (myDeck) => myDeck.id === screenStore.deckFormId, ); - assert(deck); + assert(deck, "Deck not found in deckListStore"); this.form = { title: createDeckTitleField(deck.name), description: new TextField(deck.description ?? ""), @@ -81,7 +81,7 @@ export class DeckFormStore { } openNewCardForm() { - assert(this.form); + assert(this.form, 'openNewCardForm: form is empty'); this.cardFormIndex = this.form.cards.length; this.form.cards.push({ front: createCardSideField(""), @@ -101,7 +101,7 @@ export class DeckFormStore { } async onCardBack() { - assert(this.cardForm); + assert(this.cardForm, 'onCardBack: cardForm is empty'); if (isFormEmpty(this.cardForm)) { this.quitCardForm(); return; @@ -114,7 +114,7 @@ export class DeckFormStore { } async onDeckBack() { - assert(this.form); + assert(this.form, 'onDeckBack: form is empty'); if (isFormEmpty(this.form) || !isFormTouched(this.form)) { screenStore.navigateToMain(); return; @@ -127,14 +127,13 @@ export class DeckFormStore { } onDeckSave() { - assert(this.form); + assert(this.form, 'onDeckSave: form is empty'); if (this.form.cards.length === 0) { showAlert("Please add at least 1 card to create a deck"); return; } - assert(this.form); formTouchAll(this.form); if (!isFormValid(this.form)) { return; @@ -162,8 +161,8 @@ export class DeckFormStore { } quitCardForm() { - assert(this.cardFormIndex !== undefined); - assert(this.form); + 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; } diff --git a/src/store/deck-list-store.ts b/src/store/deck-list-store.ts index fe843151..ec3d5fb9 100644 --- a/src/store/deck-list-store.ts +++ b/src/store/deck-list-store.ts @@ -88,7 +88,7 @@ export class DeckListStore { get canReview() { const deck = this.selectedDeck; - assert(deck); + assert(deck, "canReview requires a deck to be selected"); return ( deck.cardsToReview.length > 0 || screenStore.screen === Screen.DeckPublic @@ -100,7 +100,7 @@ export class DeckListStore { return; } - assert(deckListStore.selectedDeck); + assert(deckListStore.selectedDeck, "No selected deck for review"); if (screenStore.screen === Screen.DeckPublic) { deckListStore.addDeckToMine(deckListStore.selectedDeck.id); } diff --git a/src/store/quick-add-card-form-store.ts b/src/store/quick-add-card-form-store.ts index 9d83f33e..f7e4336b 100644 --- a/src/store/quick-add-card-form-store.ts +++ b/src/store/quick-add-card-form-store.ts @@ -27,7 +27,7 @@ export class QuickAddCardFormStore { return; } - assert(screenStore.cardQuickAddDeckId); + assert(screenStore.cardQuickAddDeckId, "cardQuickAddDeckId should not be empty"); this.isSending = true; diff --git a/src/store/review-store-context.tsx b/src/store/review-store-context.tsx index 47d9035a..88c944ac 100644 --- a/src/store/review-store-context.tsx +++ b/src/store/review-store-context.tsx @@ -14,6 +14,6 @@ export const ReviewStoreProvider = (props: { children: ReactNode }) => { export const useReviewStore = () => { const store = useContext(Context); - assert(store); + assert(store, "ReviewStoreProvider not found"); return store; }; diff --git a/src/store/review-store.ts b/src/store/review-store.ts index 05f9f7e5..990f6cdc 100644 --- a/src/store/review-store.ts +++ b/src/store/review-store.ts @@ -64,19 +64,19 @@ export class ReviewStore { open() { const currentCard = this.currentCard; - assert(currentCard); + assert(currentCard, "Current card should not be empty"); currentCard.open(); } changeState(cardState: CardState) { const currentCard = this.currentCard; - assert(currentCard); + assert(currentCard, "currentCard should not be null while changing state in review"); currentCard.changeState(cardState); const currentCardIdx = this.cardsToReview.findIndex( (card) => card.id === currentCard.id, ); - assert(currentCardIdx !== -1); + assert(currentCardIdx !== -1, "currentCardIdx is empty"); this.cardsToReview.splice(currentCardIdx, 1); if (currentCard.state === CardState.Forget) { if (!this.result.forgotIds.includes(currentCard.id)) {