fix: unify activity labels and Russian plurals

This commit is contained in:
ik
2026-09-06 13:31:44 +07:00
parent a4b51027e2
commit 366ff83a60
11 changed files with 72 additions and 27 deletions
+2 -6
View File
@@ -12,6 +12,8 @@ export type DictionaryItem = { id: string; slug: string; name_ru: string };
export type OfficialRecord = { id: string; fish: string; weight_g: number; waterbody: string; bait: string | null; player_name: string | null; record_date: string | null; category: string | null; region: string | null; source_url: string | null };
export type ImportRun = { id: string; started_at: string; finished_at: string | null; status: string; source_url: string; rows_seen: number; rows_created: number; rows_updated: number; error_summary: string | null };
export { activityLevel, ago, kg, plural } from "./presentation";
const base = process.env.API_INTERNAL_URL || import.meta.env.API_INTERNAL_URL || "http://localhost:8000";
export async function api<T>(path: string): Promise<T> {
@@ -19,9 +21,3 @@ export async function api<T>(path: string): Promise<T> {
if (!response.ok) throw new Error(`API ${response.status}`);
return response.json() as Promise<T>;
}
export function kg(grams: number) { return `${(grams / 1000).toFixed(2)} кг`; }
export function ago(value: string) {
const minutes = Math.max(0, Math.round((Date.now() - new Date(value).getTime()) / 60000));
return minutes < 60 ? `${minutes} мин назад` : `${Math.floor(minutes / 60)} ч назад`;
}
+22
View File
@@ -0,0 +1,22 @@
export function kg(grams: number) { return `${(grams / 1000).toFixed(2)} кг`; }
export function plural(number: number, forms: readonly [string, string, string]) {
const absolute = Math.abs(number) % 100;
const last = absolute % 10;
if (absolute > 10 && absolute < 20) return forms[2];
if (last === 1) return forms[0];
if (last >= 2 && last <= 4) return forms[1];
return forms[2];
}
export function activityLevel(score: number) {
if (score >= 80) return { short: "Очень высокий", description: "Очень высокая активность" };
if (score >= 60) return { short: "Высокий", description: "Высокая активность" };
if (score >= 40) return { short: "Средний", description: "Средняя активность" };
return { short: "Низкий", description: "Низкая активность" };
}
export function ago(value: string) {
const minutes = Math.max(0, Math.round((Date.now() - new Date(value).getTime()) / 60000));
return minutes < 60 ? `${minutes} мин назад` : `${Math.floor(minutes / 60)} ч назад`;
}