{progress ? `${progress.completed} z ${progress.total} dni` : 'brak aktywnego planu'}
{daysLeft != null && daysLeft > 0 ? ` · ${daysLeft} dni do końca` : ''}
@@ -352,10 +383,10 @@ export default function Dashboard() {
))}
-
+
>
) : (
diff --git a/app/src/pages/DayExecution.tsx b/app/src/pages/DayExecution.tsx
index a127b01..27649b9 100644
--- a/app/src/pages/DayExecution.tsx
+++ b/app/src/pages/DayExecution.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useState, type ReactNode } from 'react';
+import { useEffect, useRef, useState, type ReactNode } from 'react';
import { useParams } from 'react-router-dom';
import { useQueryClient } from '@tanstack/react-query';
import { Check, ChevronDown, Plus, Trash2 } from 'lucide-react';
@@ -579,13 +579,19 @@ export default function DayExecution() {
: undefined,
});
+ // podwójny klik nie może wysłać dwóch żądań (serwer zbiłby drugie 400)
+ const addingRef = useRef(false);
+
const addExercise = async (exerciseId: string) => {
- if (!session) return;
+ if (!session || addingRef.current) return;
+ addingRef.current = true;
try {
await addSessionExercise(session.id, exerciseId);
await queryClient.invalidateQueries({ queryKey: ['sessions', session.id] });
} catch (e) {
setError(e instanceof Error ? e.message : 'Błąd');
+ } finally {
+ addingRef.current = false;
}
};
@@ -600,12 +606,15 @@ export default function DayExecution() {
};
const addSet = async (exerciseId: string) => {
- if (!session) return;
+ if (!session || addingRef.current) return;
+ addingRef.current = true;
try {
await addSessionSet(exerciseId);
await queryClient.invalidateQueries({ queryKey: ['sessions', session.id] });
} catch (e) {
setError(e instanceof Error ? e.message : 'Błąd');
+ } finally {
+ addingRef.current = false;
}
};
diff --git a/app/src/pages/profile/ProfileBodyParameters.tsx b/app/src/pages/profile/ProfileBodyParameters.tsx
index ac5aa02..3460552 100644
--- a/app/src/pages/profile/ProfileBodyParameters.tsx
+++ b/app/src/pages/profile/ProfileBodyParameters.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useState, type ReactNode } from 'react';
+import { useEffect, useRef, useState, type ReactNode } from 'react';
import { useNavigate } from 'react-router-dom';
import { ChevronDown, Plus, Ruler, Scale, Trash2, type LucideIcon } from 'lucide-react';
import {
@@ -381,30 +381,47 @@ export default function ProfileBodyParameters() {
if (available.length > 0 && !available.includes(month)) setMonth(available[0]);
}, [monthsKey, month, setMonth]);
+ // ref (nie stan): drugi klik w tym samym ticku musi zobaczyć flagę natychmiast
+ const savingRef = useRef(false);
+
const saveWeight = async (e: React.FormEvent) => {
e.preventDefault();
- if (!weight) return;
- await addWeight(parseFloat(weight), weightDate || undefined);
- setWeight('');
- setWeightDate(today());
- setAddOpen(false);
- await refetchBp();
- push('Waga dodana', 'success');
+ if (!weight || savingRef.current) return;
+ savingRef.current = true;
+ try {
+ await addWeight(parseFloat(weight), weightDate || undefined);
+ setWeight('');
+ setWeightDate(today());
+ setAddOpen(false);
+ await refetchBp();
+ push('Waga dodana', 'success');
+ } catch (err) {
+ push(err instanceof Error ? err.message : 'Błąd zapisu', 'error');
+ } finally {
+ savingRef.current = false;
+ }
};
const saveCirc = async (e: React.FormEvent) => {
e.preventDefault();
- if (!circValue) return;
- await addCircumference(
- measurementName(circType, circSide),
- parseFloat(circValue),
- circDate || undefined,
- );
- setCircValue('');
- setCircDate(today());
- setAddOpen(false);
- await refetchBp();
- push('Obwód dodany', 'success');
+ if (!circValue || savingRef.current) return;
+ savingRef.current = true;
+ try {
+ await addCircumference(
+ measurementName(circType, circSide),
+ parseFloat(circValue),
+ circDate || undefined,
+ );
+ setCircValue('');
+ setCircDate(today());
+ setAddOpen(false);
+ await refetchBp();
+ push('Obwód dodany', 'success');
+ } catch (err) {
+ push(err instanceof Error ? err.message : 'Błąd zapisu', 'error');
+ } finally {
+ savingRef.current = false;
+ }
};
const confirmRemove = async () => {
diff --git a/app/test/message-thread.test.tsx b/app/test/message-thread.test.tsx
index 4a9b23b..4987fff 100644
--- a/app/test/message-thread.test.tsx
+++ b/app/test/message-thread.test.tsx
@@ -57,7 +57,15 @@ const TRAINEE_HISTORY = {
muscle: 'legs',
isExtra: false,
comments: [],
- sets: [{ index: 0, reps: 10, rir: 2, difficulty: 3, planned: { reps: 10, loadKg: 60, restSec: 90, rir: 2 } }],
+ sets: [
+ {
+ index: 0,
+ reps: 10,
+ rir: 2,
+ difficulty: 3,
+ planned: { reps: 10, loadKg: 60, restSec: 90, rir: 2 },
+ },
+ ],
},
{
id: 'se-2',
@@ -87,7 +95,8 @@ function mockApi() {
vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
const url = String(input);
const method = init?.method || 'GET';
- if (url.includes('/auth/login')) return jsonResponse(200, { user: TRAINER, accessToken: 'tok-1' });
+ if (url.includes('/auth/login'))
+ return jsonResponse(200, { user: TRAINER, accessToken: 'tok-1' });
if (url.includes('/auth/refresh'))
return jsonResponse(401, { error: { code: 'UNAUTHORIZED', message: 'no cookie' } });
if (url.includes('/messages/conversations/coaching-1')) {
@@ -105,7 +114,14 @@ function mockApi() {
plan: 'Plan testowy',
exercise: {
name: 'Przysiady',
- sets: [{ index: 0, reps: 10, rir: 2, planned: { reps: 10, loadKg: 60, restSec: 90, rir: 2 } }],
+ sets: [
+ {
+ index: 0,
+ reps: 10,
+ rir: 2,
+ planned: { reps: 10, loadKg: 60, restSec: 90, rir: 2 },
+ },
+ ],
},
exercises: [],
}
@@ -143,12 +159,17 @@ function mockApi() {
coachingId: 'coaching-1',
role: 'trainer',
other: { id: 'trainee-1', firstName: 'Anna', lastName: 'Nowak' },
- lastMessage: { body: 'Dobrze się czuję', createdAt: '2026-08-24T10:00:00.000Z', senderId: 'trainee-1' },
+ lastMessage: {
+ body: 'Dobrze się czuję',
+ createdAt: '2026-08-24T10:00:00.000Z',
+ senderId: 'trainee-1',
+ },
unreadCount: 0,
},
],
});
- if (url.includes('/trainer/trainees/trainee-1/history')) return jsonResponse(200, TRAINEE_HISTORY);
+ if (url.includes('/trainer/trainees/trainee-1/history'))
+ return jsonResponse(200, TRAINEE_HISTORY);
if (url.includes('/trainer/trainees/trainee-1'))
return jsonResponse(200, {
coachingId: 'coaching-1',
@@ -158,16 +179,30 @@ function mockApi() {
activePlan: { id: 'plan-1', title: 'Plan testowy', startDate: '2026-08-01' },
progress: { completed: 5, total: 14, percent: 36 },
killstreak: 3,
- nextTraining: { dayId: 'day-1', date: '2026-08-26', exercises: [{ name: 'Przysiady', muscle: 'legs' }] },
+ nextTraining: {
+ dayId: 'day-1',
+ date: '2026-08-26',
+ exercises: [{ name: 'Przysiady', muscle: 'legs' }],
+ },
extra: null,
missing: null,
lastSessionAt: '2026-08-24T08:30:00.000Z',
flags: ['no_session_7d'],
});
if (url.includes('/me/history')) return jsonResponse(200, { sessions: [] });
- if (url.includes('/me')) return jsonResponse(200, { user: TRAINER, memberships: [] });
+ if (url.includes('/me'))
+ return jsonResponse(200, {
+ user: TRAINER,
+ // wątek treningowy wymaga roli trenera (guard trasy /trainees/*)
+ memberships: [{ gymId: 'gym-1', roles: ['TRAINER'] }],
+ });
if (url.includes('/dashboard'))
- return jsonResponse(200, { killstreak: 0, activePlan: null, nextTraining: null, progress: null });
+ return jsonResponse(200, {
+ killstreak: 0,
+ activePlan: null,
+ nextTraining: null,
+ progress: null,
+ });
if (url.includes('/trainer/trainees')) return jsonResponse(200, { trainees: [] });
if (url.includes('/trainer/invitations')) return jsonResponse(200, { invitations: [] });
if (url.includes('/gyms/invitations')) return jsonResponse(200, { invitations: [] });