I18n: tlumaczenie nazw slownikowych w panelu admina (pole 'Nazwa (EN)' w katalogach cwiczen/sprzetu/stref + podglad nazwy EN i render wg jezyka, lista/postepy/historia/lancuch priorytetow)
This commit is contained in:
@@ -43,6 +43,7 @@ export interface User {
|
||||
export interface FocusArea {
|
||||
id: string;
|
||||
name: string;
|
||||
nameEn?: string | null;
|
||||
muscle: string;
|
||||
description: string | null;
|
||||
setsMin: number | null;
|
||||
@@ -56,7 +57,8 @@ export interface FocusArea {
|
||||
export interface FocusChainEntry {
|
||||
muscle: string;
|
||||
name: string;
|
||||
exercises: { id: string; name: string }[];
|
||||
nameEn?: string | null;
|
||||
exercises: { id: string; name: string; nameEn?: string | null }[];
|
||||
}
|
||||
|
||||
export interface FocusChain {
|
||||
@@ -89,6 +91,7 @@ export interface EquipmentSpec {
|
||||
export interface Equipment {
|
||||
id: string;
|
||||
name: string;
|
||||
nameEn?: string | null;
|
||||
kind: EquipmentKind;
|
||||
spec: EquipmentSpec | null;
|
||||
description: string | null;
|
||||
@@ -126,6 +129,7 @@ export interface Exercise {
|
||||
id: string;
|
||||
slug: string;
|
||||
name: string;
|
||||
nameEn?: string | null;
|
||||
primaryMuscle: string;
|
||||
secondaryMuscles: string[];
|
||||
equipment: Equipment[];
|
||||
@@ -297,6 +301,7 @@ export interface ExerciseComment {
|
||||
export interface HistoryExercise {
|
||||
id: string;
|
||||
name: string;
|
||||
nameEn?: string | null;
|
||||
muscle: string;
|
||||
isExtra: boolean;
|
||||
comments: ExerciseComment[];
|
||||
@@ -328,6 +333,7 @@ export interface ExerciseProgressPoint {
|
||||
export interface ExerciseProgress {
|
||||
exerciseId: string;
|
||||
name: string;
|
||||
nameEn?: string | null;
|
||||
muscle: string;
|
||||
points: ExerciseProgressPoint[];
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ChevronDown, ChevronUp, TrendingDown, TrendingUp } from 'lucide-react';
|
||||
import {
|
||||
Bar,
|
||||
@@ -13,6 +14,7 @@ import {
|
||||
} from 'recharts';
|
||||
import type { ExerciseProgress } from '../api/types';
|
||||
import { fmtDate, fmtVolume } from '../lib/format';
|
||||
import { localizedName } from '../lib/localizedName';
|
||||
import { MUSCLE_NAMES } from '../lib/labels';
|
||||
import { Badge, Tabs } from './ui';
|
||||
|
||||
@@ -30,6 +32,7 @@ const TOOLTIP_STYLE = {
|
||||
* Współdzielone z detalem podopiecznego (spójnie).
|
||||
*/
|
||||
export default function ExerciseProgressCards({ exercises }: { exercises: ExerciseProgress[] }) {
|
||||
const { i18n } = useTranslation();
|
||||
const [openId, setOpenId] = useState<string | null>(null);
|
||||
// aktywna zakładka per ćwiczenie (domyślnie 1RM)
|
||||
const [tabs, setTabs] = useState<Record<string, 'onerm' | 'volume'>>({});
|
||||
@@ -64,7 +67,9 @@ export default function ExerciseProgressCards({ exercises }: { exercises: Exerci
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<strong className="truncate text-[0.95rem]">{ex.name}</strong>
|
||||
<strong className="truncate text-[0.95rem]">
|
||||
{localizedName(ex, i18n.language)}
|
||||
</strong>
|
||||
{isPr && <Badge color="green">PR</Badge>}
|
||||
</div>
|
||||
<div className="text-[0.8125rem] text-dim">
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ChevronDown, ChevronUp, MessageSquare } from 'lucide-react';
|
||||
import type { HistorySession } from '../api/types';
|
||||
import { fmtDate, fmtDuration, fmtVolume } from '../lib/format';
|
||||
import { localizedName } from '../lib/localizedName';
|
||||
import { MUSCLE_NAMES, SESSION_STATUS } from '../lib/labels';
|
||||
import { Badge } from './ui';
|
||||
|
||||
@@ -16,6 +18,7 @@ interface HistoryTableProps {
|
||||
* Port odpowiednika z aplikacji (`app/src/components/HistoryTable`) bez dodawania komentarzy.
|
||||
*/
|
||||
export default function HistoryTable({ sessions, initialOpenSessionId }: HistoryTableProps) {
|
||||
const { i18n } = useTranslation();
|
||||
const [openSession, setOpenSession] = useState<string | null>(initialOpenSessionId ?? null);
|
||||
|
||||
return (
|
||||
@@ -103,7 +106,9 @@ export default function HistoryTable({ sessions, initialOpenSessionId }: History
|
||||
<div key={ex.id} className="py-3">
|
||||
<div className="mb-2 flex items-center justify-between gap-3">
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<strong className="text-[0.95rem]">{ex.name}</strong>
|
||||
<strong className="text-[0.95rem]">
|
||||
{localizedName(ex, i18n.language)}
|
||||
</strong>
|
||||
{ex.isExtra && <Badge color="yellow">dodane</Badge>}
|
||||
</div>
|
||||
<span className="text-dim text-[0.875rem]">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Equipment, EquipmentKind, EquipmentSpec } from '../api/types';
|
||||
import { localizedName } from './localizedName';
|
||||
|
||||
export const EQUIPMENT_KIND_LABELS: Record<EquipmentKind, string> = {
|
||||
DUMBBELL: 'Hantle',
|
||||
@@ -125,12 +126,16 @@ export function effectiveSpec(item: {
|
||||
}
|
||||
|
||||
/** Chip label for a gym equipment instance: "Hantle ×2 · 2.5–25 kg". */
|
||||
export function formatGymEquipment(item: {
|
||||
quantity: number;
|
||||
spec?: EquipmentSpec | null;
|
||||
equipment: Equipment;
|
||||
}): string {
|
||||
export function formatGymEquipment(
|
||||
item: {
|
||||
quantity: number;
|
||||
spec?: EquipmentSpec | null;
|
||||
equipment: Equipment;
|
||||
},
|
||||
lang = 'pl',
|
||||
): string {
|
||||
const spec = formatEquipmentSpec(effectiveSpec(item));
|
||||
const qty = item.quantity > 1 ? ` ×${item.quantity}` : '';
|
||||
return spec ? `${item.equipment.name}${qty} · ${spec}` : `${item.equipment.name}${qty}`;
|
||||
const name = localizedName(item.equipment, lang);
|
||||
return spec ? `${name}${qty} · ${spec}` : `${name}${qty}`;
|
||||
}
|
||||
|
||||
16
admin/src/lib/localizedName.ts
Normal file
16
admin/src/lib/localizedName.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Encje slownikowe (cwiczenie, sprzet, strefa) — tlumaczenie nazwy z fallbackiem PL.
|
||||
* `lang` to aktualny jezyk i18n ('pl' | 'en'); dla 'pl' lub braku nameEn zwroca `name`.
|
||||
*/
|
||||
export interface LocalizableName {
|
||||
name: string;
|
||||
nameEn?: string | null;
|
||||
}
|
||||
|
||||
export function localizedName<T extends LocalizableName>(
|
||||
entity: T | null | undefined,
|
||||
lang: string,
|
||||
): string {
|
||||
if (!entity) return '';
|
||||
return lang === 'en' && entity.nameEn ? entity.nameEn : entity.name;
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { Pencil, Plus, Trash2, Wrench } from 'lucide-react';
|
||||
import { api } from '../../api/client';
|
||||
import type { Equipment, EquipmentKind } from '../../api/types';
|
||||
import { EQUIPMENT_KIND_LABELS, formatEquipmentSpec } from '../../lib/equipment';
|
||||
import { localizedName } from '../../lib/localizedName';
|
||||
import { useTopbar } from '../../topbar';
|
||||
import { useListSearch } from '../../store/list-search';
|
||||
import {
|
||||
@@ -23,6 +25,7 @@ import {
|
||||
|
||||
interface FormState {
|
||||
name: string;
|
||||
nameEn: string;
|
||||
description: string;
|
||||
kind: EquipmentKind;
|
||||
minKg: string;
|
||||
@@ -34,6 +37,7 @@ interface FormState {
|
||||
|
||||
const EMPTY: FormState = {
|
||||
name: '',
|
||||
nameEn: '',
|
||||
description: '',
|
||||
kind: 'OTHER',
|
||||
minKg: '',
|
||||
@@ -52,6 +56,7 @@ function toFormState(item: Equipment): FormState {
|
||||
const spec = item.spec ?? {};
|
||||
return {
|
||||
name: item.name,
|
||||
nameEn: item.nameEn ?? '',
|
||||
description: item.description ?? '',
|
||||
kind: item.kind,
|
||||
minKg: spec.minKg != null ? String(spec.minKg) : '',
|
||||
@@ -70,6 +75,7 @@ function parseNum(value: string): number | undefined {
|
||||
|
||||
export default function EquipmentCatalog() {
|
||||
const qc = useQueryClient();
|
||||
const { i18n } = useTranslation();
|
||||
const { data, isLoading, error } = useQuery({
|
||||
queryKey: ['equipment'],
|
||||
queryFn: () => api<{ equipment: Equipment[] }>('/admin/equipment'),
|
||||
@@ -80,7 +86,7 @@ export default function EquipmentCatalog() {
|
||||
|
||||
const filtered = query
|
||||
? items.filter((e) =>
|
||||
[e.name, e.description, EQUIPMENT_KIND_LABELS[e.kind]]
|
||||
[e.name, e.nameEn, e.description, EQUIPMENT_KIND_LABELS[e.kind]]
|
||||
.filter(Boolean)
|
||||
.some((s) => s!.toLowerCase().includes(query.toLowerCase())),
|
||||
)
|
||||
@@ -123,6 +129,7 @@ export default function EquipmentCatalog() {
|
||||
}
|
||||
const body = {
|
||||
name: form.name,
|
||||
nameEn: form.nameEn.trim() || null,
|
||||
description: form.description || null,
|
||||
kind,
|
||||
spec,
|
||||
@@ -261,11 +268,14 @@ export default function EquipmentCatalog() {
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<div className="text-[1.05rem] font-semibold">
|
||||
{item.name}
|
||||
{localizedName(item, i18n.language)}
|
||||
<span className="ml-2 text-[0.875rem] text-dim font-normal">
|
||||
{EQUIPMENT_KIND_LABELS[item.kind]}
|
||||
</span>
|
||||
</div>
|
||||
{item.nameEn && (
|
||||
<div className="text-[0.8rem] text-dim italic">EN: {item.nameEn}</div>
|
||||
)}
|
||||
{formatEquipmentSpec(item.spec) && (
|
||||
<div className="mt-0.5 text-[0.875rem] text-dim">
|
||||
{formatEquipmentSpec(item.spec)}
|
||||
@@ -283,7 +293,7 @@ export default function EquipmentCatalog() {
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => openEdit(item)}
|
||||
aria-label={`Edytuj ${item.name}`}
|
||||
aria-label={`Edytuj ${localizedName(item, i18n.language)}`}
|
||||
>
|
||||
<Pencil className="w-4 h-4" />
|
||||
</Button>
|
||||
@@ -292,7 +302,7 @@ export default function EquipmentCatalog() {
|
||||
size="sm"
|
||||
className="text-danger hover:text-danger"
|
||||
onClick={() => setDeleting(item)}
|
||||
aria-label={`Usuń ${item.name}`}
|
||||
aria-label={`Usuń ${localizedName(item, i18n.language)}`}
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</Button>
|
||||
@@ -329,6 +339,13 @@ export default function EquipmentCatalog() {
|
||||
placeholder="np. Sztanga"
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Nazwa (EN)">
|
||||
<Input
|
||||
value={form.nameEn}
|
||||
onChange={(e) => setForm((f) => ({ ...f, nameEn: e.target.value }))}
|
||||
placeholder="e.g. Barbell"
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Rodzaj">
|
||||
<Select
|
||||
value={form.kind}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { Pencil, Plus, Trash2, Dumbbell } from 'lucide-react';
|
||||
import { api } from '../../api/client';
|
||||
import type { Equipment, Exercise, FocusArea } from '../../api/types';
|
||||
import { localizedName } from '../../lib/localizedName';
|
||||
import { useTopbar } from '../../topbar';
|
||||
import { useListSearch } from '../../store/list-search';
|
||||
import {
|
||||
@@ -117,6 +119,7 @@ function detectType(ex: Exercise): ExerciseType {
|
||||
|
||||
interface FormState {
|
||||
name: string;
|
||||
nameEn: string;
|
||||
primaryMuscle: string;
|
||||
secondaryMuscles: string[];
|
||||
description: string;
|
||||
@@ -129,6 +132,7 @@ interface FormState {
|
||||
|
||||
const EMPTY: FormState = {
|
||||
name: '',
|
||||
nameEn: '',
|
||||
primaryMuscle: '',
|
||||
secondaryMuscles: [],
|
||||
description: '',
|
||||
@@ -157,6 +161,7 @@ function muscleOptions(
|
||||
|
||||
export default function Exercises() {
|
||||
const qc = useQueryClient();
|
||||
const { i18n } = useTranslation();
|
||||
const { data, isLoading, error } = useQuery({
|
||||
queryKey: ['exercises'],
|
||||
queryFn: () => api<{ exercises: Exercise[] }>('/admin/exercises'),
|
||||
@@ -178,7 +183,7 @@ export default function Exercises() {
|
||||
|
||||
const filtered = query
|
||||
? exercises.filter((ex) =>
|
||||
[ex.name, ex.primaryMuscle, ex.description, ...ex.secondaryMuscles]
|
||||
[ex.name, ex.nameEn, ex.primaryMuscle, ex.description, ...ex.secondaryMuscles]
|
||||
.filter(Boolean)
|
||||
.some((s) => s!.toLowerCase().includes(query.toLowerCase())),
|
||||
)
|
||||
@@ -211,6 +216,7 @@ export default function Exercises() {
|
||||
const flags = currentFlags();
|
||||
return {
|
||||
name: form.name,
|
||||
nameEn: form.nameEn.trim() || null,
|
||||
primaryMuscle: form.primaryMuscle,
|
||||
secondaryMuscles: form.secondaryMuscles,
|
||||
description: form.description || null,
|
||||
@@ -277,6 +283,7 @@ export default function Exercises() {
|
||||
setEditing(ex);
|
||||
setForm({
|
||||
name: ex.name,
|
||||
nameEn: ex.nameEn ?? '',
|
||||
primaryMuscle: ex.primaryMuscle,
|
||||
secondaryMuscles: ex.secondaryMuscles,
|
||||
description: ex.description ?? '',
|
||||
@@ -324,13 +331,14 @@ export default function Exercises() {
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<div className="text-[1.05rem] font-semibold">
|
||||
{ex.name}
|
||||
{localizedName(ex, i18n.language)}
|
||||
{SOURCE_LABELS[ex.source] && (
|
||||
<span className="ml-2 text-[0.875rem] text-dim font-normal">
|
||||
{SOURCE_LABELS[ex.source]}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{ex.nameEn && <div className="text-[0.8rem] text-dim italic">EN: {ex.nameEn}</div>}
|
||||
<div className="mt-1 flex flex-wrap items-center gap-1.5">
|
||||
<Badge color="blue">{ex.primaryMuscle}</Badge>
|
||||
{ex.secondaryMuscles.map((m) => (
|
||||
@@ -355,7 +363,7 @@ export default function Exercises() {
|
||||
) : (
|
||||
ex.equipment.map((e) => (
|
||||
<Badge key={e.id} color="gray">
|
||||
{e.name}
|
||||
{localizedName(e, i18n.language)}
|
||||
</Badge>
|
||||
))
|
||||
)}
|
||||
@@ -366,7 +374,7 @@ export default function Exercises() {
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => openEdit(ex)}
|
||||
aria-label={`Edytuj ${ex.name}`}
|
||||
aria-label={`Edytuj ${localizedName(ex, i18n.language)}`}
|
||||
>
|
||||
<Pencil className="w-4 h-4" />
|
||||
</Button>
|
||||
@@ -375,7 +383,7 @@ export default function Exercises() {
|
||||
size="sm"
|
||||
className="text-danger hover:text-danger"
|
||||
onClick={() => setDeleting(ex)}
|
||||
aria-label={`Usuń ${ex.name}`}
|
||||
aria-label={`Usuń ${localizedName(ex, i18n.language)}`}
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</Button>
|
||||
@@ -413,6 +421,13 @@ export default function Exercises() {
|
||||
placeholder="np. Wyciskanie sztangi leżąc"
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Nazwa (EN)">
|
||||
<Input
|
||||
value={form.nameEn}
|
||||
onChange={(e) => setForm((f) => ({ ...f, nameEn: e.target.value }))}
|
||||
placeholder="e.g. Barbell bench press"
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Główny mięsień">
|
||||
<Select
|
||||
value={form.primaryMuscle}
|
||||
@@ -510,7 +525,7 @@ export default function Exercises() {
|
||||
onChange={() => toggleEquipment(e.id)}
|
||||
className="accent-[var(--accent)]"
|
||||
/>
|
||||
<span className="text-[0.875rem]">{e.name}</span>
|
||||
<span className="text-[0.875rem]">{localizedName(e, i18n.language)}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { Pencil, Plus, Trash2, Target } from 'lucide-react';
|
||||
import { api } from '../../api/client';
|
||||
import type { FocusArea } from '../../api/types';
|
||||
import { localizedName } from '../../lib/localizedName';
|
||||
import { useTopbar } from '../../topbar';
|
||||
import { useListSearch } from '../../store/list-search';
|
||||
import {
|
||||
@@ -22,16 +24,25 @@ import {
|
||||
|
||||
interface FormState {
|
||||
name: string;
|
||||
nameEn: string;
|
||||
muscle: string;
|
||||
description: string;
|
||||
setsMin: string;
|
||||
setsMax: string;
|
||||
}
|
||||
|
||||
const EMPTY: FormState = { name: '', muscle: '', description: '', setsMin: '', setsMax: '' };
|
||||
const EMPTY: FormState = {
|
||||
name: '',
|
||||
nameEn: '',
|
||||
muscle: '',
|
||||
description: '',
|
||||
setsMin: '',
|
||||
setsMax: '',
|
||||
};
|
||||
|
||||
export default function FocusAreas() {
|
||||
const qc = useQueryClient();
|
||||
const { i18n } = useTranslation();
|
||||
const { data, isLoading, error } = useQuery({
|
||||
queryKey: ['focus-areas'],
|
||||
queryFn: () => api<{ focusAreas: FocusArea[] }>('/admin/focus-areas'),
|
||||
@@ -42,7 +53,7 @@ export default function FocusAreas() {
|
||||
|
||||
const filtered = query
|
||||
? areas.filter((a) =>
|
||||
[a.name, a.muscle, a.description]
|
||||
[a.name, a.nameEn, a.muscle, a.description]
|
||||
.filter(Boolean)
|
||||
.some((s) => s!.toLowerCase().includes(query.toLowerCase())),
|
||||
)
|
||||
@@ -64,6 +75,7 @@ export default function FocusAreas() {
|
||||
mutationFn: async () => {
|
||||
const body = {
|
||||
name: form.name,
|
||||
nameEn: form.nameEn.trim() || null,
|
||||
muscle: form.muscle,
|
||||
description: form.description || null,
|
||||
setsMin: form.setsMin ? parseInt(form.setsMin) : null,
|
||||
@@ -127,6 +139,7 @@ export default function FocusAreas() {
|
||||
setEditing(area);
|
||||
setForm({
|
||||
name: area.name,
|
||||
nameEn: area.nameEn ?? '',
|
||||
muscle: area.muscle,
|
||||
description: area.description ?? '',
|
||||
setsMin: area.setsMin != null ? String(area.setsMin) : '',
|
||||
@@ -151,7 +164,10 @@ export default function FocusAreas() {
|
||||
<Card key={a.id} className="mb-0">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<div className="text-[1.05rem] font-semibold">{a.name}</div>
|
||||
<div className="text-[1.05rem] font-semibold">
|
||||
{localizedName(a, i18n.language)}
|
||||
</div>
|
||||
{a.nameEn && <div className="text-[0.8rem] text-dim italic">EN: {a.nameEn}</div>}
|
||||
<div className="mt-0.5 flex items-center gap-1.5">
|
||||
<Badge color="blue">{a.muscle}</Badge>
|
||||
{a.setsMin != null && a.setsMax != null && (
|
||||
@@ -169,7 +185,7 @@ export default function FocusAreas() {
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => openEdit(a)}
|
||||
aria-label={`Edytuj ${a.name}`}
|
||||
aria-label={`Edytuj ${localizedName(a, i18n.language)}`}
|
||||
>
|
||||
<Pencil className="w-4 h-4" />
|
||||
</Button>
|
||||
@@ -178,7 +194,7 @@ export default function FocusAreas() {
|
||||
size="sm"
|
||||
className="text-danger hover:text-danger"
|
||||
onClick={() => setDeleting(a)}
|
||||
aria-label={`Usuń ${a.name}`}
|
||||
aria-label={`Usuń ${localizedName(a, i18n.language)}`}
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</Button>
|
||||
@@ -216,6 +232,13 @@ export default function FocusAreas() {
|
||||
placeholder="np. Klatka piersiowa"
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Nazwa (EN)">
|
||||
<Input
|
||||
value={form.nameEn}
|
||||
onChange={(e) => setForm((f) => ({ ...f, nameEn: e.target.value }))}
|
||||
placeholder="e.g. Chest"
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Klucz mięśnia">
|
||||
<Input
|
||||
value={form.muscle}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useState } from 'react';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import {
|
||||
Crown,
|
||||
@@ -41,6 +42,7 @@ import {
|
||||
specFromFields,
|
||||
type SpecFields,
|
||||
} from '../../lib/equipment';
|
||||
import { localizedName } from '../../lib/localizedName';
|
||||
import {
|
||||
BackButton,
|
||||
Button,
|
||||
@@ -124,6 +126,7 @@ function GalleryMosaic({ gym }: { gym: Gym }) {
|
||||
|
||||
/* Kafle urządzeń (odczyt) — jak w apce; zarządzanie w modalu z grupy „Urządzenia”. */
|
||||
function EquipmentTiles({ gym }: { gym: Gym }) {
|
||||
const { i18n } = useTranslation();
|
||||
if (gym.equipment.length === 0) {
|
||||
return <p className="text-[0.875rem] text-dim">Brak urządzeń.</p>;
|
||||
}
|
||||
@@ -134,7 +137,7 @@ function EquipmentTiles({ gym }: { gym: Gym }) {
|
||||
key={e.id}
|
||||
className="flex items-center justify-between gap-2 rounded-[10px] border border-line bg-card/50 px-3 py-2.5 text-[0.85rem] font-semibold"
|
||||
>
|
||||
<span className="min-w-0 truncate">{formatGymEquipment(e)}</span>
|
||||
<span className="min-w-0 truncate">{formatGymEquipment(e, i18n.language)}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@@ -1013,6 +1016,7 @@ function AddSpecFields({
|
||||
}
|
||||
|
||||
function EquipmentSection({ gym, onChanged }: { gym: Gym; onChanged: () => void }) {
|
||||
const { i18n } = useTranslation();
|
||||
const { data: eqData, isLoading } = useQuery({
|
||||
queryKey: ['equipment'],
|
||||
queryFn: () => api<{ equipment: Equipment[] }>('/admin/equipment'),
|
||||
@@ -1113,14 +1117,14 @@ function EquipmentSection({ gym, onChanged }: { gym: Gym; onChanged: () => void
|
||||
className="flex items-center gap-2.5 rounded-[10px] border border-line bg-card/50 px-3 py-2"
|
||||
>
|
||||
<span className="min-w-0 flex-1 truncate text-[0.875rem] font-semibold">
|
||||
{formatGymEquipment(e)}
|
||||
{formatGymEquipment(e, i18n.language)}
|
||||
</span>
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
max={10000}
|
||||
defaultValue={e.quantity}
|
||||
aria-label={`Ilość: ${e.equipment.name}`}
|
||||
aria-label={`Ilość: ${localizedName(e.equipment, i18n.language)}`}
|
||||
className="w-16 shrink-0 rounded-[10px] border border-line bg-input px-2 py-1 text-center text-[0.875rem] text-ink focus:border-accent-text focus:outline-none"
|
||||
onBlur={(ev) => {
|
||||
const value = parseInt(ev.target.value, 10);
|
||||
@@ -1137,8 +1141,8 @@ function EquipmentSection({ gym, onChanged }: { gym: Gym; onChanged: () => void
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void remove(e.id)}
|
||||
aria-label={`Usuń ${e.equipment.name}`}
|
||||
title={`Usuń ${e.equipment.name}`}
|
||||
aria-label={`Usuń ${localizedName(e.equipment, i18n.language)}`}
|
||||
title={`Usuń ${localizedName(e.equipment, i18n.language)}`}
|
||||
className="shrink-0 cursor-pointer rounded-lg p-1.5 text-dim transition-colors hover:bg-danger/10 hover:text-danger"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" aria-hidden="true" />
|
||||
@@ -1166,7 +1170,7 @@ function EquipmentSection({ gym, onChanged }: { gym: Gym; onChanged: () => void
|
||||
const qty = totalQty(e.id);
|
||||
return (
|
||||
<option key={e.id} value={e.id}>
|
||||
{e.name}
|
||||
{localizedName(e, i18n.language)}
|
||||
{qty > 0 ? ` (na stanie: ${qty})` : ''}
|
||||
</option>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import {
|
||||
ArrowRight,
|
||||
@@ -32,6 +33,7 @@ import {
|
||||
} from '../../components/ui';
|
||||
import { Avatar } from '../../components/Avatar';
|
||||
import { MUSCLE_COLORS, MUSCLE_NAMES, SOCIAL_MEDIA_LABELS } from '../../lib/labels';
|
||||
import { localizedName } from '../../lib/localizedName';
|
||||
import { formatAvailabilityParts } from '../../lib/availability';
|
||||
import { useAdminUser } from './user-queries';
|
||||
import { userDisplayName } from './UserDetail';
|
||||
@@ -158,6 +160,7 @@ function SocialTile({ entry }: { entry: SocialMediaEntry }) {
|
||||
/* Ciąg przyczynowo-skutkowy: 4 kafelki w tonie grupy (kolor spójny z „Priorytety
|
||||
i wykluczenia”); puste tony wyciszone. Nazwy mięśni ujednolicone z resztą aplikacji. */
|
||||
function FocusChainCard({ chain }: { chain: FocusChain | undefined }) {
|
||||
const { i18n } = useTranslation();
|
||||
return (
|
||||
<Card>
|
||||
<SectionHeader
|
||||
@@ -204,7 +207,7 @@ function FocusChainCard({ chain }: { chain: FocusChain | undefined }) {
|
||||
<div key={e.muscle}>
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge color={MUSCLE_COLORS[e.muscle] ?? 'gray'}>
|
||||
{MUSCLE_NAMES[e.muscle] ?? e.name}
|
||||
{MUSCLE_NAMES[e.muscle] ?? localizedName(e, i18n.language)}
|
||||
</Badge>
|
||||
{(e.exercises ?? []).length > 0 && (
|
||||
<span className="text-[0.75rem] font-bold tabular-nums text-dim">
|
||||
@@ -214,7 +217,7 @@ function FocusChainCard({ chain }: { chain: FocusChain | undefined }) {
|
||||
</div>
|
||||
<div className="mt-1 text-[0.875rem] text-dim">
|
||||
{(e.exercises ?? []).length > 0
|
||||
? `${t.chainPrefix}${(e.exercises ?? []).map((x) => x.name).join(', ')}`
|
||||
? `${t.chainPrefix}${(e.exercises ?? []).map((x) => localizedName(x, i18n.language)).join(', ')}`
|
||||
: 'brak w aktywnym planie'}
|
||||
</div>
|
||||
</div>
|
||||
@@ -250,6 +253,7 @@ function InfoRow({ label, value }: { label: string; value: string }) {
|
||||
*/
|
||||
export default function UserInfo() {
|
||||
const { id } = useParams();
|
||||
const { i18n } = useTranslation();
|
||||
const { user, isLoading } = useAdminUser(id);
|
||||
const { data: areasData } = useQuery({
|
||||
queryKey: ['focus-areas'],
|
||||
@@ -261,7 +265,10 @@ export default function UserInfo() {
|
||||
enabled: !!id,
|
||||
});
|
||||
const areas = areasData?.focusAreas ?? [];
|
||||
const areaName = (muscle: string) => areas.find((a) => a.muscle === muscle)?.name ?? muscle;
|
||||
const areaName = (muscle: string) => {
|
||||
const a = areas.find((x) => x.muscle === muscle);
|
||||
return a ? localizedName(a, i18n.language) : muscle;
|
||||
};
|
||||
|
||||
useTopbar({
|
||||
// topbar = rodzic („Profil [nazwa]”), nazwa podstrony w PageHeader poniżej (h2)
|
||||
|
||||
25
admin/test/localizedName.test.ts
Normal file
25
admin/test/localizedName.test.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { localizedName } from '../src/lib/localizedName';
|
||||
|
||||
describe('localizedName', () => {
|
||||
const pl = { name: 'Przysiady', nameEn: 'Squat' };
|
||||
|
||||
it('zwraca nazwę PL dla języka polskiego', () => {
|
||||
expect(localizedName(pl, 'pl')).toBe('Przysiady');
|
||||
});
|
||||
|
||||
it('zwraca nameEn dla języka angielskiego, gdy jest dostępne', () => {
|
||||
expect(localizedName(pl, 'en')).toBe('Squat');
|
||||
});
|
||||
|
||||
it('dla braku nameEn wraca do nazwy PL (fallback)', () => {
|
||||
expect(localizedName({ name: 'Wiosłowanie' }, 'en')).toBe('Wiosłowanie');
|
||||
expect(localizedName({ name: 'Wiosłowanie', nameEn: null }, 'en')).toBe('Wiosłowanie');
|
||||
expect(localizedName({ name: 'Wiosłowanie', nameEn: '' }, 'en')).toBe('Wiosłowanie');
|
||||
});
|
||||
|
||||
it('dla pustej encji zwraca pusty string', () => {
|
||||
expect(localizedName(null, 'en')).toBe('');
|
||||
expect(localizedName(undefined, 'pl')).toBe('');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user