Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
feat(supersets): a name and a rest after each round, and A1/A2 in the editor (#292, #293)
Duarte Santosfb9dbdb68bc9
diff --git a/frontend/src/index.css b/frontend/src/index.cssindex dae05bf04..e29c4049d 100644--- a/frontend/src/index.css+++ b/frontend/src/index.css@@ -1764,6 +1764,13 @@ body.no-tabbar.resting #toast{bottom:calc(100px + var(--sab))}color:var(--acc);margin-block:8px 5px;margin-inline-start:4px;display:flex;align-items:center;gap:5px;}.ss-label .icn{font-size:13px}+/* The routine editor's label opens the superset's name and rest (#292). */+.ss-label-btn{background:none;border:0;padding:4px 6px;margin-inline-start:-2px;border-radius:8px;cursor:pointer;font:inherit;font-size:12px;font-weight:600;min-height:28px;max-width:100%}+.ss-label-btn:active{background:var(--surface-2)}+.ss-label-btn .ss-label-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}+.ss-label-btn .dim{font-weight:500;white-space:nowrap}+/* A1, A2…: a member's place in the round (#293). */+.ss-pos{flex:none;min-width:26px;height:22px;padding:0 5px;border-radius:7px;display:inline-flex;align-items:center;justify-content:center;font-size:11.5px;font-weight:700;color:var(--acc);background:var(--acc-soft, var(--surface-2))}.item.in-ss{box-shadow:inset 3px 0 0 var(--acc)}/* A past workout's detail: each exercise opens its history, and a superset's exercises share theroutine editor's label and bar. */diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.jsindex 5c5b9f693..dff617d18 100644--- a/frontend/src/lib/history.js+++ b/frontend/src/lib/history.js@@ -1,4 +1,5 @@// Pure helpers over the state object S (ported 1:1 from the vanilla app).+import { syncSupersetMeta } from './superset-meta.js'import { todayISO, isoOf, weekKey, weekStartOf, fmtNum } from './format.js'import { fmtSpeed } from './speed.js'import { isCardio, isBodyweightEq, isAssisted, betterWeight } from './exercises.js'@@ -235,6 +236,8 @@ export 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})+ // A superset's name and rest (#292) follow its members in and out of the group.+ syncSupersetMeta(ex)}// Return the contiguous run around an entry that shares its superset id. A repeated id in adiff --git a/frontend/src/lib/superset-meta.js b/frontend/src/lib/superset-meta.jsnew file mode 100644index 000000000..4e731c929--- /dev/null+++ b/frontend/src/lib/superset-meta.js@@ -0,0 +1,44 @@+// A superset's own name and its rest between rounds (#292). Carried on every member of the group+// (`sgName`, `sgRest` on a routine exercise, so on an entry's `target` once a session starts):+// a reorder, a member taken out or the routine copied into a session keeps them without a second+// structure to keep in step. The first member that has a value speaks for the group.+export const SG_NAME_MAX = 40++const fieldsOf = (item, onTarget) => (onTarget ? item?.target : item) || {}++/** { name, rest } of the group of `unit` (indices into `list`); `onTarget` for session entries. */+export function supersetMeta(list, unit, { onTarget = false } = {}) {+ let name = '', rest = 0+ for (const idx of unit || []) {+ const f = fieldsOf(list?.[idx], onTarget)+ if (!name && typeof f.sgName === 'string' && f.sgName.trim()) name = f.sgName.trim().slice(0, SG_NAME_MAX)+ if (!rest && Number(f.sgRest) > 0) rest = Math.round(Number(f.sgRest))+ }+ return { name, rest }+}++/** Writes name and rest onto every member of group `sg` in a routine's `ex`; empty clears. */+export function setSupersetMeta(ex, sg, { name = '', rest = 0 } = {}) {+ const clean = String(name || '').trim().slice(0, SG_NAME_MAX)+ const sec = Number(rest) > 0 ? Math.round(Number(rest)) : 0+ for (const e of ex || []) {+ if (!e || !sg || e.sg !== sg) continue+ if (clean) e.sgName = clean; else delete e.sgName+ if (sec) e.sgRest = sec; else delete e.sgRest+ }+ return ex+}++/** A member that joined or left a group: it takes the group's meta, or drops what it carried. */+export function syncSupersetMeta(ex) {+ const groups = new Map()+ for (const e of ex || []) {+ if (!e?.sg) { if (e) { delete e.sgName; delete e.sgRest }; continue }+ const g = groups.get(e.sg) || { name: '', rest: 0 }+ if (!g.name && e.sgName) g.name = e.sgName+ if (!g.rest && Number(e.sgRest) > 0) g.rest = Number(e.sgRest)+ groups.set(e.sg, g)+ }+ for (const [sg, g] of groups) setSupersetMeta(ex, sg, g)+ return ex+}diff --git a/frontend/src/lib/superset-meta.test.js b/frontend/src/lib/superset-meta.test.jsnew file mode 100644index 000000000..83f9bb7d2--- /dev/null+++ b/frontend/src/lib/superset-meta.test.js@@ -0,0 +1,30 @@+import { describe, it, expect } from 'vitest'+import { supersetMeta, setSupersetMeta, syncSupersetMeta } from './superset-meta.js'+import { restSecFor } from './supersetFlow.js'++describe('a superset\'s name and rest between rounds (#292)', () => {+ it('is written onto every member and read back from the group', () => {+ const ex = [{ id: 'a', sg: 'g' }, { id: 'b', sg: 'g' }, { id: 'c' }]+ setSupersetMeta(ex, 'g', { name: ' Arms finisher ', rest: 75 })+ expect(ex[0]).toMatchObject({ sgName: 'Arms finisher', sgRest: 75 })+ expect(ex[1]).toMatchObject({ sgName: 'Arms finisher', sgRest: 75 })+ expect(ex[2].sgName).toBeUndefined()+ expect(supersetMeta(ex, [0, 1])).toEqual({ name: 'Arms finisher', rest: 75 })+ setSupersetMeta(ex, 'g', { name: '', rest: 0 })+ expect(ex[0].sgName).toBeUndefined()+ expect(ex[0].sgRest).toBeUndefined()+ })+ it('a new member takes the group\'s values, one that left drops them', () => {+ const ex = [{ id: 'a', sg: 'g', sgName: 'Pair', sgRest: 60 }, { id: 'b', sg: 'g' }, { id: 'c', sgName: 'Old', sgRest: 30 }]+ syncSupersetMeta(ex)+ expect(ex[1]).toMatchObject({ sgName: 'Pair', sgRest: 60 })+ expect(ex[2].sgName).toBeUndefined()+ })+ it('the group\'s rest replaces the longest member rest after a round', () => {+ const entries = [{ target: { restSec: 120, sgRest: 45 } }, { target: { restSec: 90, sgRest: 45 } }]+ expect(restSecFor(entries, [0, 1], 90)).toBe(45)+ // On a single exercise a leftover value means nothing.+ expect(restSecFor(entries, [0], 90)).toBe(120)+ expect(restSecFor([{ target: { restSec: 120 } }, { target: {} }], [0, 1], 90)).toBe(120)+ })+})diff --git a/frontend/src/lib/supersetFlow.js b/frontend/src/lib/supersetFlow.jsindex cf49ecfbb..401265398 100644--- a/frontend/src/lib/supersetFlow.js+++ b/frontend/src/lib/supersetFlow.js@@ -1,3 +1,4 @@+import { supersetMeta } from './superset-meta.js'// Pure decisions for the active-workout superset flow. Keeping these independent of React and// the stores makes the uneven-round and re-check rules explicit and directly testable.import { isWarmupRow } from './workout-model.js'@@ -85,6 +86,11 @@ export function restSecFor(entries, unit, defaultRestSec, setRest = null) {const fallback = defaultRestSec > 0 ? defaultRestSec : 0const idxs = Array.isArray(unit) && unit.length ? unit : []if (!idxs.length) return fallback+ // A superset with a rest of its own (#292) rests exactly that after each round.+ if (idxs.length > 1) {+ const { rest } = supersetMeta(entries, idxs, { onTarget: true })+ if (rest > 0) return rest+ }return idxs.reduce((longest, idx) => {// `setRest` is the ticked set's own rest ({ idx, sec }, a pyramid set): it stands in for// that member's exercise rest, and a superset still takes the longest of the group.diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex 123612f1b..dc307f091 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -20,6 +20,7 @@ import { syncMedia } from './lib/media-sync.js'import LineChart from './components/LineChart.jsx'import Stepper from './components/Stepper.jsx'import { durationSheet } from './components/DurationWheel.jsx'+import { SG_NAME_MAX } from './lib/superset-meta.js'import { REST_MAX, fmtRest } from './lib/duration.js'import Icon from './components/Icon.jsx'import { Button, Slider, Switch, Segmented, SelectRow, Row, TextField, NumberField, MultiSelectRow } from './components/ui.jsx'@@ -2767,6 +2768,31 @@ function RenameWorkout({ close }) {}export const renameWorkoutSheet = () => ui().openSheet(close => <RenameWorkout close={close} />)+// A superset's own name and rest between rounds (#292), from the routine editor.+function SupersetSettings({ meta, onSave, close }) {+ const inputRef = useRef(null)+ const onFocus = useSheetKeyboard(inputRef)+ const [name, setName] = useState(meta.name || '')+ const [rest, setRest] = useState(meta.rest || 0)+ const save = () => { onSave({ name: name.trim().slice(0, SG_NAME_MAX), rest }); close() }+ return <>+ <h3>{t('Superset')}</h3>+ <input ref={inputRef} className="input" type="text" maxLength={SG_NAME_MAX} value={name}+ placeholder={t('Name, e.g. Arm finisher')} onFocus={onFocus} onChange={e => setName(e.target.value)}+ onKeyDown={e => { if (e.key === 'Enter') save() }} />+ <div style={{ height: 12 }} />+ <div className="list">+ <Row icon="timer" iconTint="var(--orange)" title={t('Rest after each round')}+ value={rest > 0 ? fmtRest(rest) : t('Longest exercise rest')} accessory="chevron"+ onClick={() => durationSheet({ title: t('Rest after each round'), value: rest, max: REST_MAX, off: t('Longest exercise rest'),+ footer: t('Without one, the superset rests as long as its longest exercise rest.'), onDone: setRest })} />+ </div>+ <div style={{ height: 18 }} />+ <Button variant="primary" onClick={save}>{t('Save')}</Button>+ </>+}+export const supersetSheet = (meta, onSave) => ui().openSheet(close => <SupersetSettings meta={meta} onSave={onSave} close={close} />)+/* Drop-set drops and rest-pause bursts are edited inline on the set row itself (Workout.jsx) —no sheet, no timer. A planned exercise (see the "Intensifier" config below) arrives with themalready computed via applyIntensifierPlan; an unplanned straight set can still grow one livediff --git a/frontend/src/views/RoutineEdit.jsx b/frontend/src/views/RoutineEdit.jsxindex a6f2bbcb9..79f28723e 100644--- a/frontend/src/views/RoutineEdit.jsx+++ b/frontend/src/views/RoutineEdit.jsx@@ -8,7 +8,9 @@ import { uid, exerciseNameText } from '../lib/format.js'import { t, exerciseNameFor, exerciseNameClass } from '../lib/i18n.js'import { supersetUnits, moveRoutineEntry, cleanupSg, exLine, defaultConfig } from '../lib/history.js'import { Thumb } from '../components/Media.jsx'-import { glyphPicker, exercisePicker, exConfigSheet, confirmSheet } from '../sheets.jsx'+import { glyphPicker, exercisePicker, exConfigSheet, confirmSheet, supersetSheet } from '../sheets.jsx'+import { supersetMeta, setSupersetMeta } from '../lib/superset-meta.js'+import { fmtRest } from '../lib/duration.js'import Icon from '../components/Icon.jsx'import { glyphOf } from '../lib/glyphs.js'import { Button, Row, SelectRow, Switch } from '../components/ui.jsx'@@ -445,6 +447,16 @@ export default function RoutineEdit() {const units = supersetUnits(r.ex)const unitFirst = new Set(units.filter(u => u.length > 1).map(u => u[0]))+ // Each superset gets a letter and each member its place in the round (A1, A2, B1…), so the+ // order you do them in reads off the list (#293).+ const ssPos = new Map()+ units.filter(u => u.length > 1).forEach((u, k) => u.forEach((idx, n) => ssPos.set(idx, String.fromCharCode(65 + (k % 26)) + (n + 1))))+ const unitOf = new Map(units.flatMap(u => u.map(idx => [idx, u])))+ const editSuperset = i => {+ const sg = r.ex[i]?.sg+ if (!sg) return+ supersetSheet(supersetMeta(r.ex, unitOf.get(i)), meta => edit(ex => { setSupersetMeta(ex, sg, meta) }))+ }const inSS = new Set(units.filter(u => u.length > 1).flat())const profile = activeProfile(S)const missingCount = profile ? r.ex.filter(e => !exAvailable(S, exOr(e.id))).length : 0@@ -514,11 +526,12 @@ export default function RoutineEdit() {// screen reader would lose inside one): the name is, a real <button> a click bubbles up// from. The long press treats it as the row (data-row-open, useRoutineReorder).const item = <div className={'item' + (inSS.has(i) ? ' in-ss' : '')} onClick={() => {- exConfigSheet(ex, e, cfg => edit(x => { x[i] = { id: x[i].id, sg: x[i].sg, ...cfg } }), removeHere, r, null, () => replace(i))+ exConfigSheet(ex, e, cfg => edit(x => { x[i] = { id: x[i].id, sg: x[i].sg, ...(x[i].sg ? { sgName: x[i].sgName, sgRest: x[i].sgRest } : {}), ...cfg }; cleanupSg(x) }), removeHere, r, null, () => replace(i))}}>{/* Shown on pointer devices only (index.css .routine-grip); the Move buttons and thelong press stay the way in for a keyboard and a finger. */}<span className="routine-grip" data-drag-handle aria-hidden="true" title={t('Reorder exercises')}><Icon name="grip" /></span>+ {ssPos.has(i) && <span className="ss-pos" aria-label={t('Superset position {0}', ssPos.get(i))}>{ssPos.get(i)}</span>}<Thumb ex={ex} /><button type="button" className="grow item-open" data-row-open><span className={`tt ${exerciseNameClass(ex)}`}>{exerciseNameFor(ex)}</span><span className="ss">{exLine(e, S.unit, speedUnitOf(S))}</span>{e.note && <span className="small dim" style={{ marginTop: 2 }}>{e.note}</span>}</button>@@ -534,7 +547,14 @@ export default function RoutineEdit() {return <div key={i} data-routine-row data-ex-index={i}className={'routine-drag-row' + (isDragging ? ' is-dragging' : '')}style={isDragging ? { transform: `translate3d(0, ${reorder.drag.deltaY}px, 0)` } : undefined}>- {unitFirst.has(i) && <div className="ss-label"><Icon name="link" />{t('Superset')}</div>}+ {unitFirst.has(i) && (() => {+ const meta = supersetMeta(r.ex, unitOf.get(i))+ return <button type="button" className="ss-label ss-label-btn" onClick={() => editSuperset(i)} title={t('Name and rest of this superset')}>+ <Icon name="link" /><span className="ss-label-name">{meta.name || t('Superset')}</span>+ {meta.rest > 0 && <span className="dim">· {t('{0} rest after each round', fmtRest(meta.rest))}</span>}+ <Icon name="pencil" />+ </button>+ })()}{/* Swipe (v1.3.11, Settings → Swipe actions): toward the start takes the exercise out,with an Undo; nothing on the other side. The long press still picks the row up toreorder it (a press that has lifted keeps the swipe out), and the row's sheet keepsdiff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsxindex b32de59e6..d13fc264a 100644--- a/frontend/src/views/Workout.jsx+++ b/frontend/src/views/Workout.jsx@@ -19,6 +19,7 @@ import { pyramidRestFor, maxRecordAt, isPyramid, pyramidLabel } from '../lib/pyrimport { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor, warmupRestSecFor } from '../lib/supersetFlow.js'import Media from '../components/Media.jsx'import WorkoutScrollAnchor from '../components/WorkoutScrollAnchor.jsx'+import { supersetMeta } from '../lib/superset-meta.js'import WorkoutThumb, { hasWorkoutMedia } from '../components/WorkoutThumb.jsx'import { workoutSettingsSheet } from '../components/WorkoutSettingsSheet.jsx'import { durationSheet } from '../components/DurationWheel.jsx'@@ -909,6 +910,12 @@ function ActiveWorkout() {const workoutView = A.workoutView || S.workoutViewconst listMode = workoutView === 'list' || workoutView === 'compact'const dense = workoutView === 'compact'+ // A superset's heading: its own name and rest between rounds when it has them (#292).+ const ssTitle = u => {+ const m = supersetMeta(A.entries, u, { onTarget: true })+ if (m.rest > 0) return t('{0} · back-to-back, {1} rest after each round', m.name || t('Superset'), fmtRest(m.rest))+ return m.name ? t('{0} · do these back-to-back, rest when done', m.name) : t('Superset · do these back-to-back, rest when done')+ }// Collapse finished exercises in the list (#241). The current unit stays open, superset// members included, until you move on; an empty exercise or a half-done warm-up or side does too.const collapsed = new Set(listMode && A.collapseCompleted ? units.filter(u =>@@ -1812,7 +1819,7 @@ function ActiveWorkout() {</div> : multi ? (<div className="ss-card"><div className="ss-hd" style={{ justifyContent: 'space-between' }}>- <span className="row" style={{ gap: 5 }}><Icon name="link" />{t('Superset · do these back-to-back, rest when done')}</span>+ <span className="row" style={{ gap: 5 }}><Icon name="link" />{ssTitle(u)}</span><Button size="xs" variant="ghost" icon="link" title={t('Unpair')} onClick={() => unpairAt(u[0])}>{t('Unpair')}</Button></div>{u.map((idx, k) => {@@ -1850,7 +1857,7 @@ function ActiveWorkout() {return adjacent.length > 1 ? (<div className="ss-card"><div className="ss-hd" style={{ justifyContent: 'space-between' }}>- <span className="row" style={{ gap: 5 }}><Icon name="link" />{t('Superset · do these back-to-back, rest when done')}</span>+ <span className="row" style={{ gap: 5 }}><Icon name="link" />{ssTitle(adjacent)}</span><Button size="xs" variant="ghost" icon="link" title={t('Unpair')} onClick={() => unpairAt(adjacent[0])}>{t('Unpair')}</Button></div>{adjacent.map((idx, k) => <div key={idx} className="ss-ex" data-exidx={idx}>@@ -1866,7 +1873,7 @@ function ActiveWorkout() {{isSuperset ? (<div className="ss-card"><div className="ss-hd" style={{ justifyContent: 'space-between' }}>- <span className="row" style={{ gap: 5 }}><Icon name="link" />{t('Superset · do these back-to-back, rest when done')}</span>+ <span className="row" style={{ gap: 5 }}><Icon name="link" />{ssTitle(unit)}</span><Button size="xs" variant="ghost" icon="link" title={t('Unpair')} onClick={() => unpairAt(cur)}>{t('Unpair')}</Button></div>{unit.map((idx, k) => {