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
History: a copied workout groups its supersets the way its detail sheet does, per routine first, so two routines' exercises paired across a combined session are no longer written as one superset
Duarte Santosda2441795c00
diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.jsindex 97a16fa51..75c198687 100644--- a/frontend/src/lib/history.js+++ b/frontend/src/lib/history.js@@ -665,6 +665,26 @@ export function supersetUnits(items) {return units}+// A saved session's entries in the sections its detail sheet shows: one per routine (by `rid`, in+// the order each first appears), the entries with no routine together, and inside each section its+// superset units. Indexes point into `entries`. A superset never spans two sections — in a combined+// session the last exercise of one routine can be paired with the first of the next, and they are+// read back apart, each under its own routine. The detail sheet and "Copy as text" both group a+// workout through this, so the text never shows a superset the sheet does not.+export function sessionSections(entries) {+ const list = Array.isArray(entries) ? entries : []+ const sections = []+ list.forEach((e, i) => {+ const rid = e?.rid || null+ let section = sections.find(x => x.rid === rid)+ if (!section) { section = { rid, items: [] }; sections.push(section) }+ section.items.push(i)+ })+ return sections.map(({ rid, items }) => ({+ rid, items, units: supersetUnits(items.map(i => list[i])).map(unit => unit.map(k => items[k])),+ }))+}+// Move the selected occurrence's complete display unit by one neighbouring unit. Returning a// new array keeps this helper pure; the caller decides how to persist it. Index identity matters// here because the same exercise id may appear more than once with different setup.diff --git a/frontend/src/lib/history.test.js b/frontend/src/lib/history.test.jsindex 5a91e9a65..0c76f54f7 100644--- a/frontend/src/lib/history.test.js+++ b/frontend/src/lib/history.test.js@@ -1,5 +1,5 @@import { describe, it, expect } from 'vitest'-import { nextTrainingDay, modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, bestWeightFor, bestWeightForEntry, completedRepsOf, metricRowsForEntry, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, removeRowAt, workSetsDone, setsDone, setsDoneActive, setUnits, doneUnits, setUnitsTotal, pairAdjacent, unpairSuperset, supersetUnits, applyIntensifierPlan, pinnedNoteFor, exNoteFor, effectiveRoutineIds, effectiveRoutines, effectiveRoutineId, effectiveRoutine, lastEntryFor, entryExcluded, entryRoutineId, setsRepsOf } from './history.js'+import { nextTrainingDay, modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, bestWeightFor, bestWeightForEntry, completedRepsOf, metricRowsForEntry, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, removeRowAt, workSetsDone, setsDone, setsDoneActive, setUnits, doneUnits, setUnitsTotal, pairAdjacent, unpairSuperset, supersetUnits, sessionSections, applyIntensifierPlan, pinnedNoteFor, exNoteFor, effectiveRoutineIds, effectiveRoutines, effectiveRoutineId, effectiveRoutine, lastEntryFor, entryExcluded, entryRoutineId, setsRepsOf } from './history.js'import { makeSideSet, setSideField, toggleSide, WEIGHT_ORIGIN_MANUAL } from './workout-model.js'import { EXDB } from './exercises.js'@@ -849,6 +849,26 @@ describe('superset editing', () => {})})+// The one grouping the detail sheet and "Copy as text" share: per routine first, supersets inside.+describe('sessionSections', () => {+ it('splits by routine in the order each first appears and pairs supersets only inside a section', () => {+ const entries = [+ { id: 'a', rid: 'A', sg: 'x' }, { id: 'b', rid: 'B', sg: 'x' }, { id: 'c', rid: 'B', sg: 'y' },+ { id: 'd', rid: 'B', sg: 'y' }, { id: 'e', rid: 'A' },+ ]+ expect(sessionSections(entries)).toEqual([+ { rid: 'A', items: [0, 4], units: [[0], [4]] },+ { rid: 'B', items: [1, 2, 3], units: [[1], [2, 3]] },+ ])+ })++ it('keeps a workout without routines as one section, the flat list', () => {+ const entries = [{ id: 'a', sg: 'x' }, { id: 'b', sg: 'x' }, { id: 'c' }]+ expect(sessionSections(entries)).toEqual([{ rid: null, items: [0, 1, 2], units: supersetUnits(entries) }])+ expect(sessionSections(undefined)).toEqual([])+ })+})+describe('superset editing', () => {it('pairs adjacent entries without mutating the source and keeps the display units contiguous', () => {const entries = [{ id: 'a' }, { id: 'b' }, { id: 'c' }]diff --git a/frontend/src/lib/workout-text.js b/frontend/src/lib/workout-text.jsindex dc33c3df1..e1d08baad 100644--- a/frontend/src/lib/workout-text.js+++ b/frontend/src/lib/workout-text.js@@ -2,7 +2,7 @@// ideas'): something to paste into a chat, a coach's spreadsheet or a notes app. The sets are the// same labels the history shows, so a drop-set or a rest-pause set reads the same in both.// i18n-core rather than i18n, like history.js: nothing here needs the React half.-import { setLabel, supersetUnits, workoutVolume } from './history.js'+import { setLabel, sessionSections, workoutVolume } from './history.js'import { EXIDX } from './exercises.js'import { hasCompletedWork, isWarmupRow } from './workout-model.js'import { fmtDate, fmtNum, fmtVol, durPart, capWords } from './format.js'@@ -32,8 +32,10 @@ export function workoutText(w, { unit, nameOf, speedUnit }) {const name = nameOf(entry)return [exerciseNameClass(EXIDX[entry.id]) ? capWords(name) : name, sets.map(s => setLabel(entry.id, s, entry.target, speedUnit)).join(', '), ...(entry.note ? [entry.note] : [])]}+ // Grouped the way the detail sheet groups it (sessionSections): per routine first, so a+ // superset is only ever paired inside one routine's section, in the order the sheet lists them.const entries = w.entries || []- for (const group of supersetUnits(entries)) {+ for (const group of sessionSections(entries).flatMap(section => section.units)) {const members = group.map(i => lines(entries[i])).filter(Boolean)if (!members.length) continueblocks.push([...(members.length > 1 ? [t('Superset')] : []), ...members.flat()].join('\n'))diff --git a/frontend/src/lib/workout-text.test.js b/frontend/src/lib/workout-text.test.jsindex 394675ee7..a09cc4a4d 100644--- a/frontend/src/lib/workout-text.test.js+++ b/frontend/src/lib/workout-text.test.js@@ -56,6 +56,27 @@ describe('workoutText', () => {})})+// A combined session can pair the last exercise of one routine with the first of the next. The+// detail sheet splits the workout by routine first and shows those two apart, each in its own+// section; the copied text paired them over the flat list and wrote "Superset" above them.+describe('workoutText in a combined session', () => {+ const nameOf = e => e.id+ const row = (id, rid, sg) => ({ id, rid, ...(sg ? { sg } : {}), target: { mode: 'reps' }, sets: [{ w: 20, r: 10, done: true }] })+ const at = entries => ({ d: '2026-09-03', start: 0, end: 0, name: 'Push + Pull', vol: 0, routineIds: ['A', 'B'], entries })++ it('pairs a superset only inside one routine\'s section, as the detail sheet does', () => {+ const text = workoutText(at([row('press', 'A'), row('fly', 'A', 'x'), row('row', 'B', 'x'), row('curl', 'B')]), { unit: 'kg', nameOf })+ expect(text).not.toContain('Superset')+ expect(text.split('\n\n').slice(1)).toEqual(['Press\n20×10', 'Fly\n20×10', 'Row\n20×10', 'Curl\n20×10'])+ })++ it('keeps a superset inside one routine together, and lists each routine\'s exercises in its section', () => {+ // the curl was added to routine A late in the session, after routine B's exercises+ const text = workoutText(at([row('press', 'A', 'y'), row('fly', 'A', 'y'), row('row', 'B'), row('curl', 'A')]), { unit: 'kg', nameOf })+ expect(text.split('\n\n').slice(1)).toEqual(['Superset\nPress\n20×10\nFly\n20×10', 'Curl\n20×10', 'Row\n20×10'])+ })+})+// Cardio speed in the profile's unit, as the detail sheet above the button shows it (lib/speed.js).describe('workoutText speed unit', () => {it('writes a run in mph when the profile shows mph, and in km/h by default', () => {diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex 4b31f4faf..e28925426 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -4,7 +4,7 @@ import { useUI } from './store/useUI.js'import { EXDB, EXIDX, BODYPARTS, isCardio, isBodyweightEq, allExercises, equipmentOf, smOf, searchExercises, exOr, isAssisted, betterWeight, beatsWeight } from './lib/exercises.js'import { activeProfile, exAvailable, ALL_EQUIPMENT, newProfile } from './lib/equipment.js'import { fmtDate, fmtNum, capWords, fmtVol, fmtDur, durPart, todayISO, isoOf, uid, exCount, routineCount, DAYN, DAYS, weekOrder, weekStartOf, weekDayOffset, MONTHS_LONG, ACCENTS } from './lib/format.js'-import { lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, effectiveRoutineIds, workoutDay, workoutVolume, setsDone, setsDoneActive, setUnitsTotal, lastBW, supersetUnits, unitOf, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, EFFORT, capEffort, stepEffort, isBw, isPerSide, sideReps, workSetsDone, applyIntensifierPlan, MAX_PLANNED_WARMUPS, NOTE_MAX } from './lib/history.js'+import { lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, effectiveRoutineIds, workoutDay, workoutVolume, setsDone, setsDoneActive, setUnitsTotal, lastBW, supersetUnits, sessionSections, unitOf, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, EFFORT, capEffort, stepEffort, isBw, isPerSide, sideReps, workSetsDone, applyIntensifierPlan, MAX_PLANNED_WARMUPS, NOTE_MAX } from './lib/history.js'import { usesBar, barWeightFor, defaultBarWeight, hasBarOverride, isNoBar } from './lib/bar.js'import { toScale, rirOf, EFFORT_PRESETS, effortColor } from './lib/effort.js'import { beep, vibrate } from './lib/sound.js'@@ -1878,11 +1878,11 @@ function WorkoutDetail({ w, close }) {// Exercises done as a superset stay together under a "Superset" label and one bar, the way the// routine editor shows them (Discord: "supersets aren't shown at all"). Adjacent entries with// the same tag, as in the workout itself; a workout finished before the tag was kept has none.- const entryRows = items => supersetUnits(items.map(([e]) => e)).map(unit => {- if (unit.length < 2) return entryRow(...items[unit[0]])- return <div key={'ss' + items[unit[0]][1]} className="wd-ss">+ const entryRows = units => units.map(unit => {+ if (unit.length < 2) return entryRow(w.entries[unit[0]], unit[0])+ return <div key={'ss' + unit[0]} className="wd-ss"><div className="ss-label"><Icon name="link" />{t('Superset')}</div>- {unit.map(k => entryRow(...items[k]))}+ {unit.map(i => entryRow(w.entries[i], i))}</div>})// Copied with the note as it stands in the box, which may not be saved yet.@@ -1891,32 +1891,29 @@ function WorkoutDetail({ w, close }) {toast(await copyText(workoutText(rec, { unit: st.unit, nameOf, speedUnit: speedUnitOf(st) })) ? t('Copied') : t('Could not copy'))}// A combined session's entries carry a `rid`; group them into per-routine sections in merge- // order. A legacy single-routine workout (one routineIds, or no rid anywhere) renders flat.- const groups = []- w.entries.forEach((e, i) => {- const key = e.rid || '__none'- let g = groups.find(x => x.key === key)- if (!g) { g = { key, rid: e.rid || null, items: [] }; groups.push(g) }- g.items.push([e, i])- })+ // order, with each section's supersets paired inside it (sessionSections, which "Copy as text"+ // reads the workout through too). A legacy single-routine workout (one routineIds, or no rid+ // anywhere) renders flat.+ const groups = sessionSections(w.entries)const grouped = groups.length > 1 || (groups[0] && groups[0].rid && (w.routineIds || []).length > 1)return <><h3>{w.name}</h3><div className="muted small" style={{ marginBottom: 12 }}>{[fmtDate(w.d, true), ...durPart(w.end - w.start), fmtVol(w.vol, st.unit), ...(w.bw ? [fmtNum(w.bw) + ' ' + st.unit] : [])].join(' · ')}</div>{grouped ? groups.map(g => {const r = g.rid ? st.routines.find(x => x.id === g.rid) : null- const setN = g.items.reduce((n, [e]) => n + e.sets.filter(s => s.done && !isWarmupRow(s)).length, 0)- const vol = workoutVolume({ entries: g.items.map(([e]) => e) })- return <div key={g.key}>+ const items = g.items.map(i => w.entries[i])+ const setN = items.reduce((n, e) => n + e.sets.filter(s => s.done && !isWarmupRow(s)).length, 0)+ const vol = workoutVolume({ entries: items })+ return <div key={g.rid || '__none'}><div className="row between" style={{ margin: '2px 0 8px', paddingBottom: 6, borderBottom: '1px solid var(--sep)' }}><div className="row" style={{ gap: 7, fontWeight: 600 }}>{r && <Icon name={glyphOf(r.emoji)} />}{r ? r.name : t('Freestyle')}</div><div className="small dim">{t('{0} sets', setN)} · {fmtVol(vol, st.unit)}</div></div>- {entryRows(g.items)}+ {entryRows(g.units)}</div>- }) : entryRows(w.entries.map((e, i) => [e, i]))}+ }) : entryRows(groups[0]?.units || [])}<div className="small muted" style={{ margin: '4px 0 6px' }}>{t('Session note')}</div><textarea ref={noteRef} className="input" rows={2} maxLength={NOTE_MAX} value={note}placeholder={t('How the session went as a whole.')}diff --git a/frontend/src/sheets.workout-detail.test.jsx b/frontend/src/sheets.workout-detail.test.jsxindex 008db750b..817a2717c 100644--- a/frontend/src/sheets.workout-detail.test.jsx+++ b/frontend/src/sheets.workout-detail.test.jsx@@ -121,6 +121,25 @@ describe('workout detail', () => {expect(toast).toHaveBeenCalledWith('Copied')})+ // One rule for both: a superset paired across two routines of a combined session is shown apart+ // in the sheet, each under its own routine, and the copied text does not call it a superset.+ it('groups a combined session\'s supersets the same way in the sheet and in the copied text', async () => {+ const writeText = vi.fn(() => Promise.resolve())+ vi.stubGlobal('navigator', { ...navigator, clipboard: { writeText } })+ const w = workout([+ { id: lifts[0], rid: 'A', sg: 'x', target: { mode: 'reps' }, sets: [done(40, 10)] },+ { id: lifts[1], rid: 'B', sg: 'x', target: { mode: 'reps' }, sets: [done(20, 12)] },+ { id: lifts[2], rid: 'B', target: { mode: 'reps' }, sets: [done(60, 5)] },+ ], { routineIds: ['A', 'B'] })+ useStore.setState(s => ({ S: { ...s.S, workouts: [w] } }))+ workoutDetailSheet(w)+ const host = mountTopSheet()+ expect(host.querySelector('.wd-ss')).toBeNull()+ expect(host.querySelectorAll('.wd-ex')).toHaveLength(3)+ await act(async () => { button(host, 'Copy as text').click() })+ expect(writeText.mock.calls[0][0]).not.toContain('Superset')+ })+it('says so when the clipboard refuses', async () => {vi.stubGlobal('navigator', { ...navigator, clipboard: { writeText: () => Promise.reject(new Error('denied')) } })document.execCommand = () => false