Plany: usuniecie sticky stopki edytora (podsumowanie duplikowalo PlanSummary) - bledy zapisu teraz w toastach

This commit is contained in:
tisachi
2026-09-13 15:07:27 +02:00
parent 4c31bbc3bb
commit 57eccd4ed1

View File

@@ -20,7 +20,6 @@ import {
Card,
ConfirmDialog,
EmptyState,
ErrorText,
Field,
Input,
isPastWeek,
@@ -29,15 +28,10 @@ import {
Tabs,
type BadgeColor,
} from '../../components/ui';
import { useToast } from '../../components/toast';
import { cn } from '../../lib/utils';
import { exerciseAvailableAtGym } from '../../lib/equipment';
import {
DAY_NAMES,
dayCountLabel,
exerciseCountLabel,
setCountLabel,
weekCountLabel,
} from '../../lib/labels';
import { DAY_NAMES, dayCountLabel, exerciseCountLabel } from '../../lib/labels';
import { useTopbar } from '../../topbar';
import { displayedDaysOf, type EditorDay, type EditorWeek } from './plan-editor/types';
import { usePlanEditorState } from './plan-editor/usePlanEditorState';
@@ -221,7 +215,7 @@ export default function PlanEditor() {
}
}, [isEdit, planData, editor]);
const [error, setError] = useState('');
const { push } = useToast();
const [activeWeek, setActiveWeek] = useState(0);
const [resultsOpenKey, setResultsOpenKey] = useState<string | null>(null);
const [confirmExit, setConfirmExit] = useState(false);
@@ -245,28 +239,6 @@ export default function PlanEditor() {
// Walidacja inline: tytuł (po touch)
const titleError = titleTouched && !editor.title.trim() ? 'Podaj tytuł planu' : '';
// Podsumowanie stopki: dni/ćwiczenia/serie + tygodnie bez ćwiczeń (nie blokuje)
const totals = useMemo(() => {
let days = 0;
let exerciseTotal = 0;
let sets = 0;
let emptyWeeks = 0;
editor.weeks.forEach((_, i) => {
const weekDays = displayedDaysOf(editor.weeks, i);
days += weekDays.length;
let weekExercises = 0;
weekDays.forEach((d) => {
weekExercises += d.exercises.length;
d.exercises.forEach((e) => {
sets += e.sets.length;
});
});
exerciseTotal += weekExercises;
if (weekExercises === 0) emptyWeeks += 1;
});
return { days, exercises: exerciseTotal, sets, emptyWeeks };
}, [editor.weeks]);
// Guard niezapisanych zmian: F5/odświeżenie + wyjście (Anuluj/Wstecz/mobile „<”)
useEffect(() => {
if (!editor.dirty) return;
@@ -311,14 +283,13 @@ export default function PlanEditor() {
};
const save = async () => {
setError('');
setTitleTouched(true);
if (!editor.title.trim()) {
setError('Podaj tytuł planu');
push('Podaj tytuł planu', 'error');
return;
}
if (editor.weeks.length !== editor.weeksCount) {
setError(`Plan ma ${editor.weeksCount} tygodni — zdefiniuj je wszystkie`);
push(`Plan ma ${editor.weeksCount} tygodni — zdefiniuj je wszystkie`, 'error');
return;
}
const body: PlanBody = {
@@ -350,7 +321,7 @@ export default function PlanEditor() {
// Tydzień startu: bieżący lub przyszły (WeekPicker blokuje minione; guard zapasowy).
if (editor.startDate) {
if (isPastWeek(editor.startDate)) {
setError('Tydzień startu nie może być w przeszłości');
push('Tydzień startu nie może być w przeszłości', 'error');
return;
}
body.startDate = editor.startDate;
@@ -372,7 +343,7 @@ export default function PlanEditor() {
}
navigate(`/plans/${planIdParam}`);
} catch (err) {
setError(err instanceof Error ? err.message : 'Błąd zapisu');
push(err instanceof Error ? err.message : 'Błąd zapisu', 'error');
} finally {
setSaving(false);
}
@@ -583,27 +554,6 @@ export default function PlanEditor() {
/>
)}
{/* sticky stopka: podsumowanie tylko na kroku 2 (krok 1 = brak dni, krok 3 = PlanSummary);
błędy zapisu zawsze. Akcje Dalej/Zapisz + „<” są w menu kontekstowym topbar;
na mobile pod stałym dolnym paskiem topmenu (50px = pt-2 + wiersz 34px + pb) + safe-area */}
{(step === 2 || error) && (
<div className="sticky bottom-0 -mx-4 px-4 py-3 bg-bg/95 backdrop-blur border-t border-line mt-2 md:-mx-8 md:px-8 max-md:bottom-[calc(50px+max(0.5rem,env(safe-area-inset-bottom)))]">
{error && <ErrorText>{error}</ErrorText>}
{step === 2 && (
<div className="text-dim text-[0.8125rem]">
{dayCountLabel(totals.days)} · {exerciseCountLabel(totals.exercises)} ·{' '}
{setCountLabel(totals.sets)}
{totals.emptyWeeks > 0 && (
<span className="text-warn">
{' '}
· {weekCountLabel(totals.emptyWeeks)} bez ćwiczeń
</span>
)}
</div>
)}
</div>
)}
<ConfirmDialog
open={confirmExit}
onClose={() => setConfirmExit(false)}