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 past workout lists its drop-sets and rest-pause bursts, keeps its supersets, opens each exercise's history and copies as text (Discord)
Duarte Santos389ff322c213
diff --git a/frontend/src/index.css b/frontend/src/index.cssindex cdf223e75..61c20c44c 100644--- a/frontend/src/index.css+++ b/frontend/src/index.css@@ -1343,6 +1343,14 @@ body.chips-dragging *{cursor:inherit}}.ss-label .icn{font-size:13px}.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 the+ routine editor's label and bar. */+.wd-ex{margin-bottom:12px;cursor:pointer;border-radius:10px}+.wd-ex>.grow{flex:1;min-width:0}+.wd-ex:active{background:var(--surface-2)}+.wd-ss{box-shadow:inset 3px 0 0 var(--acc);padding-left:11px;margin-bottom:12px}+.wd-ss .ss-label{margin:0 0 8px}+.wd-ss .wd-ex:last-child{margin-bottom:0}.ss-card{border-radius:var(--r-lg);padding:14px;background:var(--surface);box-shadow:inset 0 0 0 1.5px var(--acc-line);diff --git a/frontend/src/lib/clipboard.js b/frontend/src/lib/clipboard.jsnew file mode 100644index 000000000..69b69ba81--- /dev/null+++ b/frontend/src/lib/clipboard.js@@ -0,0 +1,27 @@+// Copies text to the clipboard and says whether it did. The Clipboard API is there in every+// secure context — https, localhost, the native shells' own origins — but a self-hosted server+// reached over plain http on the LAN is not one, and there the old selection copy still works.+export async function copyText(text) {+ try {+ if (navigator.clipboard?.writeText) {+ await navigator.clipboard.writeText(text)+ return true+ }+ } catch { /* refused (no permission, page not focused): the selection copy may still work */ }+ try {+ const area = document.createElement('textarea')+ area.value = text+ area.setAttribute('readonly', '')+ area.style.position = 'fixed'+ area.style.opacity = '0'+ document.body.appendChild(area)+ area.select()+ // iOS selects nothing on select() alone.+ area.setSelectionRange(0, text.length)+ const ok = document.execCommand('copy')+ area.remove()+ return !!ok+ } catch {+ return false+ }+}diff --git a/frontend/src/lib/finish-workout.js b/frontend/src/lib/finish-workout.jsindex 6be02c4a0..efe47780d 100644--- a/frontend/src/lib/finish-workout.js+++ b/frontend/src/lib/finish-workout.js@@ -1,6 +1,6 @@// The persisted boundary for a finished session. Keep this pure so compatibility tests can// exercise the exact shape the UI writes without mounting React or mutating store state.-import { bestWeightForEntry } from './history.js'+import { bestWeightForEntry, cleanupSg } from './history.js'import { hasCompletedWork } from './workout-model.js'export function buildCompletedWorkout(active, { end = Date.now(), prs = [], snapshotFor } = {}) {@@ -18,6 +18,9 @@ export function buildCompletedWorkout(active, { end = Date.now(), prs = [], snap// What the routine asked for when the session was built (session-start.js), next to the// target the prescription moved — how the next session tells an edited plan (#275)....(entry.planned ? { planned: entry.planned } : {}),+ // The superset the exercise was done in, so the history can show the pairing. Without it+ // the workout forgot at finish what it had been all session.+ ...(entry.sg ? { sg: entry.sg } : {}),}const snapshot = typeof snapshotFor === 'function' ? snapshotFor(entry) : nullif (snapshot && typeof snapshot === 'object' && !Array.isArray(snapshot) && Object.keys(snapshot).length) {@@ -33,6 +36,10 @@ export function buildCompletedWorkout(active, { end = Date.now(), prs = [], snap}return completed}).filter(entry => entry.sets.some(hasCompletedWork))+ // An exercise left without a single set drops out above, and its partner is then a superset+ // of one. cleanupSg clears the tag it no longer shares with a neighbour; the entries are this+ // function's own copies, so the running session is left alone.+ cleanupSg(entries)const sessionNote = (active?.note || '').trim()const routineIds = [].concat(active?.routineIds ?? (active?.routineId ? [active.routineId] : []))diff --git a/frontend/src/lib/finish-workout.test.js b/frontend/src/lib/finish-workout.test.jsindex b90870661..a28b2eba9 100644--- a/frontend/src/lib/finish-workout.test.js+++ b/frontend/src/lib/finish-workout.test.js@@ -161,3 +161,34 @@ describe('session notes', () => {expect('note' in buildCompletedWorkout(a)).toBe(false)})})++// Discord (rubik_97): supersets appeared nowhere once the workout was saved, because the finish+// whitelist dropped the group tag every other screen reads them from.+describe('superset groups', () => {+ const done = { w: 40, r: 10, done: true }+ const open = { w: 40, r: 10, done: false }+ const active = entries => ({ id: 'w', d: '2026-09-17', start: 1, routineIds: ['r1'], name: 'Arms', entries })++ it('keeps the group on every member that was trained', () => {+ const w = buildCompletedWorkout(active([+ { id: 'a', sg: 'sg1', sets: [done], target: {} },+ { id: 'b', sg: 'sg1', sets: [done], target: {} },+ { id: 'c', sets: [done], target: {} },+ ]))+ expect(w.entries.map(e => e.sg)).toEqual(['sg1', 'sg1', undefined])+ expect('sg' in w.entries[2]).toBe(false)+ })++ it('drops the tag of a member whose partner was never trained', () => {+ const entries = [+ { id: 'a', sg: 'sg1', sets: [done], target: {} },+ { id: 'b', sg: 'sg1', sets: [open], target: {} },+ { id: 'c', sets: [done], target: {} },+ ]+ const w = buildCompletedWorkout(active(entries))+ expect(w.entries.map(e => e.id)).toEqual(['a', 'c'])+ expect('sg' in w.entries[0]).toBe(false)+ // the running session is not the one tidied up+ expect(entries[0].sg).toBe('sg1')+ })+})diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.jsindex 18316f8e1..274740110 100644--- a/frontend/src/lib/history.js+++ b/frontend/src/lib/history.js@@ -1,7 +1,7 @@// Pure helpers over the state object S (ported 1:1 from the vanilla app).import { todayISO, isoOf, weekKey, weekStartOf, fmtNum } from './format.js'import { isCardio, isBodyweightEq, isAssisted, betterWeight } from './exercises.js'-import { phaseForSet, modeForSet, modeForEntry, isWarmupRow, normalizeMode, completedVolumeOf, nextDropWeight, splitBurstReps, makeSideSet, isSideSet, syncSideAggregate } from './workout-model.js'+import { phaseForSet, modeForSet, modeForEntry, isWarmupRow, normalizeMode, completedVolumeOf, nextDropWeight, splitBurstReps, makeSideSet, isSideSet, syncSideAggregate, dropsOf, clustersOf } from './workout-model.js'const objectOf = value => value && typeof value === 'object' && !Array.isArray(value) ? value : {}// Completed-state-independent work rows whose authoritative mode matches the requested mode.const workRowsForMode = (entry = {}, mode = 'reps') => {@@ -114,11 +114,25 @@ export function setLabel(id, s, cfg) {if (mode === 'cardio') return `${s.min || 0} min @ ${fmtNum(s.speed || 0)} km/h`if (mode === 'time') return fmtSec(s.sec) + (s.w > 0 ? ` · ${fmtNum(s.w)}` : '')const bw = isBw({ ...c, id: c.id ?? id })+ const load = (w, reps) => (bw ? (w > 0 ? `+${fmtNum(w)} × ` : '') + reps : `${fmtNum(w || 0)}×${reps}`)+ // A rest-pause set's reps read as its bursts, "60×10+4+2", the way the protocol is written+ // down. The row's own `r` is the total either way; a planned set's bursts already add up to it+ // (applyIntensifierPlan), while bursts added live sit on top of the activation set, which is+ // then whatever the total leaves over. Bursts that do not fit the total are not shown.+ const repsOf = side => {+ const reps = side.r || 0+ const bursts = clustersOf(side).map(b => Number(b?.r) || 0).filter(r => r > 0)+ const sum = bursts.reduce((a, b) => a + b, 0)+ if (!bursts.length || sum > reps) return reps+ return (reps > sum ? [reps - sum, ...bursts] : bursts).join('+')+ }// One side's "weight×reps" (or bodyweight "reps" / "+belt × reps"), the same shape a whole- // straight set reads as — reused for each side of a unilateral set below.+ // straight set reads as — reused for each side of a unilateral set below. A drop-set's drops+ // follow it ("100×8 ↘ 80×6"): the volume of the workout counts them, so the list has to show+ // them, or the total includes weight nobody can see where it came from.const oneSide = side => {- const reps = side.r || 0- return bw ? (side.w > 0 ? `+${fmtNum(side.w)} × ` : '') + reps : `${fmtNum(side.w || 0)}×${reps}`+ const drops = dropsOf(side).filter(d => (Number(d?.r) || 0) > 0)+ return load(side.w, repsOf(side)) + drops.map(d => ' ↘ ' + load(Number(d.w) || 0, Number(d.r))).join('')}// A unilateral set logged per side (issue #60) reads "L 15×8 · R 15×7" — the asymmetry is the// whole point, so both sides are shown rather than a single combined total.diff --git a/frontend/src/lib/history.test.js b/frontend/src/lib/history.test.jsindex 4177355be..de4ebf323 100644--- a/frontend/src/lib/history.test.js+++ b/frontend/src/lib/history.test.js@@ -92,6 +92,38 @@ describe('setLabel', () => {// and a set that somehow carries both is described once, by the one it was logged withexpect(setLabel(LIFT, { w: 60, r: 10, rir: 2, rpe: 8 })).toBe('60×10 (RIR 2)')})++ // Discord (rubik_97): a drop-set's drops were counted in the workout's volume but never shown,+ // so the history detail listed less weight than its own total added up to.+ it('lists a drop-set\'s drops after the main set, effort last', () => {+ const drop = { w: 100, r: 8, type: 'dropset', drops: [{ w: 80, r: 6 }, { w: 60, r: 5 }] }+ expect(setLabel(LIFT, drop)).toBe('100×8 ↘ 80×6 ↘ 60×5')+ expect(setLabel(LIFT, { ...drop, rir: 0 })).toBe('100×8 ↘ 80×6 ↘ 60×5 (RIR 0)')+ // a drop nobody did (no reps) is not work, and drops on a row that is not a drop-set are stale+ expect(setLabel(LIFT, { w: 100, r: 8, type: 'dropset', drops: [{ w: 80, r: 0 }] })).toBe('100×8')+ expect(setLabel(LIFT, { w: 100, r: 8, type: 'straight', drops: [{ w: 80, r: 6 }] })).toBe('100×8')+ })++ it('writes a rest-pause set as its bursts, adding up to the logged total', () => {+ // bursts added live sit on top of the activation set: 10 + 4 + 2 = 16+ expect(setLabel(LIFT, { w: 60, r: 16, type: 'restpause', clusters: [{ r: 4, restSec: 15 }, { r: 2, restSec: 15 }] })).toBe('60×10+4+2')+ // a planned set's bursts are the whole total already (applyIntensifierPlan)+ expect(setLabel(LIFT, { w: 60, r: 12, type: 'restpause', clusters: [6, 3, 2, 1].map(r => ({ r, restSec: 15 })) })).toBe('60×6+3+2+1')+ // bursts that no longer fit the total (edited by hand) leave just the total+ expect(setLabel(LIFT, { w: 60, r: 5, type: 'restpause', clusters: [{ r: 4 }, { r: 3 }] })).toBe('60×5')+ })++ it('reads drops and bursts of a bodyweight exercise as reps and added weight', () => {+ const cfg = { id: BW, bodyweight: true }+ expect(setLabel(BW, { w: 10, r: 8, type: 'dropset', drops: [{ w: 0, r: 5 }] }, cfg)).toBe('+10 × 8 ↘ 5')+ expect(setLabel(BW, { w: 0, r: 12, type: 'restpause', clusters: [{ r: 3 }] }, cfg)).toBe('9+3')+ })++ it('shows each side\'s own drops on a unilateral drop-set', () => {+ const side = (w, r, drops) => ({ w, r, done: true, type: 'dropset', drops })+ const s = { w: 20, r: 16, done: true, type: 'dropset', sides: { L: side(20, 8, [{ w: 15, r: 6 }]), R: side(20, 8, [{ w: 15, r: 5 }]) } }+ expect(setLabel(LIFT, s, { id: LIFT, side: true })).toBe('L 20×8 ↘ 15×6 · R 20×8 ↘ 15×5')+ })})describe('effortOf', () => {diff --git a/frontend/src/lib/pt-br-locale.test.js b/frontend/src/lib/pt-br-locale.test.jsindex 680046ae9..3f80bff04 100644--- a/frontend/src/lib/pt-br-locale.test.js+++ b/frontend/src/lib/pt-br-locale.test.js@@ -28,10 +28,10 @@ describe('Brazilian Portuguese locale', () => {const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(679)- expect(inherited).toHaveLength(674)+ expect(inherited).toHaveLength(677)// If this fails, review the changed keys and wording before accepting a new hash. From// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list- expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('f81cca4b7e73e229526217b8a3825069ee65fb6a5586c143b324038f99499f75')+ expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('adbf617a0fd3e071a7637df853ed0937d010d1ee9e4bb2cee4286dd4ed88b469')})test('does not leak European Portuguese UI terms', () => {diff --git a/frontend/src/lib/unilateral-integration.test.js b/frontend/src/lib/unilateral-integration.test.jsindex 7b5e5b559..504452dd0 100644--- a/frontend/src/lib/unilateral-integration.test.js+++ b/frontend/src/lib/unilateral-integration.test.js@@ -78,7 +78,8 @@ describe('unilateral sets across session boundaries', () => {expect(completed.entries[0].sets[0]).toEqual(s)expect(setsDone(completed)).toBe(1)expect(workoutVolume(completed)).toBe(20 * 8 + 16 * 8)- expect(setLabel('0025', s, entry(s).target)).toBe('L 20×8 · R —')+ // the drop the volume counts is on the label too (Discord: drop-sets missing from history)+ expect(setLabel('0025', s, entry(s).target)).toBe('L 20×8 ↘ 16×8 · R —')expect(workoutVolume({ entries: [entry({ ...s, phase: 'warmup' })] })).toBe(0)})diff --git a/frontend/src/lib/workout-text.js b/frontend/src/lib/workout-text.jsnew file mode 100644index 000000000..d4338187c--- /dev/null+++ b/frontend/src/lib/workout-text.js@@ -0,0 +1,38 @@+// A finished workout as plain text, for "Copy as text" in its detail sheet (Discord 'Improvement+// 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 { hasCompletedWork, isWarmupRow } from './workout-model.js'+import { fmtDate, fmtNum, fmtVol, durPart, capWords } from './format.js'+import { t } from './i18n-core.js'++/**+ * `unit` is the profile's, `nameOf(entry)` the exercise's display name. Blocks are separated by+ * a blank line: the heading, then each exercise (a superset's under one "Superset" line, its+ * members together), then the session note.+ */+export function workoutText(w, { unit, nameOf }) {+ const facts = [+ ...durPart((w.end || 0) - (w.start || 0)),+ fmtVol(w.vol ?? workoutVolume(w), unit),+ ...(w.bw ? [t('Body weight') + ' ' + fmtNum(w.bw) + ' ' + unit] : []),+ ]+ const blocks = [[[w.name, fmtDate(w.d, true, true)].filter(Boolean).join(' — '), facts.join(' · ')].join('\n')]+ // Work sets only: the text is what you trained, the work the volume above counts. Warm-ups are+ // left out of volume, records and progression everywhere else, and listed here with nothing to+ // tell them apart they would read as sets of their own.+ const lines = entry => {+ const sets = (entry.sets || []).filter(s => hasCompletedWork(s) && !isWarmupRow(s))+ if (!sets.length) return null+ return [capWords(nameOf(entry)), sets.map(s => setLabel(entry.id, s, entry.target)).join(', '), ...(entry.note ? [entry.note] : [])]+ }+ const entries = w.entries || []+ for (const group of supersetUnits(entries)) {+ const members = group.map(i => lines(entries[i])).filter(Boolean)+ if (!members.length) continue+ blocks.push([...(members.length > 1 ? [t('Superset')] : []), ...members.flat()].join('\n'))+ }+ if (w.note) blocks.push(w.note)+ return blocks.join('\n\n')+}diff --git a/frontend/src/lib/workout-text.test.js b/frontend/src/lib/workout-text.test.jsnew file mode 100644index 000000000..fbe91afd4--- /dev/null+++ b/frontend/src/lib/workout-text.test.js@@ -0,0 +1,57 @@+import { describe, expect, it } from 'vitest'+import { workoutText } from './workout-text.js'+import { fmtDate } from './format.js'++// Discord 'Improvement ideas': a past workout copied as plain text to paste anywhere.+describe('workoutText', () => {+ const names = { bench: 'barbell bench press', curl: 'dumbbell curl', pushdown: 'cable pushdown', run: 'run' }+ const nameOf = e => names[e.id] || e.id+ const w = {+ id: 'w1', d: '2026-09-03', start: 0, end: 58 * 60000, name: 'Push', vol: 1790, bw: 80,+ note: 'Felt strong.',+ entries: [+ { id: 'bench', target: { mode: 'reps' }, note: 'narrower grip', sets: [+ { w: 40, r: 8, done: true, phase: 'warmup' },+ { w: 60, r: 8, done: true },+ { w: 60, r: 6, done: true, type: 'dropset', drops: [{ w: 45, r: 6 }] },+ { w: 60, r: 8, done: false },+ ] },+ { id: 'curl', sg: 'sg1', target: { mode: 'reps' }, sets: [{ w: 12, r: 10, done: true }] },+ { id: 'pushdown', sg: 'sg1', target: { mode: 'reps' }, sets: [{ w: 20, r: 12, done: true }] },+ { id: 'run', target: { mode: 'cardio' }, sets: [{ min: 20, speed: 10, done: true }] },+ ],+ }++ it('reads as the heading, each exercise with its work sets, supersets together, then the note', () => {+ expect(workoutText(w, { unit: 'kg', nameOf })).toBe([+ `Push — ${fmtDate('2026-09-03', true, true)}`,+ '58 min · 1,790 kg · Body weight 80 kg',+ '',+ 'Barbell Bench Press',+ '60×8, 60×6 ↘ 45×6',+ 'narrower grip',+ '',+ 'Superset',+ 'Dumbbell Curl',+ '12×10',+ 'Cable Pushdown',+ '20×12',+ '',+ 'Run',+ '20 min @ 10 km/h',+ '',+ 'Felt strong.',+ ].join('\n'))+ })++ it('leaves out what was not trained and what was never recorded', () => {+ const bare = { d: '2026-09-03', start: 5, end: 5, name: 'Legs', entries: [+ { id: 'bench', target: { mode: 'reps' }, sets: [{ w: 40, r: 8, done: true, phase: 'warmup' }] },+ { id: 'curl', sg: 'sg1', target: { mode: 'reps' }, sets: [{ w: 12, r: 10, done: true }] },+ { id: 'pushdown', sg: 'sg1', target: { mode: 'reps' }, sets: [{ w: 20, r: 12, done: false }] },+ ] }+ // no clock, no weigh-in, no note; an exercise with only a warm-up drops out, and a superset+ // with one member left trained is just that exercise+ expect(workoutText(bare, { unit: 'lb', nameOf })).toBe(`Legs — ${fmtDate('2026-09-03', true, true)}\n120 lb\n\nDumbbell Curl\n12×10`)+ })+})diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.jsindex d736fc60a..b96973f9d 100644--- a/frontend/src/locales/de.js+++ b/frontend/src/locales/de.js@@ -1320,4 +1320,8 @@ export default {'Plan: {0}': 'Plan: {0}','today {0}': 'heute {0}','reps from your last session': 'Wdh. aus deiner letzten Einheit',+ // --- a past workout: drop-sets, supersets, its exercises' history, copy as text ---+ 'Copy as text': 'Als Text kopieren',+ 'Copied': 'Kopiert',+ 'Could not copy': 'Kopieren nicht möglich',}diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.jsindex 5764277a7..36e652f36 100644--- a/frontend/src/locales/es.js+++ b/frontend/src/locales/es.js@@ -1300,4 +1300,8 @@ export default {'Plan: {0}': 'Plan: {0}','today {0}': 'hoy {0}','reps from your last session': 'reps de tu última sesión',+ // --- a past workout: drop-sets, supersets, its exercises' history, copy as text ---+ 'Copy as text': 'Copiar como texto',+ 'Copied': 'Copiado',+ 'Could not copy': 'No se pudo copiar',}diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.jsindex 277c4dbc0..30cd4b2f4 100644--- a/frontend/src/locales/fr.js+++ b/frontend/src/locales/fr.js@@ -1300,4 +1300,8 @@ export default {'Plan: {0}': 'Plan : {0}','today {0}': 'aujourd’hui {0}','reps from your last session': 'reps de ta dernière séance',+ // --- a past workout: drop-sets, supersets, its exercises' history, copy as text ---+ 'Copy as text': 'Copier en texte',+ 'Copied': 'Copié',+ 'Could not copy': 'Copie impossible',}diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.jsindex 303289210..5b286402c 100644--- a/frontend/src/locales/hi.js+++ b/frontend/src/locales/hi.js@@ -1300,4 +1300,8 @@ export default {'Plan: {0}': 'प्लान: {0}','today {0}': 'आज {0}','reps from your last session': 'रेप्स आपके पिछले सेशन से',+ // --- a past workout: drop-sets, supersets, its exercises' history, copy as text ---+ 'Copy as text': 'टेक्स्ट के रूप में कॉपी करें',+ 'Copied': 'कॉपी हो गया',+ 'Could not copy': 'कॉपी नहीं हो सका',}diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.jsindex 28c1a24a8..7f32cff99 100644--- a/frontend/src/locales/hu.js+++ b/frontend/src/locales/hu.js@@ -1303,4 +1303,8 @@ export default {'Plan: {0}': 'Terv: {0}','today {0}': 'ma {0}','reps from your last session': 'ismétlések az utolsó edzésedből',+ // --- a past workout: drop-sets, supersets, its exercises' history, copy as text ---+ 'Copy as text': 'Másolás szövegként',+ 'Copied': 'Kimásolva',+ 'Could not copy': 'Nem sikerült másolni',}diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.jsindex 65fbe048b..8b61b74b3 100644--- a/frontend/src/locales/it.js+++ b/frontend/src/locales/it.js@@ -1300,4 +1300,8 @@ export default {'Plan: {0}': 'Piano: {0}','today {0}': 'oggi {0}','reps from your last session': 'rip. dalla tua ultima sessione',+ // --- a past workout: drop-sets, supersets, its exercises' history, copy as text ---+ 'Copy as text': 'Copia come testo',+ 'Copied': 'Copiato',+ 'Could not copy': 'Impossibile copiare',}diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.jsindex 9018a95d3..954a8febf 100644--- a/frontend/src/locales/ko.js+++ b/frontend/src/locales/ko.js@@ -1300,4 +1300,8 @@ export default {'Plan: {0}': '계획: {0}','today {0}': '오늘 {0}','reps from your last session': '지난 세션의 횟수',+ // --- a past workout: drop-sets, supersets, its exercises' history, copy as text ---+ 'Copy as text': '텍스트로 복사',+ 'Copied': '복사됨',+ 'Could not copy': '복사할 수 없음',}diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.jsindex 668ec24b2..610867b49 100644--- a/frontend/src/locales/pl.js+++ b/frontend/src/locales/pl.js@@ -1300,4 +1300,8 @@ export default {'Plan: {0}': 'Plan: {0}','today {0}': 'dziś {0}','reps from your last session': 'powt. z ostatniej sesji',+ // --- a past workout: drop-sets, supersets, its exercises' history, copy as text ---+ 'Copy as text': 'Kopiuj jako tekst',+ 'Copied': 'Skopiowano',+ 'Could not copy': 'Nie udało się skopiować',}diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.jsindex fb5d3ef38..9b89e6870 100644--- a/frontend/src/locales/pt.js+++ b/frontend/src/locales/pt.js@@ -1300,4 +1300,8 @@ export default {'Plan: {0}': 'Plano: {0}','today {0}': 'hoje {0}','reps from your last session': 'reps da tua última sessão',+ // --- a past workout: drop-sets, supersets, its exercises' history, copy as text ---+ 'Copy as text': 'Copiar como texto',+ 'Copied': 'Copiado',+ 'Could not copy': 'Não foi possível copiar',}diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.jsindex 9bfac9658..110c32a88 100644--- a/frontend/src/locales/ru.js+++ b/frontend/src/locales/ru.js@@ -1300,4 +1300,8 @@ export default {'Plan: {0}': 'План: {0}','today {0}': 'сегодня {0}','reps from your last session': 'повт. с прошлой тренировки',+ // --- a past workout: drop-sets, supersets, its exercises' history, copy as text ---+ 'Copy as text': 'Скопировать как текст',+ 'Copied': 'Скопировано',+ 'Could not copy': 'Не удалось скопировать',}diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.jsindex 952e70287..c2c53f256 100644--- a/frontend/src/locales/th.js+++ b/frontend/src/locales/th.js@@ -1311,4 +1311,8 @@ export default {'Plan: {0}': 'แผน: {0}','today {0}': 'วันนี้ {0}','reps from your last session': 'จำนวนครั้งจากเซสชันล่าสุด',+ // --- a past workout: drop-sets, supersets, its exercises' history, copy as text ---+ 'Copy as text': 'คัดลอกเป็นข้อความ',+ 'Copied': 'คัดลอกแล้ว',+ 'Could not copy': 'คัดลอกไม่ได้',}diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.jsindex 6f0a9eca2..6809101e6 100644--- a/frontend/src/locales/tr.js+++ b/frontend/src/locales/tr.js@@ -1300,4 +1300,8 @@ export default {'Plan: {0}': 'Plan: {0}','today {0}': 'bugün {0}','reps from your last session': 'tekrarlar son seansından',+ // --- a past workout: drop-sets, supersets, its exercises' history, copy as text ---+ 'Copy as text': 'Metin olarak kopyala',+ 'Copied': 'Kopyalandı',+ 'Could not copy': 'Kopyalanamadı',}diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.jsindex 5ad7f7998..80a16a028 100644--- a/frontend/src/locales/zh.js+++ b/frontend/src/locales/zh.js@@ -1300,4 +1300,8 @@ export default {'Plan: {0}': '计划:{0}','today {0}': '今天 {0}','reps from your last session': '次数沿用上次训练',+ // --- a past workout: drop-sets, supersets, its exercises' history, copy as text ---+ 'Copy as text': '复制为文本',+ 'Copied': '已复制',+ 'Could not copy': '无法复制',}diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex 90871a73a..a460f7f8d 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -37,6 +37,8 @@ import { isFav, toggleFav, sortFavouritesFirst } from './lib/favourites.js'import { buildSessionEntries, buildPlannedEntry } from './lib/session-start.js'import { buildCombinedEntries, deriveSessionName } from './lib/session-merge.js'import { workoutsOn, backfillStart, backfillEnd, completeBackfill } from './lib/backfill.js'+import { workoutText } from './lib/workout-text.js'+import { copyText } from './lib/clipboard.js'const S = () => useStore.getState().Sconst update = (...a) => useStore.getState().update(...a)@@ -1696,19 +1698,38 @@ function WorkoutDetail({ w, close }) {if (text) rec.note = text; else delete rec.note})}, [])- // 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 nameOf = e => (EXIDX[e.id] ? exerciseNameFor(EXIDX[e.id]) : (e.n || e.id))+ // Tapping an exercise opens its history (Discord 'Improvement ideas'): from one session to the+ // curve it sits on, which is the question a past workout raises most often.const entryRow = (e, i) => {const ex = EXIDX[e.id]- return <div key={i} className="row" style={{ marginBottom: 12, alignItems: 'flex-start' }}>+ return <div key={i} className="row wd-ex" style={{ alignItems: 'flex-start' }} {...tappable(() => exerciseHistorySheet(e.id))}>{ex && <Thumb ex={ex} />}- <div className="grow"><div className="tt capitalize" style={{ fontWeight: 600 }}>{ex ? exerciseNameFor(ex) : (e.n || e.id)} {w.prs && w.prs.includes(e.id) && <span className="pr"><Icon name="trophy" />PR</span>}</div>+ <div className="grow"><div className="tt capitalize" style={{ fontWeight: 600 }}>{nameOf(e)} {w.prs && w.prs.includes(e.id) && <span className="pr"><Icon name="trophy" />PR</span>}</div><div className="ss">{e.sets.filter(hasCompletedWork).map(s => setLabel(e.id, s, e.target)).join(' · ') || t('no sets')}</div>{e.note && <div className="small dim" style={{ marginTop: 3 }}>{e.notePin && <Icon name="flag" style={{ fontSize: 12, marginRight: 4, verticalAlign: '-1px', color: 'var(--yellow)' }} />}{e.note}</div>}</div>+ <Icon name="chevronRight" className="chev" style={{ alignSelf: 'center' }} />+ </div>+ }+ // 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">+ <div className="ss-label"><Icon name="link" />{t('Superset')}</div>+ {unit.map(k => entryRow(...items[k]))}</div>+ })+ // Copied with the note as it stands in the box, which may not be saved yet.+ const copyAsText = async () => {+ const rec = { ...(st.workouts.find(x => x.id === w.id) || w), note: note.trim() }+ toast(await copyText(workoutText(rec, { unit: st.unit, nameOf })) ? 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'@@ -1731,14 +1752,16 @@ function WorkoutDetail({ w, close }) {</div><div className="small dim">{t('{0} sets', setN)} · {fmtVol(vol, st.unit)}</div></div>- {g.items.map(([e, i]) => entryRow(e, i))}+ {entryRows(g.items)}</div>- }) : w.entries.map((e, i) => entryRow(e, i))}+ }) : entryRows(w.entries.map((e, i) => [e, i]))}<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.')}onFocus={onNoteFocus} onChange={e => setNote(e.target.value)} onBlur={saveNote} /><div style={{ height: 14 }} />+ <Button icon="clipboard" onClick={copyAsText}>{t('Copy as text')}</Button>+ <div style={{ height: 8 }} /><Button variant="danger" onClick={() => confirmSheet({ title: t('Delete workout?'), message: t('This removes it from your history for good.'), confirmText: t('Delete'), danger: true, onConfirm: () => { update(s => { s.workouts = s.workouts.filter(x => x.id !== w.id) }); close(); toast(t('Workout deleted')) } })}>{t('Delete workout')}</Button></>}diff --git a/frontend/src/sheets.workout-detail.test.jsx b/frontend/src/sheets.workout-detail.test.jsxnew file mode 100644index 000000000..008db750b--- /dev/null+++ b/frontend/src/sheets.workout-detail.test.jsx@@ -0,0 +1,133 @@+// @vitest-environment happy-dom+// A past workout's detail sheet. Discord (rubik_97): drop-set weights were counted in the volume+// but never listed, and supersets were not shown at all. Discord 'Improvement ideas': an exercise+// opens its own history from here, and the workout can be copied as text.+import React, { act } from 'react'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { createRoot } from 'react-dom/client'+import { DEF, useStore } from './store/useStore.js'+import { useUI } from './store/useUI.js'+import { workoutDetailSheet } from './sheets.jsx'+import { EXDB } from './lib/exercises-data.js'++const lifts = EXDB.filter(e => e.bp !== 'cardio' && e.eq === 'barbell').slice(0, 3).map(e => e.id)+const clone = v => JSON.parse(JSON.stringify(v))+const mounted = []++function mountTopSheet() {+ const sheet = useUI.getState().sheets.at(-1)+ const host = document.createElement('div')+ document.body.appendChild(host)+ const root = createRoot(host)+ mounted.push(root)+ act(() => root.render(sheet.render(() => useUI.getState().closeSheet(sheet.id))))+ return host+}+const button = (host, text) => [...host.querySelectorAll('button')].find(b => b.textContent.trim() === text)++const workout = (entries, extra = {}) => ({+ id: 'w1', d: '2026-09-15', start: Date.UTC(2026, 8, 15, 17), end: Date.UTC(2026, 8, 15, 18), name: 'Push',+ vol: 0, prs: [], routineIds: [], entries, ...extra,+})+const done = (w, r, more = {}) => ({ w, r, done: true, ...more })++let toast+beforeEach(() => {+ globalThis.IS_REACT_ACT_ENVIRONMENT = true+ toast = vi.fn()+ useUI.setState({ sheets: [], toast })+ const S = clone(DEF)+ Object.assign(S, { unit: 'kg', routines: [], workouts: [], active: null })+ useStore.setState({ S, user: null })+ document.body.innerHTML = ''+})+afterEach(() => {+ act(() => { mounted.splice(0).forEach(root => root.unmount()) })+ vi.unstubAllGlobals()+})++describe('workout detail', () => {+ it('lists a drop-set\'s drops and a rest-pause set\'s bursts', () => {+ workoutDetailSheet(workout([+ { id: lifts[0], target: { mode: 'reps' }, sets: [done(100, 8, { type: 'dropset', drops: [{ w: 80, r: 6 }, { w: 60, r: 5 }] })] },+ { id: lifts[1], target: { mode: 'reps' }, sets: [done(60, 16, { type: 'restpause', clusters: [{ r: 4, restSec: 15 }, { r: 2, restSec: 15 }] })] },+ ]))+ const rows = [...mountTopSheet().querySelectorAll('.wd-ex .ss')].map(el => el.textContent)+ expect(rows).toEqual(['100×8 ↘ 80×6 ↘ 60×5', '60×10+4+2'])+ })++ it('keeps a superset together under one label, in a flat and in a combined workout', () => {+ const entries = [+ { id: lifts[0], sg: 'sg1', target: { mode: 'reps' }, sets: [done(40, 10)] },+ { id: lifts[1], sg: 'sg1', target: { mode: 'reps' }, sets: [done(20, 12)] },+ { id: lifts[2], target: { mode: 'reps' }, sets: [done(60, 5)] },+ ]+ workoutDetailSheet(workout(entries))+ let host = mountTopSheet()+ let groups = host.querySelectorAll('.wd-ss')+ expect(groups).toHaveLength(1)+ expect(groups[0].querySelector('.ss-label').textContent).toBe('Superset')+ expect(groups[0].querySelectorAll('.wd-ex')).toHaveLength(2)+ expect(host.querySelectorAll('.wd-ex')).toHaveLength(3)++ useUI.setState({ sheets: [] })+ const combined = entries.map((e, i) => ({ ...e, rid: i < 2 ? 'A' : 'B' }))+ workoutDetailSheet(workout(combined, { routineIds: ['A', 'B'] }))+ host = mountTopSheet()+ expect(host.textContent).toContain('Freestyle') // routines since deleted+ expect(host.querySelectorAll('.wd-ss .wd-ex')).toHaveLength(2)+ })++ it('shows an unpaired exercise without a superset label', () => {+ workoutDetailSheet(workout([+ { id: lifts[0], sg: 'sg1', target: { mode: 'reps' }, sets: [done(40, 10)] },+ { id: lifts[1], target: { mode: 'reps' }, sets: [done(20, 12)] },+ ]))+ expect(mountTopSheet().querySelector('.wd-ss')).toBeNull()+ })++ it('opens the exercise\'s history from its row', () => {+ const w = workout([{ id: lifts[0], target: { mode: 'reps' }, sets: [done(60, 5)] }])+ useStore.setState(s => ({ S: { ...s.S, workouts: [w] } }))+ workoutDetailSheet(w)+ const row = mountTopSheet().querySelector('.wd-ex')+ expect(row.getAttribute('role')).toBe('button')+ act(() => { row.click() })+ expect(useUI.getState().sheets).toHaveLength(2)+ const history = mountTopSheet()+ expect(history.textContent).toContain('Exercise history')+ expect(history.textContent).toContain('60×5')+ })++ it('copies the workout as text, with the note as it stands in the box', async () => {+ const writeText = vi.fn(() => Promise.resolve())+ vi.stubGlobal('navigator', { ...navigator, clipboard: { writeText } })+ const w = workout([{ id: lifts[0], target: { mode: 'reps' }, sets: [done(60, 5, { phase: 'warmup' }), done(80, 5)] }])+ useStore.setState(s => ({ S: { ...s.S, workouts: [w] } }))+ workoutDetailSheet(w)+ const host = mountTopSheet()+ const note = host.querySelector('textarea')+ act(() => {+ Object.getOwnPropertyDescriptor(note.constructor.prototype, 'value').set.call(note, 'Good day')+ note.dispatchEvent(new Event('input', { bubbles: true }))+ })+ await act(async () => { button(host, 'Copy as text').click() })+ expect(writeText).toHaveBeenCalledTimes(1)+ const text = writeText.mock.calls[0][0]+ expect(text.split('\n')[0]).toMatch(/^Push — /)+ expect(text).toContain('\n80×5\n')+ expect(text).not.toContain('60×5')+ expect(text.endsWith('\n\nGood day')).toBe(true)+ expect(toast).toHaveBeenCalledWith('Copied')+ })++ it('says so when the clipboard refuses', async () => {+ vi.stubGlobal('navigator', { ...navigator, clipboard: { writeText: () => Promise.reject(new Error('denied')) } })+ document.execCommand = () => false+ workoutDetailSheet(workout([{ id: lifts[0], target: { mode: 'reps' }, sets: [done(60, 5)] }]))+ const host = mountTopSheet()+ await act(async () => { button(host, 'Copy as text').click() })+ expect(toast).toHaveBeenCalledWith('Could not copy')+ delete document.execCommand+ })+})