From 4c554d9149a9f000a51cf0aed76cf1bddafc6e6b Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Mon, 20 Jul 2026 15:24:15 +0200 Subject: [PATCH] =?UTF-8?q?Workout-Builder:=20Suchsuche=20bleibt=20offen,?= =?UTF-8?q?=20"Chosen"-Filter,=20Supers=C3=A4tze?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Übungs-Picker schließt beim Antippen nicht mehr — Config öffnet darüber, Wegwischen führt zurück zur Suche (Suchbegriff bleibt erhalten) - Neuer "⭐ Chosen"-Filter: Übungen, die schon in Routinen/Workouts genutzt werden (nach Häufigkeit sortiert), plus ⭐-Marker in der Liste - Supersätze: im Routine-Editor per 🔗 mit der Übung darüber verknüpfen (visuelle Gruppierung mit Akzent-Rand + Label); im Workout als eine Superset-Karte dargestellt (beide Übungen, Pause erst nach der letzten), Unit-weise Navigation und weiterführende Gewichts-Abfrage --- frontend/src/components/Media.jsx | 6 +- frontend/src/index.css | 15 +++ frontend/src/lib/history.js | 13 +++ frontend/src/sheets.jsx | 59 ++++++++---- frontend/src/views/RoutineEdit.jsx | 55 +++++++---- frontend/src/views/Workout.jsx | 141 +++++++++++++++-------------- 6 files changed, 185 insertions(+), 104 deletions(-) diff --git a/frontend/src/components/Media.jsx b/frontend/src/components/Media.jsx index f18bafb..fb9db2c 100644 --- a/frontend/src/components/Media.jsx +++ b/frontend/src/components/Media.jsx @@ -1,11 +1,11 @@ import { useState } from 'react' import { imgSrc, gifSrc } from '../lib/exercises.js' -// Big autoplaying animation; tap toggles to the still frame. -export default function Media({ ex, id }) { +// Big autoplaying animation; tap toggles to the still frame. `compact` shrinks it (superset cards). +export default function Media({ ex, id, compact }) { const [playing, setPlaying] = useState(true) return ( -
setPlaying(p => !p)}> +
setPlaying(p => !p)}> {ex.n} {playing ? '⏸ tap to pause' : '▶ tap to play'}
diff --git a/frontend/src/index.css b/frontend/src/index.css index ff97fe0..7d2d3e2 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -306,3 +306,18 @@ h4.sec{font-size:.8rem;text-transform:uppercase;letter-spacing:.08em;color:var(- .exmedia img{height:400px} .hm-wrap{display:flex;flex-direction:column;align-items:center} } + +/* ---------- supersets ---------- */ +/* editor: grouped exercises get a left accent + a label */ +.ss-label{font-size:.66rem;font-weight:800;letter-spacing:.06em;text-transform:uppercase; + color:var(--acc);margin:6px 0 4px 4px;display:flex;align-items:center;gap:5px} +.item.in-ss{border-left:3px solid var(--acc)} +.iconbtn.on-ss{background:var(--accT);border-color:var(--acc);color:var(--acc)} +/* workout: superset card holds both exercises */ +.ss-card{border:1.5px solid var(--acc);border-radius:var(--r);padding:14px; + background:color-mix(in srgb, var(--acc) 6%, var(--card))} +.ss-hd{font-size:.72rem;font-weight:800;letter-spacing:.04em;color:var(--acc); + margin-bottom:12px;text-align:center} +.ss-ex{position:relative} +.ss-amp{text-align:center;font-size:1.3rem;font-weight:800;color:var(--acc);margin:14px 0 8px} +.exmedia.compact img{height:190px} diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.js index 329ad61..8404b47 100644 --- a/frontend/src/lib/history.js +++ b/frontend/src/lib/history.js @@ -57,6 +57,19 @@ export function setsDoneActive(A) { } export const lastBW = S => (S.bodyweight.length ? S.bodyweight[S.bodyweight.length - 1] : null) +// Group consecutive items sharing a superset id (sg) into "units" of indices. +// items may be routine exercises ({sg}) or active-workout entries ({sg}). +export function supersetUnits(items) { + const units = [] + items.forEach((e, i) => { + const prev = items[i - 1] + if (i > 0 && e.sg && prev && prev.sg && e.sg === prev.sg) units[units.length - 1].push(i) + else units.push([i]) + }) + return units +} +export function unitOf(units, idx) { return units.find(u => u.includes(idx)) || [idx] } + export function streakWeeks(S) { if (!S.workouts.length) return 0 const weeks = new Set(S.workouts.map(w => weekKey(w.d))) diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx index d65016a..a5867eb 100644 --- a/frontend/src/sheets.jsx +++ b/frontend/src/sheets.jsx @@ -3,7 +3,7 @@ import { useStore } from './store/useStore.js' import { useUI } from './store/useUI.js' import { EXDB, EXIDX, BODYPARTS } from './lib/exercises.js' import { fmtDate, fmtNum, fmtVol, fmtDur, todayISO, uid, DAYN, MONTHS_LONG, ACCENTS } from './lib/format.js' -import { lastEntryFor, bestWeightFor, buildSets, effectiveRoutineId, workoutVolume, setsDone, setsDoneActive, lastBW } from './lib/history.js' +import { lastEntryFor, bestWeightFor, buildSets, effectiveRoutineId, workoutVolume, setsDone, setsDoneActive, lastBW, supersetUnits, unitOf } from './lib/history.js' import { beep, vibrate } from './lib/sound.js' import { nav } from './lib/nav.js' import Media, { Thumb } from './components/Media.jsx' @@ -145,25 +145,40 @@ function AddToRoutine({ ex, close }) { export const addToRoutineSheet = ex => ui().openSheet(close => ) /* ============================ exercise picker ============================ */ +// Exercises already used in your routines or past workouts (for the "Chosen" filter + a marker). +function usageMap(st) { + const u = {} + st.routines.forEach(r => r.ex.forEach(e => { u[e.id] = (u[e.id] || 0) + 1 })) + st.workouts.forEach(w => w.entries.forEach(e => { u[e.id] = (u[e.id] || 0) + 1 })) + return u +} function ExercisePicker({ onPick, close }) { + const st = useStore(s => s.S) + const usage = usageMap(st) const [q, setQ] = useState('') - const [bp, setBp] = useState('') + const [bp, setBp] = useState('') // '' = all, '★' = chosen, else a body part const [shown, setShown] = useState(50) const ql = q.toLowerCase().trim() - const f = EXDB.filter(e => (!bp || e.bp === bp) && (!ql || e.n.includes(ql) || e.tg.includes(ql) || e.eq.includes(ql))) + let f = EXDB.filter(e => + (bp === '★' ? usage[e.id] : (!bp || e.bp === bp)) && + (!ql || e.n.includes(ql) || e.tg.includes(ql) || e.eq.includes(ql))) + if (bp === '★') f = [...f].sort((a, b) => (usage[b.id] - usage[a.id]) || (a.n < b.n ? -1 : 1)) + const chosenCount = Object.keys(usage).length return <>

Add exercise

{ setQ(e.target.value); setShown(50) }} />
+ {chosenCount > 0 && } {BODYPARTS.map(b => )}
- {f.slice(0, shown).map(e =>
{ close(); onPick(e) }}> -
{e.n}
{(e.tg || e.bp)} · {e.eq}
+ + {f.slice(0, shown).map(e =>
onPick(e)}> +
{e.n}
{(e.tg || e.bp)} · {e.eq}
+ {usage[e.id] && ⭐}+
)} - {f.length === 0 &&
No match 🤷
} + {f.length === 0 &&
{bp === '★' ? 'Nothing chosen yet — add exercises and they’ll show up here.' : 'No match 🤷'}
}
{f.length > shown && <>
} @@ -322,48 +337,56 @@ export function startFlow(routineId) { export function beginWorkout(routineId, bw) { const st = S() const r = routineId ? st.routines.find(x => x.id === routineId) : null - const entries = (r ? r.ex : []).map(cfg => ({ id: cfg.id, target: { ...cfg }, sets: buildSets(st, cfg) })) + const entries = (r ? r.ex : []).map(cfg => ({ id: cfg.id, sg: cfg.sg, target: { ...cfg }, sets: buildSets(st, cfg) })) update(s => { s.active = { id: uid(), d: todayISO(), start: Date.now(), routineId, name: r ? r.name : 'Freestyle', bw: bw || null, cur: 0, entries } }) useUI.getState().stopRest() nav('/workout') } -function TopWeight({ entry, close }) { +function TopWeight({ entryIdx, close }) { const st = useStore(s => s.S) const A = st.active + const entry = A.entries[entryIdx] const ex = EXIDX[entry.id] const maxSet = Math.max(0, ...entry.sets.filter(s => s.done).map(s => s.w || 0)) const prevBest = Math.max((st.exWeights[entry.id] || {}).w || 0, bestWeightFor(st, entry.id)) const [v, setV] = useState(String(Math.max(maxSet, prevBest) || entry.target.weight || 0)) - const isLastEx = A && A.cur >= A.entries.length - 1 const ref = useRef(null) useEffect(() => { setTimeout(() => { ref.current?.focus(); ref.current?.select() }, 250) }, []) + + const units = supersetUnits(A.entries) + const unit = unitOf(units, entryIdx) + const unitDone = unit.every(i => A.entries[i].sets.every(s => s.done)) + const unitIdx = units.findIndex(u => u === unit) + const isLastUnit = unitIdx === units.length - 1 + const commit = advance => { const n = parseFloat(v) if (!isFinite(n) || n < 0) { toast('Enter a valid weight'); return } update(s => { - const e = s.active.entries.find(x => x === s.active.entries[A.cur]) || s.active.entries[A.cur] - s.active.entries[A.cur].topW = n + s.active.entries[entryIdx].topW = n const cur = s.exWeights[entry.id] s.exWeights[entry.id] = { w: Math.max(n, cur ? cur.w : 0), d: todayISO() } }) close() - if (advance && A) { - if (isLastEx) finishWorkout() - else update(s => { s.active.cur = Math.min(s.active.entries.length - 1, s.active.cur + 1) }) + if (advance && unitDone) { + if (isLastUnit) finishWorkout() + else update(s => { s.active.cur = units[unitIdx + 1][0] }) } else toast('Tracked — next time starts at ' + fmtNum(S().exWeights[entry.id].w) + ' ' + st.unit + ' 📈') } return <>

✅ {ex.n} done

-
Confirm the weight you worked with — your highest becomes the default next time.
+
Confirm the weight you worked with — your highest becomes the default next time.{!unitDone && unit.length > 1 ? ' Then finish the superset partner.' : ''}
setV(e.target.value)} />{st.unit}
{prevBest > 0 ?
Previous best: {fmtNum(prevBest)} {st.unit}{maxSet > prevBest && — new record! 🏆}
:
} - -
+ {unitDone ? <> + +
+ : } } -export const topWeightSheet = entry => ui().openSheet(close => ) +export const topWeightSheet = entryIdx => ui().openSheet(close => ) function FinishSummary({ w, prs, close }) { const st = useStore(s => s.S) diff --git a/frontend/src/views/RoutineEdit.jsx b/frontend/src/views/RoutineEdit.jsx index 33afe5f..5900ed1 100644 --- a/frontend/src/views/RoutineEdit.jsx +++ b/frontend/src/views/RoutineEdit.jsx @@ -2,10 +2,18 @@ import { useNavigate, useParams } from 'react-router-dom' import { useEffect } from 'react' import { useStore } from '../store/useStore.js' import { EXIDX } from '../lib/exercises.js' -import { fmtNum } from '../lib/format.js' +import { fmtNum, uid } from '../lib/format.js' +import { supersetUnits } from '../lib/history.js' import { Thumb } from '../components/Media.jsx' import { emojiPicker, exercisePicker, exConfigSheet } from '../sheets.jsx' +// drop superset ids that no longer have an adjacent partner (after unlink/reorder) +function cleanupSg(ex) { + ex.forEach((e, i) => { + if (e.sg && !(ex[i - 1]?.sg === e.sg || ex[i + 1]?.sg === e.sg)) delete e.sg + }) +} + export default function RoutineEdit() { const nav = useNavigate() const { id } = useParams() @@ -15,13 +23,20 @@ export default function RoutineEdit() { useEffect(() => { if (!r) nav('/plan') }, [!!r]) if (!r) return null - const move = (i, dir) => update(s => { - const ex = s.routines.find(x => x.id === id).ex - const j = i + dir - if (j < 0 || j >= ex.length) return - ;[ex[i], ex[j]] = [ex[j], ex[i]] + const edit = fn => update(s => { fn(s.routines.find(x => x.id === id).ex) }) + const move = (i, dir) => edit(ex => { const j = i + dir; if (j < 0 || j >= ex.length) return;[ex[i], ex[j]] = [ex[j], ex[i]]; cleanupSg(ex) }) + const toggleLink = i => edit(ex => { + if (i < 1) return + const cur = ex[i], prev = ex[i - 1] + if (cur.sg && prev.sg && cur.sg === prev.sg) delete cur.sg + else { const gid = prev.sg || ('sg' + uid()); prev.sg = gid; cur.sg = gid } + cleanupSg(ex) }) + const units = supersetUnits(r.ex) + const unitFirst = new Set(units.filter(u => u.length > 1).map(u => u[0])) + const inSS = new Set(units.filter(u => u.length > 1).flat()) + return
@@ -34,21 +49,27 @@ export default function RoutineEdit() { {r.ex.length ?
{r.ex.map((e, i) => { const ex = EXIDX[e.id]; if (!ex) return null - return
{ - exConfigSheet(ex, e, cfg => update(s => { Object.assign(s.routines.find(x => x.id === id).ex[i], cfg) }), - () => update(s => { s.routines.find(x => x.id === id).ex.splice(i, 1) })) - }}> - -
{ex.n}
{e.sets} × {e.reps}{e.weight ? ' · ' + fmtNum(e.weight) + ' ' + S.unit : ''}
-
- - + const linkedPrev = i > 0 && e.sg && r.ex[i - 1].sg === e.sg + return
+ {unitFirst.has(i) &&
🔗 Superset
} +
{ + exConfigSheet(ex, e, cfg => edit(x => { Object.assign(x[i], cfg) }), () => edit(x => { x.splice(i, 1); cleanupSg(x) })) + }}> + +
{ex.n}
{e.sets} × {e.reps}{e.weight ? ' · ' + fmtNum(e.weight) + ' ' + S.unit : ''}
+
+ {i > 0 && } +
+ + +
+
})}
:
🏋️
No exercises yet — add your first one.
} -
- +
Tip: tap 🔗 on an exercise to superset it with the one above — you’ll do them back-to-back.
+
} -/* ---------- one set row ---------- */ -function SetRow({ entry, i, unit, last, onToggle, onWeight, onReps }) { - const s = entry.sets[i] - return
-
{i + 1}
-
- - e.target.select()} onChange={e => onWeight(e.target.value === '' ? 0 : Math.max(0, parseFloat(e.target.value) || 0))} /> - +/* ---------- one exercise block (used standalone or inside a superset card) ---------- */ +function ExerciseBlock({ entryIdx, compact, onToggle, onWeight, onReps, onAddSet }) { + const S = useStore(s => s.S) + const entry = S.active.entries[entryIdx] + const ex = EXIDX[entry.id] + const last = lastEntryFor(S, entry.id) + const best = bestWeightFor(S, entry.id) + const hint = last && last.sets.length >= (entry.target.sets || 1) && last.sets.every(s => s.r >= entry.target.reps) && last.sets[0].w > 0 + ? Math.max(...last.sets.map(s => s.w)) + 2.5 : null + return <> + +
+
{ex.n}
+
-
- - e.target.select()} onChange={e => onReps(e.target.value === '' ? 0 : Math.max(0, Math.round(parseFloat(e.target.value) || 0)))} /> - +
+ {ex.tg || ex.bp}{ex.eq} + {best > 0 && Best: {fmtNum(best)} {S.unit}}
- -
+ {last &&
Last time ({fmtDate(last.d)}): {last.sets.map(s => fmtNum(s.w) + '×' + s.r).join(', ')}
} + {hint && } +
+
Weight ({S.unit})Reps
+ {entry.sets.map((s, i) =>
+
{i + 1}
+
+ + e.target.select()} onChange={e => onWeight(i, e.target.value === '' ? 0 : Math.max(0, parseFloat(e.target.value) || 0))} /> + +
+
+ + e.target.select()} onChange={e => onReps(i, e.target.value === '' ? 0 : Math.max(0, Math.round(parseFloat(e.target.value) || 0)))} /> + +
+ +
)} +
+ +
+ } /* ---------- active workout ---------- */ @@ -65,45 +89,39 @@ function ActiveWorkout() { const A = S.active const [elapsed, setElapsed] = useState('0:00') - const cur = Math.min(A.cur, Math.max(0, A.entries.length - 1)) - const entry = A.entries[cur] - useEffect(() => { - const tick = () => { - const sec = Math.floor((Date.now() - A.start) / 1000) - setElapsed(Math.floor(sec / 60) + ':' + String(sec % 60).padStart(2, '0')) - } + const tick = () => { const sec = Math.floor((Date.now() - A.start) / 1000); setElapsed(Math.floor(sec / 60) + ':' + String(sec % 60).padStart(2, '0')) } tick(); const iv = setInterval(tick, 1000); return () => clearInterval(iv) }, [A.start]) + const units = supersetUnits(A.entries) + const cur = Math.min(A.cur, Math.max(0, A.entries.length - 1)) + const unit = A.entries.length ? unitOf(units, cur) : [] + const unitIdx = units.findIndex(u => u === unit) + const isSuperset = unit.length > 1 + const total = A.entries.reduce((n, e) => n + e.sets.length, 0) const done = setsDoneActive(A) - const ex = entry ? EXIDX[entry.id] : null - const last = entry ? lastEntryFor(S, entry.id) : null - const best = entry ? bestWeightFor(S, entry.id) : 0 - const hint = last && entry && last.sets.length >= (entry.target.sets || 1) && last.sets.every(s => s.r >= entry.target.reps) && last.sets[0].w > 0 - ? Math.max(...last.sets.map(s => s.w)) + 2.5 : null - const mutEntry = fn => update(s => { fn(s.active.entries[cur]) }, true) + const mutEntry = (idx, fn) => update(s => { fn(s.active.entries[idx]) }, true) + const setWeight = (idx, i, v) => { if (i === -1) mutEntry(idx, e => e.sets.forEach(s => { if (!s.done) s.w = v })); else mutEntry(idx, e => { e.sets[i].w = v }) } + const setReps = (idx, i, v) => mutEntry(idx, e => { e.sets[i].r = v }) + const addSet = idx => mutEntry(idx, e => { const l = e.sets[e.sets.length - 1]; e.sets.push({ w: l ? l.w : 0, r: l ? l.r : e.target.reps, done: false }) }) - const toggle = i => { + const toggle = (idx, i) => { let askTop = false - mutEntry(e => { + mutEntry(idx, e => { e.sets[i].done = !e.sets[i].done if (e.sets[i].done) { beep(S.sound, 1040, 0.12); vibrate(30) - const allDone = e.sets.every(x => x.done) - const isLastEx = cur >= A.entries.length - 1 - if (!allDone) startRest(S.restSec) - else { stopRest(); useUI.getState().toast(isLastEx ? 'All sets done — Finish 🏁' : 'Exercise done ✓') } - if (allDone && !e.asked) { e.asked = true; askTop = true } + const isLastExInUnit = idx === unit[unit.length - 1] + const unitDone = unit.every(ui => (ui === idx ? e : A.entries[ui]).sets.every(x => x.done)) + if (isLastExInUnit && !unitDone) startRest(S.restSec) + else if (unitDone) stopRest() + if (e.sets.every(x => x.done) && !e.asked) { e.asked = true; askTop = true } } }) - if (askTop) { - const e2 = S.active.entries[cur] - const maxW = Math.max(0, ...entry.sets.map(x => x.w || 0), entry.target.weight || 0, (S.exWeights[entry.id] || {}).w || 0) - if (maxW > 0) topWeightSheet(entry) - } + if (askTop) topWeightSheet(idx) } return
@@ -114,35 +132,26 @@ function ActiveWorkout() {
- {entry ? <> -
Exercise {cur + 1} / {A.entries.length}
- -
-
{ex.n}
- -
-
- {ex.tg || ex.bp}{ex.eq} - {best > 0 && Best: {fmtNum(best)} {S.unit}} -
- {last &&
Last time ({fmtDate(last.d)}): {last.sets.map(s => fmtNum(s.w) + '×' + s.r).join(', ')}
} - {hint && } - -
-
Weight ({S.unit})Reps
- {entry.sets.map((s, i) => toggle(i)} - onWeight={v => mutEntry(e => { e.sets[i].w = v })} - onReps={v => mutEntry(e => { e.sets[i].r = v })} />)} -
- -
+ {A.entries.length ? <> +
{isSuperset ? `Superset ${unitIdx + 1} / ${units.length}` : `Exercise ${unitIdx + 1} / ${units.length}`}
+ {isSuperset ? ( +
+
🔗 Superset · do these back-to-back, rest after both
+ {unit.map((idx, k) =>
+ {k > 0 &&
+
} + toggle(idx, i)} onWeight={(i, v) => setWeight(idx, i, v)} onReps={(i, v) => setReps(idx, i, v)} onAddSet={() => addSet(idx)} /> +
)} +
+ ) : ( + toggle(cur, i)} onWeight={(i, v) => setWeight(cur, i, v)} onReps={(i, v) => setReps(cur, i, v)} onAddSet={() => addSet(cur)} /> + )} :
🎯
Freestyle workout — add your first exercise.
}
- - + +