Plany: usuniecie sticky stopki edytora (podsumowanie duplikowalo PlanSummary) - bledy zapisu teraz w toastach
This commit is contained in:
@@ -20,7 +20,6 @@ import {
|
|||||||
Card,
|
Card,
|
||||||
ConfirmDialog,
|
ConfirmDialog,
|
||||||
EmptyState,
|
EmptyState,
|
||||||
ErrorText,
|
|
||||||
Field,
|
Field,
|
||||||
Input,
|
Input,
|
||||||
isPastWeek,
|
isPastWeek,
|
||||||
@@ -29,15 +28,10 @@ import {
|
|||||||
Tabs,
|
Tabs,
|
||||||
type BadgeColor,
|
type BadgeColor,
|
||||||
} from '../../components/ui';
|
} from '../../components/ui';
|
||||||
|
import { useToast } from '../../components/toast';
|
||||||
import { cn } from '../../lib/utils';
|
import { cn } from '../../lib/utils';
|
||||||
import { exerciseAvailableAtGym } from '../../lib/equipment';
|
import { exerciseAvailableAtGym } from '../../lib/equipment';
|
||||||
import {
|
import { DAY_NAMES, dayCountLabel, exerciseCountLabel } from '../../lib/labels';
|
||||||
DAY_NAMES,
|
|
||||||
dayCountLabel,
|
|
||||||
exerciseCountLabel,
|
|
||||||
setCountLabel,
|
|
||||||
weekCountLabel,
|
|
||||||
} from '../../lib/labels';
|
|
||||||
import { useTopbar } from '../../topbar';
|
import { useTopbar } from '../../topbar';
|
||||||
import { displayedDaysOf, type EditorDay, type EditorWeek } from './plan-editor/types';
|
import { displayedDaysOf, type EditorDay, type EditorWeek } from './plan-editor/types';
|
||||||
import { usePlanEditorState } from './plan-editor/usePlanEditorState';
|
import { usePlanEditorState } from './plan-editor/usePlanEditorState';
|
||||||
@@ -221,7 +215,7 @@ export default function PlanEditor() {
|
|||||||
}
|
}
|
||||||
}, [isEdit, planData, editor]);
|
}, [isEdit, planData, editor]);
|
||||||
|
|
||||||
const [error, setError] = useState('');
|
const { push } = useToast();
|
||||||
const [activeWeek, setActiveWeek] = useState(0);
|
const [activeWeek, setActiveWeek] = useState(0);
|
||||||
const [resultsOpenKey, setResultsOpenKey] = useState<string | null>(null);
|
const [resultsOpenKey, setResultsOpenKey] = useState<string | null>(null);
|
||||||
const [confirmExit, setConfirmExit] = useState(false);
|
const [confirmExit, setConfirmExit] = useState(false);
|
||||||
@@ -245,28 +239,6 @@ export default function PlanEditor() {
|
|||||||
// Walidacja inline: tytuł (po touch)
|
// Walidacja inline: tytuł (po touch)
|
||||||
const titleError = titleTouched && !editor.title.trim() ? 'Podaj tytuł planu' : '';
|
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 „<”)
|
// Guard niezapisanych zmian: F5/odświeżenie + wyjście (Anuluj/Wstecz/mobile „<”)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!editor.dirty) return;
|
if (!editor.dirty) return;
|
||||||
@@ -311,14 +283,13 @@ export default function PlanEditor() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const save = async () => {
|
const save = async () => {
|
||||||
setError('');
|
|
||||||
setTitleTouched(true);
|
setTitleTouched(true);
|
||||||
if (!editor.title.trim()) {
|
if (!editor.title.trim()) {
|
||||||
setError('Podaj tytuł planu');
|
push('Podaj tytuł planu', 'error');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (editor.weeks.length !== editor.weeksCount) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
const body: PlanBody = {
|
const body: PlanBody = {
|
||||||
@@ -350,7 +321,7 @@ export default function PlanEditor() {
|
|||||||
// Tydzień startu: bieżący lub przyszły (WeekPicker blokuje minione; guard zapasowy).
|
// Tydzień startu: bieżący lub przyszły (WeekPicker blokuje minione; guard zapasowy).
|
||||||
if (editor.startDate) {
|
if (editor.startDate) {
|
||||||
if (isPastWeek(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;
|
return;
|
||||||
}
|
}
|
||||||
body.startDate = editor.startDate;
|
body.startDate = editor.startDate;
|
||||||
@@ -372,7 +343,7 @@ export default function PlanEditor() {
|
|||||||
}
|
}
|
||||||
navigate(`/plans/${planIdParam}`);
|
navigate(`/plans/${planIdParam}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err instanceof Error ? err.message : 'Błąd zapisu');
|
push(err instanceof Error ? err.message : 'Błąd zapisu', 'error');
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false);
|
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
|
<ConfirmDialog
|
||||||
open={confirmExit}
|
open={confirmExit}
|
||||||
onClose={() => setConfirmExit(false)}
|
onClose={() => setConfirmExit(false)}
|
||||||
|
|||||||
Reference in New Issue
Block a user