Skip to content

Commit

Permalink
Log frozen cards
Browse files Browse the repository at this point in the history
  • Loading branch information
kubk committed Apr 9, 2024
1 parent df30b26 commit d7f8189
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ export const folderUpsertRequest = (body: AddFolderRequest) => {
};

export const deleteFolderRequest = (folderId: number) => {
return request<DeleteFolderResponse>(`/delete-folder?folder_id=${folderId}`, "POST");
return request<DeleteFolderResponse>(
`/delete-folder?folder_id=${folderId}`,
"POST",
);
};

export const decksMineRequest = () => {
Expand Down
5 changes: 3 additions & 2 deletions src/screens/freeze-cards/freeze-cards-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { screenStore } from "../../store/screen-store.ts";
import { hapticImpact } from "../../lib/telegram/haptics.ts";
import { showConfirm } from "../../lib/telegram/show-confirm.ts";
import { t } from "../../translations/t.ts";
import { formatFrozenCards } from "./translations.ts";

export class FreezeCardsStore {
isLoading = false;
Expand Down Expand Up @@ -85,10 +86,10 @@ export class FreezeCardsStore {
});
assert(this.freezeDays !== null, "freezeDays is null");
cardsFreezeRequest({ days: this.freezeDays })
.then(() => {
.then(({ frozenCards }) => {
screenStore.go({ type: "main" });
hapticImpact("heavy");
showAlert(t("freeze_success"));
showAlert(formatFrozenCards(frozenCards));
})
.catch((error) => {
reportHandledError("Failed to freeze cards", error);
Expand Down
48 changes: 48 additions & 0 deletions src/screens/freeze-cards/translations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
import { translator } from "../../translations/t.ts";

export const formatFrozenCards = (cards: number) => {
const language = translator.getLang();
switch (language) {
case "en": {
return cards === 1
? `1 card has been frozen`
: `${cards} have been frozen`;
}
case "ru": {
const rules = new Intl.PluralRules("ru-RU");
const result = rules.select(cards);
switch (result) {
case "one":
return `${cards} карточка заморожена`;
case "few":
return `${cards} карточки заморожены`;
case "many":
return `${cards} карточек заморожено`;
case "two":
default:
return `${cards} карточки заморожены`;
}
}
case "es": {
const rulesEs = new Intl.PluralRules("es-ES");
const resultEs = rulesEs.select(cards);
switch (resultEs) {
case "one":
return `${cards} tarjeta ha sido congelada`;
case "other":
default:
return `${cards} han sido congeladas`;
}
}
case "pt-br": {
const rulesPt = new Intl.PluralRules("pt-br");
const resultPt = rulesPt.select(cards);
switch (resultPt) {
case "one":
return `${cards} cartão foi congelado`;
case "other":
default:
return `${cards} foram congelados`;
}
}
}
};

export const formatDays = (days: number) => {
const language = translator.getLang();

Expand Down
10 changes: 2 additions & 8 deletions src/translations/t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ const en = {
validate_under_100: "Please enter a number less than 100",
freeze_confirm_freeze:
"Are you sure you want to freeze your cards? This action can't be undone.",
freeze_success: "All the cards have been frozen",
freeze_error: "Failed to freeze cards. Please try again later",
freeze_title: "Freeze cards",
freeze_how: "How it works",
Expand Down Expand Up @@ -432,7 +431,6 @@ const ru: Translation = {
freeze_rule_3: "Заморозка карточек необратима.",
freeze_rule_4:
"Если вы добавите карточку в период заморозки, она не будет затронута заморозкой.",
freeze_success: "Все карточки были заморожены",
validate_number: "Пожалуйста, введите корректное число",
validate_positive: "Пожалуйста, введите положительное число",
validate_under_100: "Пожалуйста, введите число меньше 100",
Expand Down Expand Up @@ -623,8 +621,7 @@ const es: Translation = {
share_deck_settings: "Compartir un mazo",
share_perpetual_link: "Compartir enlace perpetuo",
go_back: "Volver",
delete_folder_confirm:
"¿Quieres eliminar la carpeta?",
delete_folder_confirm: "¿Quieres eliminar la carpeta?",
user_stats_btn: "Estadísticas",
user_stats_page: "Mi estadística",
user_stats_remembered: "Tarjetas recordadas",
Expand Down Expand Up @@ -657,7 +654,6 @@ const es: Translation = {
freeze_rule_4:
"Si añades una tarjeta durante el período de congelación, no se verá afectada por la congelación.",
freeze_rule_3: "La congelación de tarjetas no se puede deshacer.",
freeze_success: "Todas las tarjetas han sido congeladas",
freeze_title: "Congelar tarjetas",
freeze_hint: "Posponer el estudio de las tarjetas",
};
Expand Down Expand Up @@ -846,8 +842,7 @@ const ptBr: Translation = {
share_one_time_link: "Compartilhar link de acesso único",
share_unused: "Não utilizado",
go_back: "Voltar",
delete_folder_confirm:
"Você quer deletar a pasta?",
delete_folder_confirm: "Você quer deletar a pasta?",
user_stats_btn: "Estatísticas",
user_stats_page: "Minha Estatística",
user_stats_remembered: "Cartões Memorizados",
Expand All @@ -862,7 +857,6 @@ const ptBr: Translation = {
user_stats_chart_min_expl: "Não conheço o cartão",
user_stats_chart_max_expl: "Conheço o cartão muito bem",
freeze_title: "Congelar cartões",
freeze_success: "Todos os cartões foram congelados",
freeze_rule_4:
"Se você adicionar um cartão durante o período de congelamento, ele não será afetado pelo congelamento.",
freeze_rule_3: "O congelamento de cartões é irreversível.",
Expand Down

0 comments on commit d7f8189

Please sign in to comment.