-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
308 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { EnumLike } from "./is-enum-valid.ts"; | ||
|
||
export function enumValues<E extends EnumLike>(enumObject: E): E[keyof E][] { | ||
return Object.keys(enumObject) | ||
.filter((key) => Number.isNaN(Number(key))) | ||
.map((key) => enumObject[key] as E[keyof E]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { enumValues } from "./enum-values.ts"; | ||
|
||
export type EnumLike = { [key: string]: number | string }; | ||
|
||
export function isEnumValid<T extends EnumLike>( | ||
param: unknown, | ||
enumObject: T, | ||
): param is T[keyof T] { | ||
return enumValues(enumObject).includes(param as T[keyof T]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
export enum SpeakLanguageEnum { | ||
AmericanEnglish = "en-US", | ||
Italian = "it-IT", | ||
Swedish = "sv-SE", | ||
CanadianFrench = "fr-CA", | ||
Malay = "ms-MY", | ||
German = "de-DE", | ||
BritishEnglish = "en-GB", | ||
Hebrew = "he-IL", | ||
AustralianEnglish = "en-AU", | ||
Indonesian = "id-ID", | ||
French = "fr-FR", | ||
Bulgarian = "bg-BG", | ||
Spanish = "es-ES", | ||
MexicanSpanish = "es-MX", | ||
Finnish = "fi-FI", | ||
BrazilianPortuguese = "pt-BR", | ||
BelgianDutch = "nl-BE", | ||
Japanese = "ja-JP", | ||
Romanian = "ro-RO", | ||
Portuguese = "pt-PT", | ||
Thai = "th-TH", | ||
Croatian = "hr-HR", | ||
Slovak = "sk-SK", | ||
Hindi = "hi-IN", | ||
Ukrainian = "uk-UA", | ||
MainlandChinaChinese = "zh-CN", | ||
Vietnamese = "vi-VN", | ||
ModernStandardArabic = "ar-001", | ||
TaiwaneseChinese = "zh-TW", | ||
Greek = "el-GR", | ||
Russian = "ru-RU", | ||
Danish = "da-DK", | ||
HongKongChinese = "zh-HK", | ||
Hungarian = "hu-HU", | ||
Dutch = "nl-NL", | ||
Turkish = "tr-TR", | ||
Korean = "ko-KR", | ||
Polish = "pl-PL", | ||
Czech = "cs-CZ", | ||
} | ||
|
||
export const speak = (text: string, language: SpeakLanguageEnum) => { | ||
const utterance = new SpeechSynthesisUtterance(text); | ||
utterance.lang = language; | ||
|
||
window.speechSynthesis.speak(utterance); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { makeAutoObservable } from "mobx"; | ||
import { assert } from "../lib/typescript/assert.ts"; | ||
import { DeckCardDbType } from "../../functions/db/deck/decks-with-cards-schema.ts"; | ||
import { DeckWithCardsWithReviewType } from "./deck-list-store.ts"; | ||
import { speak, SpeakLanguageEnum } from "../lib/voice-playback/speak.ts"; | ||
import { isEnumValid } from "../lib/typescript/is-enum-valid.ts"; | ||
|
||
export enum CardState { | ||
Remember = "remember", | ||
Forget = "forget", | ||
} | ||
|
||
export enum DeckSpeakField { | ||
Front = "front", | ||
Back = "back", | ||
} | ||
|
||
export class CardUnderReviewStore { | ||
id: number; | ||
front: string; | ||
back: string; | ||
example: string | null = null; | ||
deckName?: string; | ||
deckSpeakLocale: string | null = null; | ||
deckSpeakField: string | null = null; | ||
|
||
isOpened = false; | ||
state?: CardState; | ||
|
||
constructor(card: DeckCardDbType, deck: DeckWithCardsWithReviewType) { | ||
this.id = card.id; | ||
this.front = card.front; | ||
this.back = card.back; | ||
this.example = card.example; | ||
this.deckName = deck.name; | ||
this.deckSpeakLocale = deck.speak_locale; | ||
this.deckSpeakField = deck.speak_field; | ||
|
||
makeAutoObservable(this, {}, { autoBind: true }); | ||
} | ||
|
||
open() { | ||
this.isOpened = true; | ||
} | ||
|
||
close() { | ||
this.isOpened = false; | ||
} | ||
|
||
changeState(state: CardState) { | ||
assert(this.isOpened, "The card should be opened before changing state"); | ||
this.state = state; | ||
} | ||
|
||
speak() { | ||
if (!this.deckSpeakLocale || !this.deckSpeakField) { | ||
return; | ||
} | ||
if ( | ||
!isEnumValid(this.deckSpeakField, DeckSpeakField) || | ||
!isEnumValid(this.deckSpeakLocale, SpeakLanguageEnum) | ||
) { | ||
return; | ||
} | ||
|
||
speak(this[this.deckSpeakField], this.deckSpeakLocale); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.