From 64f33dd3bd81d7673b02d102f703e5c2a0755a1a Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Mon, 20 Jul 2026 20:26:38 +0200 Subject: [PATCH] Tab-Wechsel scrollt nach oben, Slider-Geste blockiert Sheet-Swipe, Zielgewicht mit Slider MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Bei jedem Tab-/Routen-Wechsel springt die Seite an den Anfang (scrollTo(0,0)) - Wenn eine Geste auf dem Slider startet, ignoriert das Sheet den Swipe-to-dismiss komplett (Slider gehört die Geste) — erst beim Loslassen kann wieder weggewischt werden - Zielgewicht (Goal) nutzt jetzt denselben Slider + Plus/Minus statt Zahlenfeld (geteilte WeightInput-Komponente) --- frontend/src/App.jsx | 7 ++-- frontend/src/components/Modals.jsx | 6 ++++ frontend/src/sheets.jsx | 51 ++++++++++++++++-------------- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index a41d9a9..4fc0934 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,5 +1,5 @@ import { useEffect } from 'react' -import { HashRouter, Routes, Route, Navigate, useNavigate } from 'react-router-dom' +import { HashRouter, Routes, Route, Navigate, useNavigate, useLocation } from 'react-router-dom' import { useStore } from './store/useStore.js' import { ACCENTS } from './lib/format.js' import { setNav } from './lib/nav.js' @@ -28,17 +28,20 @@ function applyPrefs(theme, accent) { function Shell() { const navigate = useNavigate() + const loc = useLocation() const { S, user, ready } = useStore() const isGuest = useStore(s => s.isGuest()) useEffect(() => { setNav(navigate) }, [navigate]) useEffect(() => { applyPrefs(S.theme, S.accent) }, [S.theme, S.accent]) + // every tab/route change starts at the top of the page + useEffect(() => { window.scrollTo(0, 0) }, [loc.pathname]) const authed = user || isGuest if (!ready && !authed) return
🏋️
return ( <> -
+
{!authed ? : ( } /> diff --git a/frontend/src/components/Modals.jsx b/frontend/src/components/Modals.jsx index 79c7fe3..0923ee8 100644 --- a/frontend/src/components/Modals.jsx +++ b/frontend/src/components/Modals.jsx @@ -9,6 +9,12 @@ function Sheet({ sheet }) { const onTouchStart = e => { const el = ref.current + // a gesture that begins on a slider (or opted-out control) belongs to that control, + // not to the sheet's swipe-to-dismiss — so it keeps working while you drag + if (e.target.closest && e.target.closest('input[type=range], [data-nodrag]')) { + drag.current = { startY: null, delta: 0 } + return + } drag.current = { startY: el.scrollTop <= 0 ? e.touches[0].clientY : null, delta: 0 } } const onTouchMove = e => { diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx index 42ce56a..660850a 100644 --- a/frontend/src/sheets.jsx +++ b/frontend/src/sheets.jsx @@ -28,21 +28,34 @@ export function loadStarterPlan() { toast('Starter plan loaded — Mon Push · Wed Pull · Fri Legs') } +/* ============================ weight picker (shared: body weight + goal) ============================ */ +function WeightInput({ value, setValue, unit }) { + const clamp = x => Math.max(20, Math.min(300, Math.round((x || 0) * 10) / 10)) + const range = useRef(null) + if (!range.current) { const s = value || 70; range.current = [Math.max(30, Math.round(s - 20)), Math.min(250, Math.round(s + 20))] } + const [lo, hi] = range.current + const sv = Math.max(lo, Math.min(hi, value)) + const pct = ((sv - lo) / (hi - lo)) * 100 + return <> +
+ +
{fmtNum(value)} {unit}
+ +
+ setValue(clamp(parseFloat(e.target.value)))} + style={{ '--track': `linear-gradient(90deg, var(--acc) ${pct}%, var(--bg2) ${pct}%)` }} /> + +} + /* ============================ body weight ============================ */ function BwSheet({ required, onDone, close }) { const st = useStore(s => s.S) const unit = st.unit const bw = lastBW(st) - const start = bw ? bw.w : 70 - const [v, setV] = useState(start) - const clamp = x => Math.max(20, Math.min(300, Math.round((x || 0) * 10) / 10)) - const set = x => setV(clamp(x)) // absolute (slider) - const step = d => setV(p => clamp(p + d)) // relative (buttons/chips) — safe for rapid taps - // fixed slider window around the starting value (buttons/quick chips can go beyond) - const lo = Math.max(30, Math.round(start - 20)) - const hi = Math.min(250, Math.round(start + 20)) + const [v, setV] = useState(bw ? bw.w : 70) const save = () => { - const n = clamp(v) + const n = Math.round((v || 0) * 10) / 10 if (!n || n <= 0) { toast('Enter a valid weight'); return } update(s => { const iso = todayISO() @@ -58,14 +71,7 @@ function BwSheet({ required, onDone, close }) { return <>

{required ? 'Quick check-in ⚖️' : 'Log body weight'}

{required ? 'Slide or tap to set your weight — tracked before every workout so your curve stays honest.' : 'Today, ' + fmtDate(todayISO(), true)}
-
- -
{fmtNum(v)} {unit}
- -
- set(parseFloat(e.target.value))} - style={{ '--track': `linear-gradient(90deg, var(--acc) ${((Math.max(lo, Math.min(hi, v)) - lo) / (hi - lo)) * 100}%, var(--bg2) ${((Math.max(lo, Math.min(hi, v)) - lo) / (hi - lo)) * 100}%)` }} /> +
{required && <> @@ -99,16 +105,15 @@ export function bwDeltaColor(delta, currentW) { function GoalSheet({ close }) { const st = S() const bw = lastBW(st) - const [v, setV] = useState(st.targetW || (bw ? String(bw.w) : '')) - const ref = useRef(null) - useEffect(() => { setTimeout(() => { ref.current?.focus(); ref.current?.select() }, 250) }, []) + const [v, setV] = useState(st.targetW || (bw ? bw.w : 70)) return <>

Target weight 🎯

Your goal is drawn as a line through the weight charts, and gains/losses are colored by whether they move toward it.
-
setV(e.target.value)} placeholder="0.0" />{st.unit}
+ +