From e737954e37fe0634d23ea2863ae404f91e3a2d1d Mon Sep 17 00:00:00 2001 From: Ameer Khan Date: Tue, 25 Aug 2026 15:21:19 +0000 Subject: [PATCH 01/13] Import: resolve Hevy exercise names instead of inventing customs Hevy writes the equipment in parentheses and says "bicep"/"chest fly" where the catalogue says "biceps"/"fly", so the word-bag matcher landed one word off. A real 34-session export arrived with 27 custom exercises covering a third of its sets. Three separate causes: - SYN rewrote 'machine' -> 'lever' before 'smith machine' -> 'smith' could ever fire, so every Smith-machine name became "smith lever ..." and matched nothing in the catalogue. The two rules are order dependent; 'smith machine' now runs first. - The alias table had no entry for Hevy's vocabulary. Added the names from a real export, mapped by hand to catalogue ids. - Hevy exports no category column, so every invented exercise took the 'upper legs' default and a third of an imported history was attributed to the legs in the muscle map. With no category to read, the body part now comes off the name instead. The same export now creates 2 custom exercises instead of 27. The two that remain, box jump and wall ball, are genuinely not in a 1,324-entry strength catalogue, and guessing would file them under the wrong lift. import-match.test.js covers the new aliases, the SYN ordering and the body-part inference. --- frontend/src/lib/import-csv.js | 43 +++++++++++++++++- frontend/src/lib/import-match.test.js | 63 ++++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/import-csv.js b/frontend/src/lib/import-csv.js index 1cf2402..282f0bb 100644 --- a/frontend/src/lib/import-csv.js +++ b/frontend/src/lib/import-csv.js @@ -111,7 +111,9 @@ export function detectSource(header) { const SYN = [ [/\bbb\b/g, 'barbell'], [/\bdb\b/g, 'dumbbell'], [/\bkb\b/g, 'kettlebell'], [/\bohp\b/g, 'overhead press'], [/\bbw\b/g, 'body weight'], [/\bbodyweight\b/g, 'body weight'], - [/\bmachine\b/g, 'lever'], [/\bsmith machine\b/g, 'smith'], [/\bez bar\b/g, 'ez barbell'], + // 'smith machine' first: the generic machine->lever rule would otherwise eat the word + // and leave 'smith lever', which matches no entry in the dataset. + [/\bsmith machine\b/g, 'smith'], [/\bmachine\b/g, 'lever'], [/\bez bar\b/g, 'ez barbell'], [/\bpull ups?\b/g, 'pull up'], [/\bchin ups?\b/g, 'chin up'], [/\bpush ups?\b/g, 'push up'], [/\bsit ups?\b/g, 'sit up'], [/\bdips?\b/g, 'dip'], [/\braises?\b/g, 'raise'], [/\bcurls?\b/g, 'curl'], [/\bpresses\b/g, 'press'], [/\bextensions?\b/g, 'extension'], @@ -185,6 +187,25 @@ const ALIAS_EX = { // same movement, wrong equipment label, which beats leaving it uncategorised. 'pallof press': '0979', 'cable pallof press': '0979', 'vertical pallof press': '1015', 'cable core pallof press': '0979', 'core pallof press': '0979', + // Hevy's own vocabulary, from a real export. Hevy writes the equipment in parentheses + // and uses "bicep"/"chest fly"/"reverse fly" where the dataset says "biceps"/"fly"/ + // "reverse fly", so these are near-misses the word-bag cannot close on its own. + 'bicep curl (dumbbell)': '0294', 'bicep curl (cable)': '0868', 'bicep curl (barbell)': '0031', + 'chest fly (dumbbell)': '0308', 'chest fly (machine)': '0596', 'butterfly (pec deck)': '0596', + 'incline chest fly (dumbbell)': '0319', 'cable fly crossovers': '1269', + 'rear delt reverse fly (dumbbell)': '0383', 'rear delt reverse fly (machine)': '0602', + 'chest supported reverse fly (dumbbell)': '0383', + 'bench press (smith machine)': '0748', 'overhead press (smith machine)': '0766', + 'hack squat (machine)': '0743', 'iso-lateral row (machine)': '0571', + 'seated cable row - bar grip': '0218', 'reverse grip lat pulldown (cable)': '0673', + 'single arm lateral raise (cable)': '0192', 'plate front raise': '0310', + 'back extension (weighted hyperextension)': '0573', + 'behind the back bicep wrist curl (barbell)': '0104', + // A face pull is a rope rear-delt row; the dataset has no entry under that name. + 'face pull': '0203', + // Cardio again: the only candidates in a 29-entry cardio vocabulary. + 'jumping jack': '3220', 'jumping jacks': '3220', 'battle ropes': '0128', + 'stair machine (steps)': '2311', 'stair machine': '2311', } let ALIAS_IDX = null @@ -230,6 +251,23 @@ export function matchExercise(name) { return ties === 1 ? best : null } +// Hevy exports no category column, so every invented exercise fell through to the +// 'upper legs' default and a third of an imported history was attributed to the legs in +// the muscle map. When there is no category, read the body part off the name instead. +const NAME_BP = [ + [/\b(curl|bicep|biceps|tricep|triceps|skullcrusher|pushdown)\b/, 'upper arms'], + [/\b(wrist|forearm|forearms|grip)\b/, 'lower arms'], + [/\b(bench|chest|pec|fly|flye|crossover|crossovers|dip)\b/, 'chest'], + [/\b(row|pulldown|pullup|pull up|chin up|lat|lats|back|deadlift|shrug)\b/, 'back'], + [/\b(shoulder|delt|delts|overhead|lateral raise|front raise|face pull|press up)\b/, 'shoulders'], + [/\b(calf|calves)\b/, 'lower legs'], + [/\b(squat|lunge|leg|glute|hamstring|quad|hip thrust|deadlift)\b/, 'upper legs'], + [/\b(ab|abs|core|plank|crunch|sit up|oblique|russian twist)\b/, 'waist'], + [/\b(run|running|jog|bike|cycling|rope|ropes|jump|jacks|burpee|sprint|treadmill|stair)\b/, 'cardio'], + [/\bneck\b/, 'neck'], +] +const bpFromName = name => (NAME_BP.find(([re]) => re.test(name)) || [])[1] || null + // Categories the exporters use -> the dataset's body parts, for exercises we invent. const CATEGORY_BP = { chest: 'chest', back: 'back', lats: 'back', shoulders: 'shoulders', delts: 'shoulders', @@ -358,7 +396,8 @@ export function parseWorkoutCSV(text, { unit = 'kg' } = {}) { if (!c) { c = { id: 'im' + uid(), n: name.toLowerCase(), custom: true, eq: 'custom', tg: '', desc: '', - bp: CATEGORY_BP[cell(r, 'category').toLowerCase()] || (km || (mins && !reps) ? 'cardio' : 'upper legs'), + bp: CATEGORY_BP[cell(r, 'category').toLowerCase()] || (km || (mins && !reps) ? 'cardio' : null) + || bpFromName(name.toLowerCase()) || 'upper legs', } created.set(key, c) unmatched.add(name) diff --git a/frontend/src/lib/import-match.test.js b/frontend/src/lib/import-match.test.js index 631b667..2febc5f 100644 --- a/frontend/src/lib/import-match.test.js +++ b/frontend/src/lib/import-match.test.js @@ -1,5 +1,5 @@ import { describe, it, expect } from 'vitest' -import { matchExercise } from './import-csv.js' +import { matchExercise, parseWorkoutCSV } from './import-csv.js' import { EXIDX } from './exercises.js' // The names other apps actually export, and the catalogue entry each has to land on. @@ -12,6 +12,20 @@ const MAPS = { 'Cable Core Pallof Press': '0979', Elliptical: '2141', 'Stationary Bike': '2138', + // Hevy's vocabulary, from a real export. It writes the equipment in parentheses and says + // "bicep"/"chest fly" where the catalogue says "biceps"/"fly", so the word-bag lands one + // word off on every one of these and they arrived as custom exercises. + 'Bicep Curl (Dumbbell)': '0294', + 'Bicep Curl (Cable)': '0868', + 'Chest Fly (Machine)': '0596', + 'Butterfly (Pec Deck)': '0596', + 'Incline Chest Fly (Dumbbell)': '0319', + 'Rear Delt Reverse Fly (Dumbbell)': '0383', + 'Face Pull': '0203', + 'Battle Ropes': '0128', + 'Hack Squat (Machine)': '0743', + 'Seated Cable Row - Bar Grip': '0218', + 'Single Arm Lateral Raise (Cable)': '0192', } describe('foreign exercise names resolve to the catalogue', () => { @@ -43,8 +57,55 @@ describe('foreign exercise names resolve to the catalogue', () => { expect(matchExercise('Deadlift')).toBe('0032') }) + // SYN rewrote 'machine' -> 'lever' before it ever reached 'smith machine' -> 'smith', + // so every Smith-machine name arrived as "smith lever ..." and could not match anything + // in the catalogue. The two rules are order-dependent; this pins the order. + it('resolves Smith-machine names rather than leaving a stray "lever"', () => { + expect(matchExercise('Bench Press (Smith Machine)')).toBe('0748') + expect(matchExercise('Overhead Press (Smith Machine)')).toBe('0766') + expect(matchExercise('Smith Machine Bench Press')).toBe('0748') + }) + + // The generic machine -> lever rule still has to work on its own. + it('keeps the plain machine alias working', () => { + expect(matchExercise('Seated Fly (Machine)')).toBe('0596') + }) + it('still refuses to guess', () => { expect(matchExercise('Some Movement I Invented')).toBe(null) expect(matchExercise('')).toBe(null) }) }) + +// Hevy exports no category column, so every invented exercise took the 'upper legs' default +// and a third of an imported history was attributed to the legs in the muscle map. With no +// category to read, the body part comes off the name instead. +describe('invented exercises get a body part from their name', () => { + const HEAD = 'title,start_time,end_time,description,exercise_title,superset_id,exercise_notes,set_index,set_type,weight_kg,reps,distance_km,duration_seconds,rpe' + const row = name => `W,"09 Oct 2025, 19:22","09 Oct 2025, 20:22",,"${name}",,,0,normal,40,10,,,` + const bpOf = name => { + const r = parseWorkoutCSV([HEAD, row(name)].join('\n'), { unit: 'kg' }) + return r.customEx[0] && r.customEx[0].bp + } + + it('reads the body part off names the catalogue does not have', () => { + expect(bpOf('Kirk Shrug Machine Thing')).toBe('back') + expect(bpOf('Bicep Curl Contraption')).toBe('upper arms') + expect(bpOf('Standing Calf Thing')).toBe('lower legs') + }) + + it('no longer files everything under the legs', () => { + expect(bpOf('Some Chest Contraption')).not.toBe('upper legs') + expect(bpOf('Some Chest Contraption')).toBe('chest') + }) + + it('leaves a genuine leg movement on the legs', () => { + expect(bpOf('Bulgarian Split Squat Machine v9')).toBe('upper legs') + }) + + it('still prefers an explicit category column when the file has one', () => { + const head = 'Date,Exercise,Category,Weight,Reps' + const r = parseWorkoutCSV([head, '2025-10-09,Some Invented Lift,Shoulders,40,10'].join('\n'), { unit: 'kg' }) + expect(r.customEx[0].bp).toBe('shoulders') + }) +}) From 4a614eb8ca5d40adc5cfde0dbb0cba178c7fdfea Mon Sep 17 00:00:00 2001 From: Manuel Date: Tue, 25 Aug 2026 16:43:06 +0000 Subject: [PATCH 02/13] Show calendar year in multi-year chart tooltips --- frontend/src/components/LineChart.jsx | 9 ++- frontend/src/components/LineChart.test.jsx | 74 ++++++++++++++++++++++ frontend/src/lib/format.js | 8 ++- 3 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 frontend/src/components/LineChart.test.jsx diff --git a/frontend/src/components/LineChart.jsx b/frontend/src/components/LineChart.jsx index c236464..e8e59db 100644 --- a/frontend/src/components/LineChart.jsx +++ b/frontend/src/components/LineChart.jsx @@ -91,7 +91,10 @@ export default function LineChart({ points, h = 150, unit = '', color = 'var(--a const poly = pts.map(p => X(p.t).toFixed(1) + ',' + Y(p.y).toFixed(1)).join(' ') const last = pts[pts.length - 1] const gid = 'g' + Math.round(t0 % 1e7) + '_' + H - const hoverPts = (single ? [points[0]] : points).map(p => ({ x: X(p.t), y: Y(p.y), iso: p.d || isoOf(new Date(p.t)), v: p.y, note: p.note })) + const hoverSource = single ? [points[0]] : points + const hoverDates = hoverSource.map(p => p.d || isoOf(new Date(p.t))) + const showYear = new Set(hoverDates.map(iso => new Date(iso + 'T12:00:00').getFullYear())).size > 1 + const hoverPts = hoverSource.map((p, i) => ({ x: X(p.t), y: Y(p.y), iso: hoverDates[i], v: p.y, note: p.note })) const marked = points.some(p => p.m != null) const onMove = e => { @@ -132,8 +135,8 @@ export default function LineChart({ points, h = 150, unit = '', color = 'var(--a } {hover &&
- {fmtDate(hover.iso, true)} · {fmtNum(hover.v)}{unit ? ' ' + unit : ''}{hover.note ? ' · ' + hover.note : ''} + {fmtDate(hover.iso, true, showYear)} · {fmtNum(hover.v)}{unit ? ' ' + unit : ''}{hover.note ? ' · ' + hover.note : ''}
} ) -} +} \ No newline at end of file diff --git a/frontend/src/components/LineChart.test.jsx b/frontend/src/components/LineChart.test.jsx new file mode 100644 index 0000000..fe41810 --- /dev/null +++ b/frontend/src/components/LineChart.test.jsx @@ -0,0 +1,74 @@ +// @vitest-environment happy-dom +import React, { act } from 'react' +import { createRoot } from 'react-dom/client' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' +import LineChart from './LineChart.jsx' +import { fmtDate, isoOf } from '../lib/format.js' + +globalThis.IS_REACT_ACT_ENVIRONMENT = true + +let container +let root + +beforeEach(() => { + container = document.createElement('div') + document.body.appendChild(container) + root = createRoot(container) +}) + +afterEach(() => { + act(() => root.unmount()) + container.remove() +}) + +const point = (year, month, day, y) => ({ + d: `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`, + t: new Date(year, month - 1, day, 12).getTime(), + y +}) + +function renderChart(points) { + act(() => root.render()) +} + +function hoverAt(clientX) { + act(() => { + container.querySelector('.chart-i').dispatchEvent(new MouseEvent('mousemove', { bubbles: true, clientX })) + }) + return container.querySelector('.ctip').textContent +} + +describe('LineChart hover date', () => { + it('keeps same-year points in the compact format', () => { + const first = point(2026, 1, 15, 70) + renderChart([first, point(2026, 2, 15, 71)]) + + expect(hoverAt(0)).toBe(`${fmtDate(first.d, true)} · 70 kg`) + }) + + it('includes the calendar year at a short cross-year boundary', () => { + const first = point(2025, 11, 30, 70) + const last = point(2026, 2, 1, 71) + renderChart([first, last]) + + expect(hoverAt(0)).toBe(`${fmtDate(first.d, true, true)} · 70 kg`) + expect(hoverAt(340)).toBe(`${fmtDate(last.d, true, true)} · 71 kg`) + }) + + it('keeps a single point compact', () => { + const only = point(2026, 7, 4, 70) + renderChart([only]) + + expect(hoverAt(170)).toBe(`${fmtDate(only.d, true)} · 70 kg`) + }) + + it('uses timestamp-only points when deciding whether to show the year', () => { + const first = point(2025, 12, 31, 70) + const last = point(2026, 1, 1, 71) + const timestampOnly = [{ t: first.t, y: first.y }, { t: last.t, y: last.y }] + renderChart(timestampOnly) + + const lastIso = isoOf(new Date(last.t)) + expect(hoverAt(340)).toBe(`${fmtDate(lastIso, true, true)} · 71 kg`) + }) +}) \ No newline at end of file diff --git a/frontend/src/lib/format.js b/frontend/src/lib/format.js index e8eadeb..cd11e2b 100644 --- a/frontend/src/lib/format.js +++ b/frontend/src/lib/format.js @@ -12,9 +12,11 @@ export const DAYS = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'] export const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] export const MONTHS_LONG = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] -export function fmtDate(iso, long) { +export function fmtDate(iso, long, withYear = false) { const d = new Date(iso + 'T12:00:00') - return d.toLocaleDateString(dateLocale(), long ? { weekday: 'short', day: 'numeric', month: 'short' } : { day: 'numeric', month: 'short' }) + const options = long ? { weekday: 'short', day: 'numeric', month: 'short' } : { day: 'numeric', month: 'short' } + if (withYear) options.year = 'numeric' + return d.toLocaleDateString(dateLocale(), options) } export function fmtDur(ms) { const m = Math.floor(ms / 60000) @@ -44,4 +46,4 @@ export function weekKey(d) { export const localTZ = () => { try { return Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC' } catch { return 'UTC' } } export const uid = () => Date.now().toString(36) + Math.random().toString(36).slice(2, 7) -export const ACCENTS = { lime: '#30d158', sky: '#0a84ff', orange: '#ff9f0a', violet: '#bf5af2', pink: '#ff375f', red: '#ff453a', teal: '#40c8e0', gold: '#ffd60a' } +export const ACCENTS = { lime: '#30d158', sky: '#0a84ff', orange: '#ff9f0a', violet: '#bf5af2', pink: '#ff375f', red: '#ff453a', teal: '#40c8e0', gold: '#ffd60a' } \ No newline at end of file From 0863aa73fbe8e20ffb982b2dbeeb2a13f17ebe98 Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Tue, 25 Aug 2026 19:59:31 +0200 Subject: [PATCH 03/13] workout: fix the warm-up weight and the missing rest after a final set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two session bugs that users reported separately and that both sat in the "what happens when a set ends" path. insertWarmupRow read rows[at - 1] to find what to ramp from. For the FIRST warm-up `at` is 0, so that is rows[-1] — undefined — and the `||` fallback took the LAST row instead: the heaviest work set. "Add warm-up set" handed you a warm-up at your full working weight, every time, and you corrected it by hand. It now ramps from the first work row, each added row closing half the remaining gap (50% / 75% / 87.5%), rounded DOWN to the exercise's own loading step — a warm-up a notch light costs nothing, one a notch heavy is a set you have to strip plates off. The step is passed in by the caller so history.js keeps no dependency on progression.js, which already imports it. Rest timers stopped at the end of an exercise: the singleton path called stopRest() and then skipped startRest(), commented as "final sets finish quietly". But another exercise follows that set, and you rest before it too — a two-set exercise timed one rest instead of two (issue #3), and the rest never carried across the gap. Supersets already had the right rule, so the condition is now shared as restAfterSet(): rest after every completed set except the last set of the last exercise, which is where zkssyth landed independently in Discord. --- frontend/src/lib/history.js | 95 +++++++++++++++++++++-- frontend/src/lib/history.test.js | 105 +++++++++++++++++++++++++- frontend/src/lib/supersetFlow.js | 15 ++++ frontend/src/lib/supersetFlow.test.js | 19 ++++- frontend/src/views/Workout.jsx | 40 +++++++--- 5 files changed, 253 insertions(+), 21 deletions(-) diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.js index db34438..e3aa526 100644 --- a/frontend/src/lib/history.js +++ b/frontend/src/lib/history.js @@ -217,6 +217,33 @@ export function lastEntryFor(S, exId) { return null } +/** How long any single note may get. Long enough for a paragraph, short enough to stay a note. */ +export const NOTE_MAX = 500 + +/** + * The most recent session note the user pinned for this exercise, or null. + * + * A note written mid-session is about that session — "shoulder twinged today". Some of them are + * about the NEXT one instead: "go a notch narrower". The pin is how the user says which, at the + * moment of writing, when they are the only one who knows. Pinned notes surface again the next + * time the exercise comes up; unpinned ones stay in that day's history. + * + * Only the newest pinned note is returned: a pin is a message to your next self, and a stack of + * them from six sessions ago is noise, not context. + */ +export function pinnedNoteFor(S, exId) { + const workouts = S?.workouts || [] + for (let i = workouts.length - 1; i >= 0; i--) { + const en = (workouts[i].entries || []).find(e => e.id === exId) + const note = (en?.note || '').trim() + if (note && en.notePin) return { note, d: workouts[i].d } + } + return null +} + +/** The standing note for an exercise — the one that is true every session. */ +export const exNoteFor = (S, exId) => ((S?.exNotes || {})[exId] || '').trim() || null + // A freestyle exercise starts with the last target the user actually trained, rather than the // generic config sheet defaults used when there is no history. The set rows themselves are still // built by buildSets(), which copies each completed set by position; only the target shape and @@ -249,7 +276,30 @@ export function effectiveRoutine(S, iso) { const id = effectiveRoutineId(S, iso) return id ? S.routines.find(r => r.id === id) || null : null } +/** + * Build the rows a planned exercise starts a session with: its work sets, preceded by however + * many warm-up sets the routine asks for (`cfg.warmupSets`, 0 by default so an existing plan + * behaves exactly as before). + * + * The warm-ups are stacked with insertWarmupRow, one call each, so the ramp is the same one + * the in-session "Add warm-up set" button produces: each row halves the gap left to the work + * weight, giving 50% / 75% / 87.5% for three. `options.step` is the exercise's loading step, + * passed in by the caller (see insertWarmupRow for why this module cannot read it itself). + */ export function buildSets(S, cfg, options = {}) { + const rows = buildWorkSets(S, cfg, options) + const warm = Math.max(0, Math.min(MAX_PLANNED_WARMUPS, Math.round(cfg.warmupSets) || 0)) + if (!warm) return rows + const mode = modeOf(cfg) + let out = rows + for (let i = 0; i < warm; i++) out = insertWarmupRow(out, mode, cfg, options.step) + return out +} + +/** Beyond this a "warm-up" is its own workout; the config stepper stops here too. */ +export const MAX_PLANNED_WARMUPS = 5 + +function buildWorkSets(S, cfg, options = {}) { const last = lastEntryFor(S, cfg.id) const n = Math.max(1, cfg.sets || 1) const mode = modeOf(cfg) @@ -388,16 +438,49 @@ export function cascadeWeight(rows, from, value) { return next } -/** Insert a warm-up row before the first work row, copying the preceding warm-up's values. */ -export function insertWarmupRow(rows, mode, target) { +/** + * Insert a warm-up row at the end of the warm-up block, ramping toward the working weight. + * + * Each added row halves what is left between the last warm-up and the first work set, so the + * first one lands at half the working weight, a second at three quarters, and so on — and a + * row you edited by hand is what the next one ramps from. `step` is the exercise's own loading + * step (progression.js's defaultIncrement, passed in by the caller so this module keeps no + * dependency on progression — that one already imports from here): a warm-up you cannot + * actually load onto the bar is noise. + * + * The reference is the first WORK row, never `rows[at - 1]` alone: for the first warm-up + * `at` is 0, and reading `rows[-1]` used to fall through to the *last* row — the heaviest + * work set — so "add warm-up set" handed you a full-weight set to correct by hand. + */ +export function insertWarmupRow(rows, mode, target, step = 2.5) { const firstWork = rows.findIndex(x => !isWarmupRow(x)) const at = firstWork === -1 ? rows.length : firstWork - const l = rows[at - 1] || rows[rows.length - 1] + const prev = at > 0 ? rows[at - 1] : null // the warm-up this one ramps from + const work = firstWork === -1 ? null : rows[firstWork] + const rampTo = to => { + const from = prev ? (prev.w || 0) : 0 + if (!(to > 0) || to <= from) return from + // Rounded DOWN to the step: a warm-up that lands a notch light costs nothing, one that + // lands a notch heavy is a set you have to strip plates off before you can use it. + return Math.max(0, Math.min(to, Math.floor((from + (to - from) / 2) / step) * step)) + } const warm = mode === 'cardio' - ? { min: l ? l.min : (target.min || 20), speed: l ? l.speed : (target.speed || 8), done: false, phase: 'warmup', warmup: true } + ? { + min: prev ? prev.min : (work ? work.min : (target.min || 20)), + speed: prev ? prev.speed : (work ? work.speed : (target.speed || 8)), + done: false, phase: 'warmup', warmup: true, + } : mode === 'time' - ? { sec: l ? l.sec : (target.sec || 45), w: l ? (l.w || 0) : (target.weight || 0), done: false, phase: 'warmup', warmup: true } - : { w: l ? l.w : 0, r: l ? l.r : target.reps, done: false, phase: 'warmup', warmup: true } + ? { + sec: prev ? prev.sec : (work ? work.sec : (target.sec || 45)), + w: rampTo(work ? (work.w || 0) : (target.weight || 0)), + done: false, phase: 'warmup', warmup: true, + } + : { + w: rampTo(work ? (work.w || 0) : (target.weight || 0)), + r: work ? work.r : (prev ? prev.r : target.reps), + done: false, phase: 'warmup', warmup: true, + } const next = rows.slice() next.splice(at, 0, warm) return next diff --git a/frontend/src/lib/history.test.js b/frontend/src/lib/history.test.js index 39b89c4..12eec2b 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 { modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, bestWeightFor, bestWeightForEntry, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, removeRowAt, workSetsDone, pairAdjacent, unpairSuperset, supersetUnits, applyIntensifierPlan } from './history.js' +import { modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, bestWeightFor, bestWeightForEntry, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, removeRowAt, workSetsDone, pairAdjacent, unpairSuperset, supersetUnits, applyIntensifierPlan, pinnedNoteFor, exNoteFor } from './history.js' import { EXDB } from './exercises.js' // Real ids out of the shipped catalogue, so the body-part fallback is exercised for real. @@ -365,6 +365,42 @@ describe('freestyleConfig', () => { ]) }) + // Planned warm-ups: the routine says how many, buildSets stacks them onto the work sets with + // the same ramp the in-session button uses. A plan without the field must not change shape. + it('adds no rows when the config asks for no warm-ups', () => { + const S = { exWeights: {}, workouts: [] } + const cfg = { id: '0025', mode: 'reps', sets: 2, reps: 5, weight: 100 } + expect(buildSets(S, cfg)).toEqual([ + { w: 100, r: 5, done: false }, + { w: 100, r: 5, done: false }, + ]) + }) + + it('prepends the planned warm-ups as a ramp toward the work weight', () => { + const S = { exWeights: {}, workouts: [] } + const cfg = { id: '0025', mode: 'reps', sets: 2, reps: 5, weight: 100, warmupSets: 3 } + const rows = buildSets(S, cfg, { step: 2.5 }) + expect(rows.map(r => r.w)).toEqual([50, 75, 87.5, 100, 100]) + expect(rows.slice(0, 3).every(r => r.phase === 'warmup')).toBe(true) + expect(rows.slice(3).every(r => r.phase === undefined)).toBe(true) + }) + + it('caps the planned warm-ups and ignores nonsense values', () => { + const S = { exWeights: {}, workouts: [] } + const base = { id: '0025', mode: 'reps', sets: 1, reps: 5, weight: 100 } + expect(buildSets(S, { ...base, warmupSets: 99 }, { step: 2.5 }).filter(r => r.phase === 'warmup')).toHaveLength(5) + expect(buildSets(S, { ...base, warmupSets: -2 }, { step: 2.5 })).toHaveLength(1) + expect(buildSets(S, { ...base, warmupSets: 'x' }, { step: 2.5 })).toHaveLength(1) + }) + + it('keeps planned warm-ups out of the work-set count', () => { + const S = { exWeights: {}, workouts: [] } + const rows = buildSets(S, { id: '0025', mode: 'reps', sets: 3, reps: 5, weight: 100, warmupSets: 2 }, { step: 2.5 }) + const logged = { entries: [{ id: '0025', sets: rows.map(r => ({ ...r, done: true })) }] } + expect(logged.entries[0].sets).toHaveLength(5) + expect(workSetsDone(logged)).toBe(3) + }) + it('inherits the target for timed and cardio exercises too', () => { const timed = { exWeights: {}, @@ -705,19 +741,48 @@ describe('session row helpers', () => { expect('w' in next[2]).toBe(false) }) - it('insertWarmupRow inserts before the first work row and copies the last warm-up values', () => { + it('insertWarmupRow inserts before the first work row, ramping toward the work weight', () => { const rows = [ { warmup: true, w: 20, r: 8, done: true }, { warmup: true, w: 30, r: 8, done: false }, { w: 60, r: 8, done: false }, ] - const next = insertWarmupRow(rows, 'reps', { reps: 8 }) + const next = insertWarmupRow(rows, 'reps', { reps: 8 }, 2.5) expect(next.length).toBe(4) expect(next[2].warmup).toBe(true) - expect(next[2].w).toBe(30) // copies the preceding warm-up + expect(next[2].w).toBe(45) // halfway from the last warm-up (30) to the work set (60) expect(next[3].w).toBe(60) // work row still after the warm-up block }) + // The first warm-up is the case that was broken: `at` is 0, so the old code read rows[-1], + // fell through to `rows[rows.length - 1]` — the heaviest work set — and handed you a + // "warm-up" at your full working weight. + it('gives the first warm-up half the working weight, not the working weight itself', () => { + const next = insertWarmupRow([{ w: 100, r: 5, done: false }], 'reps', { reps: 5 }, 2.5) + expect(next.length).toBe(2) + expect(next[0]).toMatchObject({ w: 50, r: 5, phase: 'warmup', warmup: true, done: false }) + expect(next[1].w).toBe(100) + }) + + it('rounds the ramp to the exercise loading step', () => { + // 0 -> 95 halves to 47.5, which is not loadable in 5 kg steps: 45 is. + expect(insertWarmupRow([{ w: 95, r: 5 }], 'reps', { reps: 5 }, 5)[0].w).toBe(45) + }) + + it('keeps bodyweight warm-ups at zero and never exceeds the work set', () => { + expect(insertWarmupRow([{ w: 0, r: 12 }], 'reps', { reps: 12 }, 2.5)[0].w).toBe(0) + // A warm-up already at the working weight cannot ramp any further. + const at100 = insertWarmupRow([{ warmup: true, w: 100, r: 5 }, { w: 100, r: 5 }], 'reps', { reps: 5 }, 2.5) + expect(at100[1].w).toBe(100) + }) + + it('ramps a timed hold the same way and leaves cardio on the work row values', () => { + expect(insertWarmupRow([{ sec: 45, w: 40, done: false }], 'time', { sec: 45 }, 2.5)[0]) + .toMatchObject({ sec: 45, w: 20, phase: 'warmup' }) + expect(insertWarmupRow([{ min: 20, speed: 10, done: false }], 'cardio', { min: 20 }, 2.5)[0]) + .toMatchObject({ min: 20, speed: 10, phase: 'warmup' }) + }) + it('removeRowAt never empties an entry below one row', () => { expect(removeRowAt([{ w: 60 }], 0).length).toBe(1) const rows = [{ w: 60 }, { w: 70 }] @@ -748,3 +813,35 @@ describe('warm-up rows identified by phase alone', () => { expect(next[2].w).toBe(100) }) }) + +describe('pinnedNoteFor', () => { + const S = { + workouts: [ + { d: '2026-08-01', entries: [{ id: '0025', note: 'felt heavy', notePin: true }] }, + { d: '2026-08-08', entries: [{ id: '0025', note: 'just a diary line' }] }, + { d: '2026-08-15', entries: [{ id: '0025', note: 'go narrower', notePin: true }] }, + { d: '2026-08-22', entries: [{ id: '0293', note: 'other exercise', notePin: true }] }, + ], + } + + it('returns only the newest pinned note for that exercise', () => { + expect(pinnedNoteFor(S, '0025')).toEqual({ note: 'go narrower', d: '2026-08-15' }) + }) + + it('ignores notes that were not pinned', () => { + expect(pinnedNoteFor({ workouts: [{ d: '2026-08-08', entries: [{ id: '0025', note: 'diary' }] }] }, '0025')).toBeNull() + }) + + it('is null for an exercise with no notes, and safe on empty state', () => { + expect(pinnedNoteFor(S, '9999')).toBeNull() + expect(pinnedNoteFor({}, '0025')).toBeNull() + }) +}) + +describe('exNoteFor', () => { + it('reads the standing note and trims it away when blank', () => { + expect(exNoteFor({ exNotes: { '0025': ' seat 4, pin 7 ' } }, '0025')).toBe('seat 4, pin 7') + expect(exNoteFor({ exNotes: { '0025': ' ' } }, '0025')).toBeNull() + expect(exNoteFor({}, '0025')).toBeNull() + }) +}) diff --git a/frontend/src/lib/supersetFlow.js b/frontend/src/lib/supersetFlow.js index c78e72c..07eb202 100644 --- a/frontend/src/lib/supersetFlow.js +++ b/frontend/src/lib/supersetFlow.js @@ -10,6 +10,21 @@ export function setProgressHighWater(entry, previous = 0) { return { isNew: done > previous, highWater: Math.max(previous, done) } } +/** + * Whether completing a set should start a rest timer. + * + * A rest belongs after every completed set — the last set of an exercise included, because + * another exercise follows it and you rest before that one too. The only set with nothing + * left to time is the last set of the last exercise, where the session is over. + * + * Ordinary exercises used to "finish quietly" instead: an exercise started no rest on its + * closing set, so a two-set exercise timed one rest instead of two (issue #3) and a rest + * never carried across the gap into the next exercise. Supersets already did it this way. + */ +export function restAfterSet({ unitDone, lastUnit }) { + return !unitDone || !lastUnit +} + // Decide where a newly completed superset set goes next. Spent members are skipped, including // across the wrap. A round ends when no later member in display order has work left; this makes // the last *active* member the boundary rather than blindly using the group's last array index. diff --git a/frontend/src/lib/supersetFlow.test.js b/frontend/src/lib/supersetFlow.test.js index 2c96a16..b5682db 100644 --- a/frontend/src/lib/supersetFlow.test.js +++ b/frontend/src/lib/supersetFlow.test.js @@ -1,8 +1,25 @@ import { describe, expect, it } from 'vitest' -import { setProgressHighWater, supersetFlowStep } from './supersetFlow.js' +import { setProgressHighWater, supersetFlowStep, restAfterSet } from './supersetFlow.js' const entry = done => ({ sets: done.map(value => ({ done: value })) }) +describe('restAfterSet', () => { + it('rests between the sets of an exercise', () => { + expect(restAfterSet({ unitDone: false, lastUnit: false })).toBe(true) + expect(restAfterSet({ unitDone: false, lastUnit: true })).toBe(true) + }) + + // Issue #3: a two-set exercise timed one rest instead of two, because the closing set + // "finished quietly". The next exercise still follows it, so the rest belongs there. + it('rests after the closing set when another exercise follows', () => { + expect(restAfterSet({ unitDone: true, lastUnit: false })).toBe(true) + }) + + it('stays quiet only on the very last set of the session', () => { + expect(restAfterSet({ unitDone: true, lastUnit: true })).toBe(false) + }) +}) + describe('supersetFlowStep', () => { it('does not create navigation or rest flow for a normal singleton exercise', () => { const entries = [entry([true]), entry([false])] diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx index a377b22..9c49f67 100644 --- a/frontend/src/views/Workout.jsx +++ b/frontend/src/views/Workout.jsx @@ -3,17 +3,17 @@ import { useNavigate } from 'react-router-dom' import { useStore } from '../store/useStore.js' import { useUI } from '../store/useUI.js' import { exOr } from '../lib/exercises.js' -import { effectiveRoutine, lastEntryFor, bestWeightFor, buildSets, freestyleConfig, defaultConfig, setsDoneActive, supersetUnits, unitOf, setLabel, modeOf, isBw, isPerSide, sideReps, repStep, EFFORT, effortOf, stepEffort, capEffort, cascadeWeight, insertWarmupRow, removeRowAt, pairAdjacent, unpairSuperset, cleanupSg, applyIntensifierPlan } from '../lib/history.js' +import { effectiveRoutine, lastEntryFor, bestWeightFor, buildSets, freestyleConfig, defaultConfig, setsDoneActive, supersetUnits, unitOf, setLabel, modeOf, isBw, isPerSide, sideReps, repStep, EFFORT, effortOf, stepEffort, capEffort, cascadeWeight, insertWarmupRow, removeRowAt, pairAdjacent, unpairSuperset, cleanupSg, applyIntensifierPlan, pinnedNoteFor, exNoteFor } from '../lib/history.js' import { fmtNum, fmtDate, todayISO, exCount, DAYN } from '../lib/format.js' import { beep, vibrate } from '../lib/sound.js' import { t, exerciseNameFor } from '../lib/i18n.js' import { api } from '../lib/api.js' -import { setProgressHighWater, supersetFlowStep } from '../lib/supersetFlow.js' +import { setProgressHighWater, supersetFlowStep, restAfterSet } from '../lib/supersetFlow.js' import Media from '../components/Media.jsx' -import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout, workoutCompleteSheet, confirmSheet } from '../sheets.jsx' +import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet } from '../sheets.jsx' import Icon from '../components/Icon.jsx' import { Button, Check, NumberField } from '../components/ui.jsx' -import { nextPrescription, applyPrescription } from '../lib/progression.js' +import { nextPrescription, applyPrescription, defaultIncrement } from '../lib/progression.js' import { glyphOf } from '../lib/glyphs.js' import { isWarmupRow, isDropSet, isRestPauseSet, dropsOf, clustersOf, addDrop, addCluster, removeDropAt, removeClusterAt, setDropAt, setClusterAt, nextDropWeight, nextBurstReps } from '../lib/workout-model.js' @@ -96,6 +96,10 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov const cardio = mode === 'cardio' const timed = mode === 'time' const last = lastEntryFor(S, entry.id) + const standingNote = exNoteFor(S, entry.id) + // Only worth surfacing while there is still work left: once the exercise is finished, a note + // telling you what to do in it is behind you, and the block is already long. + const pinnedNote = entry.sets.some(s => !s.done) ? pinnedNoteFor(S, entry.id) : null // The same number the "confirm your working weight" sheet calls your best, so the two // never disagree inside one session: heaviest logged set, or the working weight you kept. const best = cardio ? 0 : Math.max(bestWeightFor(S, entry.id), (S.exWeights[entry.id] || {}).w || 0) @@ -154,7 +158,12 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov
{exerciseNameFor(ex)}
- +
+ + +
{!compact && (onPairPrev || onPairNext) &&
{onPairPrev && } @@ -169,7 +178,17 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov {ex.eq && {t(ex.eq)}} {best > 0 && {t('Best:')} {fmtNum(best)} {S.unit}}
+ {/* Three notes can apply to one exercise and they are not interchangeable, so each keeps its + own line and its own icon: the plan's instruction (cfg.note, from the routine), the + standing fact about the movement (exNotes), and the message you pinned to yourself last + session. Today's own note is edited through the button in the header and shown last. */} {cfg.note &&
{cfg.note}
} + {standingNote &&
{standingNote}
} + {pinnedNote &&
+ + {t('From {0}:', fmtDate(pinnedNote.d, true))} {pinnedNote.note} +
} + {entry.note &&
{entry.note}
} {last &&
{t('Last time')} ({fmtDate(last.d)}): {last.sets.map(s => setLabel(entry.id, s, last.target)).join(', ')}
} {plan && plan.why && plan.kind !== 'off' &&
@@ -304,7 +323,7 @@ function ActiveWorkout() { const removeSet = idx => mutEntry(idx, e => { if (e.sets.length > 1) e.sets.pop() }) const addWarmup = idx => mutEntry(idx, e => { const m = modeOf({ ...(e.target || {}), id: e.id }) - e.sets = insertWarmupRow(e.sets, m, e.target || {}) + e.sets = insertWarmupRow(e.sets, m, e.target || {}, defaultIncrement(e.id, S.unit)) }) const removeSetAt = (idx, i) => mutEntry(idx, e => { e.sets = removeRowAt(e.sets, i) }) const pairAt = (first, second) => update(s => { @@ -400,11 +419,12 @@ function ActiveWorkout() { const freshLastUnit = freshUnitIdx >= freshUnits.length - 1 const freshUnitDone = freshUnit?.every(ui => fresh.entries[ui].sets.every(x => x.done)) - // Singleton units are ordinary exercises: preserve their historical between-set rest, - // while final sets finish quietly and never enter superset navigation. + // Singleton units are ordinary exercises: they rest between sets and after the closing + // one, and never enter superset navigation. stopRest() first so the rest that belongs + // after this set replaces the one that was running, rather than stacking on it. if (freshUnitDone) stopRest() if (!freshUnit || freshUnit.length <= 1) { - if (!freshUnitDone) startRest(S.restSec) + if (restAfterSet({ unitDone: freshUnitDone, lastUnit: freshLastUnit })) startRest(S.restSec) return } @@ -493,7 +513,7 @@ function ActiveWorkout() { exConfigSheet(ex, null, cfg => update(s => { const full = { ...cfg, id: ex.id } const plan = freestyle ? null : nextPrescription(s, full, s.routines.find(r => r.id === s.active.routineId)) - const sets = buildSets(s, full, freestyle ? { preferLast: true } : undefined) + const sets = buildSets(s, full, { step: defaultIncrement(ex.id, s.unit), ...(freestyle ? { preferLast: true } : {}) }) const progressed = freestyle ? sets : applyPrescription(sets, plan) s.active.entries.push({ id: ex.id, target: { ...cfg }, plan, sets: applyIntensifierPlan(progressed, full) }) s.active.cur = s.active.entries.length - 1 From 46eaefd2c7e881e93312c81195de3f1b3f99e88e Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Tue, 25 Aug 2026 19:59:50 +0200 Subject: [PATCH 04/13] css: make the tab bar opaque, and actually ship backdrop-filter to Firefox MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported as "the navigation bar is half transparent … the information can be harder to see as it is mixed with the background". Two separate causes. The bar was 72% opaque. Even with the blur working that is too little to read labels against a scrolling page, and nobody needs to read what is behind a navigation bar. Now 94% in both themes, with the blur down from 24px to 10px: this is a position:fixed element, so the WebView recomposites the blurred region on every scroll frame, which is the most expensive thing on an Android screen. Same blur reduction on the rest timer, which is on screen for a whole session. The second cause is worse and was invisible from the source: the CSS minifier dedupes a `backdrop-filter` / `-webkit-backdrop-filter` pair down to whichever is written LAST, so the standard property was being dropped from the build entirely and only the -webkit- one shipped. Firefox understands only the unprefixed name, so it had no blur at all — just the alpha, which is exactly the reported symptom. All five pairs now put the prefixed line first, with a comment so nobody tidies the order back. Adds an @supports fallback to fully opaque where backdrop-filter is genuinely unavailable (old Android WebViews, reduce-transparency settings), and drops .ss-card's padding on narrow screens — a superset pays the page gutter twice and squeezed the reps field, which socialscientist93 diagnosed exactly. --- frontend/src/index.css | 45 +++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/frontend/src/index.css b/frontend/src/index.css index 376bf10..e674797 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -272,15 +272,21 @@ h4.sec{ .btn:disabled{opacity:.32;pointer-events:none} /* ----------------------------------------------------------- tab bar ----- */ +/* Nearly opaque, and deliberately so. At the old 72% the page read straight through the bar + and the labels had to compete with whatever was scrolling behind them — nobody needs to read + the content under a navigation bar. 94% keeps a hint of movement behind the glass without + letting text through. The blur is also down from 24px to 10px: this is a fixed element, so + the WebView recomposites the blurred region on every scroll frame, and on Android that is + the single most expensive thing on the screen. See @supports below for the no-blur case. */ #tabbar{ position:fixed;left:0;right:0;bottom:0;z-index:50; display:flex;justify-content:space-around;align-items:flex-end; padding:7px 6px calc(6px + var(--sab)); - background:color-mix(in srgb,var(--bg-el) 72%,transparent); - backdrop-filter:saturate(180%) blur(24px);-webkit-backdrop-filter:saturate(180%) blur(24px); + background:color-mix(in srgb,var(--bg-el) 94%,transparent); + -webkit-backdrop-filter:saturate(180%) blur(10px);backdrop-filter:saturate(180%) blur(10px); border-top:var(--hair) solid var(--sep-op); } -:root[data-theme="light"] #tabbar{background:rgba(249,249,251,.78)} +:root[data-theme="light"] #tabbar{background:rgba(249,249,251,.94)} #tabbar button{ flex:1;display:flex;flex-direction:column;align-items:center;gap:3px; color:var(--label-3);font-size:10px;font-weight:500;letter-spacing:.005em;padding-top:3px; @@ -317,6 +323,24 @@ h4.sec{ } @keyframes ping{0%{transform:scale(1);opacity:.7}100%{transform:scale(1.45);opacity:0}} +/* NOTE on every backdrop-filter pair in this file: the -webkit- line comes FIRST and the + standard property SECOND. The CSS minifier dedupes the pair down to whichever is written + last, so with the usual order (standard first) the build shipped -webkit-backdrop-filter + alone — and Firefox, which only understands the unprefixed property, got no blur at all, + just the alpha. That is what made the tab bar read as see-through there. Do not "tidy" + the order back. + + Where backdrop-filter is genuinely unsupported there is no glass either — only the alpha, + and the page shows through unblurred, which is the worst of both. Older Android WebViews + never had it, and "reduce transparency" accessibility settings drop it. Those surfaces go + fully opaque instead. Keep this in sync with the rules above. */ +@supports not ((backdrop-filter:blur(1px)) or (-webkit-backdrop-filter:blur(1px))){ + #tabbar{background:var(--bg-el)} + :root[data-theme="light"] #tabbar{background:#f9f9fb} + #timer{background:var(--surface)} + #toast{background:var(--surface-2)} +} + /* ------------------------------------------------------------ week strip -- */ .week{display:flex;justify-content:space-between;gap:4px} .wday{ @@ -536,7 +560,7 @@ h4.sec{ position:absolute;bottom:9px;display:inline-flex;align-items:center;gap:4px; background:rgba(0,0,0,.45);color:#fff;border-radius:99px;padding:5px 11px; font-size:12px;font-weight:500; - backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px); + -webkit-backdrop-filter:blur(12px);backdrop-filter:blur(12px); } .exmedia .gifhint{right:9px} .exmedia .giftoggle{left:9px} @@ -626,7 +650,7 @@ h4.sec{ /* nearly opaque: the set rows underneath were reading through the old 82% and made the clock hard to pick out mid-set. The blur stays, so it still sits above the page. */ background:color-mix(in srgb,var(--surface) 97%,transparent); - backdrop-filter:saturate(180%) blur(24px);-webkit-backdrop-filter:saturate(180%) blur(24px); + -webkit-backdrop-filter:saturate(180%) blur(10px);backdrop-filter:saturate(180%) blur(10px); border-radius:var(--r-lg);padding:12px 14px; display:flex;align-items:center;gap:12px; box-shadow:0 12px 34px -8px rgba(0,0,0,.55); @@ -659,7 +683,7 @@ h4.sec{ #modal-root.open{display:block} .mback{ position:absolute;inset:0;background:rgba(0,0,0,.4); - backdrop-filter:blur(2px);-webkit-backdrop-filter:blur(2px); + -webkit-backdrop-filter:blur(2px);backdrop-filter:blur(2px); touch-action:none;overscroll-behavior:none; } .sheet{ @@ -846,7 +870,7 @@ h4.sec{ position:fixed;left:50%;transform:translateX(-50%) translateY(6px); bottom:calc(96px + var(--sab));z-index:200; background:color-mix(in srgb,var(--surface-2) 88%,transparent); - backdrop-filter:saturate(180%) blur(20px);-webkit-backdrop-filter:saturate(180%) blur(20px); + -webkit-backdrop-filter:saturate(180%) blur(20px);backdrop-filter:saturate(180%) blur(20px); border-radius:99px;padding:11px 20px;font-size:15px;font-weight:500; box-shadow:0 10px 30px -6px rgba(0,0,0,.5); opacity:0;pointer-events:none;transition:opacity var(--med),transform var(--med) var(--ease); @@ -898,6 +922,13 @@ h4.sec{ border-radius:var(--r-lg);padding:14px; background:var(--surface);box-shadow:inset 0 0 0 1.5px var(--acc-line); } +/* A superset nests a card inside the page's own gutter, so its inset is paid twice. On a + narrow phone that left the weight and reps steppers too tight to show a three-digit + number — reported as "the reps textbox becomes too small when superset on mobile". The + card only gives up its own padding; the rows inside keep their spacing. */ +@media (max-width:400px){ + .ss-card{padding:10px 8px} +} .ss-hd{ font-size:12px;font-weight:600;color:var(--acc);margin-bottom:12px; text-align:center;display:flex;align-items:center;justify-content:center;gap:5px; From 62b69ea88d9c6918f65e5e949046f3109a61ab35 Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Tue, 25 Aug 2026 19:59:50 +0200 Subject: [PATCH 05/13] home + stats: stop asking for a workout that is done, plot bodyweight lifts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Home's week strip already knew today was finished — its dot goes 'done' from S.workouts — but the row underneath only ever asked `routine`, so a logged day kept showing the routine name behind a green Start tag and read as still outstanding (issue #4). It now reports the session instead. Tapping still starts another one; it just stops urging. Stats dropped every point whose value was 0, and a bodyweight pull-up has no weight, so "Exercise progress" read "No data yet" for exercises with a full history behind them (issue #5). When nothing in an exercise's history was ever loaded, its progress IS the rep count, so that is what gets plotted, labelled in reps. Add a weighted set later and it switches back to weight on its own — which is also the honest reading, because that is when load became the thing improving. Same fallback in currentOf, or the picker label went blank and the exercise sorted to the bottom as if it had no history at all. --- frontend/src/views/Home.jsx | 18 +++++++++++++++--- frontend/src/views/Stats.jsx | 24 +++++++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/frontend/src/views/Home.jsx b/frontend/src/views/Home.jsx index 1a751f8..a7abcc7 100644 --- a/frontend/src/views/Home.jsx +++ b/frontend/src/views/Home.jsx @@ -26,6 +26,9 @@ export default function Home() { const monday = new Date(today); monday.setDate(today.getDate() - ((today.getDay() + 6) % 7) + weekOffset * 7) const doneDays = new Set(S.workouts.map(w => w.d)) + // The last session logged for today, if any — what the row below reports instead of asking + // you to start the one you already did. Last wins, so a second session names itself. + const doneToday = S.workouts.filter(w => w.d === todayISO()).at(-1) || null const strip = [] for (let i = 0; i < 7; i++) { const d = new Date(monday); d.setDate(monday.getDate() + i) @@ -58,17 +61,26 @@ export default function Home() {
{strip}
+ {/* Once today's session is logged the row stops asking for it. The week strip already + knew (its dot goes 'done'); this row did not, so a finished day kept showing the + routine name behind a green Start tag and read as still outstanding (issue #4). + An in-progress session still wins — that one is happening right now. Tapping the + row keeps working, so a second session in one day is a tap away, just not urged. */}
- - + +
{t('Today')}
-
{S.active ? t('{0} — in progress', S.active.name) : routine ? routine.name : t('Rest day')}{todayOvr && routine ? ' · ' + t('rescheduled') : ''}
+
{S.active ? t('{0} — in progress', S.active.name) + : doneToday ? (doneToday.name ? t('{0} — done', doneToday.name) : t('Workout done')) + : routine ? routine.name : t('Rest day')}{todayOvr && routine && !doneToday ? ' · ' + t('rescheduled') : ''}
{S.active ? {t('Resume')} + : doneToday ? {t('Done')} : routine ? {t('Start')} : }
diff --git a/frontend/src/views/Stats.jsx b/frontend/src/views/Stats.jsx index 0140e72..9bd4621 100644 --- a/frontend/src/views/Stats.jsx +++ b/frontend/src/views/Stats.jsx @@ -300,6 +300,12 @@ export default function Stats() { const rows = metricRowsForEntry(en, mode) const mx = mode === 'reps' ? bestWeightForEntry(en) : Math.max(0, ...rows.map(s => mode === 'cardio' ? (s.speed || 0) : mode === 'time' ? (s.sec || 0) : (s.w || 0))) if (mx > 0) return { mx, unit: mode === 'cardio' ? 'km/h' : mode === 'time' ? 's' : S.unit } + // Unloaded reps work still has a current figure — its rep count. Without this the whole + // picker label went blank and the exercise sorted to the bottom as if it had no history. + if (mode === 'reps') { + const reps = Math.max(0, ...rows.map(s => Number(s.r) || 0)) + if (reps > 0) return { mx: reps, unit: t('reps') } + } } return { mx: 0, unit: S.unit } } @@ -321,8 +327,18 @@ export default function Stats() { })() : 'reps' const curCardio = curMode === 'cardio' const curTimed = curMode === 'time' + // A pull-up or a push-up carries no weight, so its "best weight" is 0 — and dropping every + // zero point left the card reading "No data yet" for exercises with a full history behind + // them (issue #5). When nothing in an exercise's history was ever loaded, the progress IS + // the rep count, so plot that. Add a weighted set later and it switches back to weight on + // its own, which is also the honest reading: that is when load became the thing improving. + const repsOnly = curEx && curMode === 'reps' && !workouts.some(w => { + const en = w.entries.find(e => e.id === curEx) + return en && bestWeightForEntry(en) > 0 + }) + const bestRepsOf = en => Math.max(0, ...metricRowsForEntry(en, 'reps').map(s => Number(s.r) || 0)) const metric = s => curCardio ? (s.speed || 0) : curTimed ? (s.sec || 0) : (s.w || 0) - const exUnit = curCardio ? 'km/h' : curTimed ? 's' : S.unit + const exUnit = curCardio ? 'km/h' : curTimed ? 's' : repsOnly ? t('reps') : S.unit let exPts = [], exList = [], exBest = 0 if (curEx) { workouts.forEach(w => { @@ -331,7 +347,9 @@ export default function Stats() { const loggedMode = metricModeForEntry(en) if (loggedMode !== curMode) return const doneSets = metricRowsForEntry(en, curMode) - const mx = curMode === 'reps' ? bestWeightForEntry(en) : Math.max(0, ...doneSets.map(metric)) + const mx = curMode === 'reps' + ? (repsOnly ? bestRepsOf(en) : bestWeightForEntry(en)) + : Math.max(0, ...doneSets.map(metric)) if (mx > 0) { exPts.push({ t: w.start, y: mx, d: w.d, sets: doneSets, target: en.target }) if (mx > exBest) exBest = mx @@ -413,7 +431,7 @@ export default function Stats() {
{exList.map((p, i) =>
{fmtDate(p.d, true)}{p.sets.map(s => setLabel(curEx, s, p.target)).join(' ')}
)}
- {onEff ? t('Average effort per workout') : onE1 ? t('Estimated 1RM per workout') : curCardio ? t('Top speed per workout') : curTimed ? t('Longest hold per workout') : t('Best set weight per workout')} + {onEff ? t('Average effort per workout') : onE1 ? t('Estimated 1RM per workout') : curCardio ? t('Top speed per workout') : curTimed ? t('Longest hold per workout') : repsOnly ? t('Most reps in a set per workout') : t('Best set weight per workout')} {onEff ? '' : <> · {t('Best:')}{' '}{fmtNum(onE1 ? e1Best.est : exBest)} {onE1 ? S.unit : exUnit}}
{onE1 &&
From 37d6cf895a7aa726003779b1f5e5d8557a0ea4db Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Tue, 25 Aug 2026 20:00:10 +0200 Subject: [PATCH 06/13] notes and planned warm-ups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three kinds of note, because they have three different lifetimes and users asked for all three: · a session note on an exercise — what happened today, stored on the workout entry. It carries a PIN, and that is the whole design: only the person writing knows whether "shoulder twinged" is a diary line or "go narrower" is a message to their next self. A pinned note surfaces again the next time that exercise comes up, where the "Last time" line already is; an unpinned one stays in that day's history. This is deliberately not a global setting: the answer differs per note, so a single switch would need constant flipping, while at the moment of writing it is obvious. · a standing note on the exercise itself (S.exNotes) — seat height, pin position, a form cue. True every session, shown every session. This is elchavalico's request, with ten messages of agreement behind it. · a whole-session note on the workout, editable from its history entry, where it is easier to say how a session went once you can see what you did. A routine's own `note` (!14) stays where it is: it belongs to the plan, not to the day or to the movement. Planned warm-ups: `warmupSets` on an exercise config, stacked by buildSets using the same ramp as the in-session button, so the session starts with them already there instead of you adding them by hand every time. Written only when non-zero, so an existing plan keeps its exact shape and reads back as 0. They travel with a shared plan, and stay out of volume, records and progression via the phase flag that already existed. --- frontend/src/lib/finish-workout.js | 11 +++ frontend/src/lib/finish-workout.test.js | 33 +++++++ frontend/src/lib/plan-share.js | 1 + frontend/src/sheets.jsx | 117 ++++++++++++++++++++++-- frontend/src/store/useStore.js | 4 + 5 files changed, 160 insertions(+), 6 deletions(-) diff --git a/frontend/src/lib/finish-workout.js b/frontend/src/lib/finish-workout.js index f34f92b..e1de54c 100644 --- a/frontend/src/lib/finish-workout.js +++ b/frontend/src/lib/finish-workout.js @@ -12,9 +12,19 @@ export function buildCompletedWorkout(active, { end = Date.now(), prs = [], snap if (snapshot && typeof snapshot === 'object' && !Array.isArray(snapshot) && Object.keys(snapshot).length) { completed.muscleSnapshot = { ...snapshot } } + // What you typed about this exercise today, and whether you asked to see it again next + // time. Written only when there is something to keep, so an untouched entry is byte-for-byte + // the shape it always was. + const note = (entry.note || '').trim() + if (note) { + completed.note = note + if (entry.notePin) completed.notePin = true + } return completed }).filter(entry => entry.sets.some(set => set.done)) + const sessionNote = (active?.note || '').trim() + return { id: active.id, d: active.d, @@ -25,5 +35,6 @@ export function buildCompletedWorkout(active, { end = Date.now(), prs = [], snap bw: active.bw, entries, prs, + ...(sessionNote ? { note: sessionNote } : {}), } } diff --git a/frontend/src/lib/finish-workout.test.js b/frontend/src/lib/finish-workout.test.js index 2dbe951..8f8e2c5 100644 --- a/frontend/src/lib/finish-workout.test.js +++ b/frontend/src/lib/finish-workout.test.js @@ -36,3 +36,36 @@ describe('completed workout boundary', () => { }) }) }) + +// Notes written during a session have to survive it, or "write a note during your workout" +// means "write a note and lose it when you tap Finish". +describe('session notes', () => { + const active = (entry) => ({ + id: 'w1', d: '2026-08-25', start: 1, routineId: 'r1', name: 'Push', bw: null, + entries: [{ id: '0025', sets: [{ w: 100, r: 5, done: true }], ...entry }], + }) + + it('keeps a per-exercise note and its pin', () => { + const w = buildCompletedWorkout(active({ note: ' narrower grip next time ', notePin: true })) + expect(w.entries[0].note).toBe('narrower grip next time') + expect(w.entries[0].notePin).toBe(true) + }) + + it('keeps an unpinned note without inventing a pin', () => { + const w = buildCompletedWorkout(active({ note: 'shoulder twinged' })) + expect(w.entries[0].note).toBe('shoulder twinged') + expect('notePin' in w.entries[0]).toBe(false) + }) + + it('writes no note fields at all when nothing was typed', () => { + const w = buildCompletedWorkout(active({ note: ' ', notePin: true })) + expect('note' in w.entries[0]).toBe(false) + expect('notePin' in w.entries[0]).toBe(false) + }) + + it('keeps a whole-session note on the workout', () => { + const a = active({}) + expect(buildCompletedWorkout({ ...a, note: 'slept badly' }).note).toBe('slept badly') + expect('note' in buildCompletedWorkout(a)).toBe(false) + }) +}) diff --git a/frontend/src/lib/plan-share.js b/frontend/src/lib/plan-share.js index a24329f..06a3bd5 100644 --- a/frontend/src/lib/plan-share.js +++ b/frontend/src/lib/plan-share.js @@ -46,6 +46,7 @@ function cleanEx(e) { if (e.repsMax != null) o.repsMax = e.repsMax if (e.sg) o.sg = e.sg if (e.note) o.note = e.note + if (e.warmupSets) o.warmupSets = e.warmupSets return o } diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx index fe8513b..b7a5448 100644 --- a/frontend/src/sheets.jsx +++ b/frontend/src/sheets.jsx @@ -1,10 +1,10 @@ import { useEffect, useRef, useState } from 'react' import { useStore } from './store/useStore.js' import { useUI } from './store/useUI.js' -import { EXDB, EXIDX, BODYPARTS, isCardio, isBodyweightEq, allExercises, equipmentOf, smOf, matchExercise } from './lib/exercises.js' +import { EXDB, EXIDX, BODYPARTS, isCardio, isBodyweightEq, allExercises, equipmentOf, smOf, matchExercise, exOr } from './lib/exercises.js' import { activeProfile, exAvailable, ALL_EQUIPMENT, newProfile } from './lib/equipment.js' import { fmtDate, fmtNum, fmtVol, fmtDur, durPart, todayISO, uid, exCount, DAYN, MONTHS_LONG, ACCENTS } from './lib/format.js' -import { lastEntryFor, bestWeightFor, buildSets, effectiveRoutineId, workoutVolume, setsDone, setsDoneActive, lastBW, supersetUnits, unitOf, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, isBw, isPerSide, sideReps, workSetsDone, applyIntensifierPlan } from './lib/history.js' +import { lastEntryFor, bestWeightFor, buildSets, effectiveRoutineId, workoutVolume, setsDone, setsDoneActive, lastBW, supersetUnits, unitOf, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, isBw, isPerSide, sideReps, workSetsDone, applyIntensifierPlan, MAX_PLANNED_WARMUPS, NOTE_MAX } from './lib/history.js' import { beep, vibrate } from './lib/sound.js' import { t, instrFor, exerciseNameFor, getLang, INSTR_LANGS } from './lib/i18n.js' import { nav } from './lib/nav.js' @@ -602,14 +602,18 @@ function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) { // Mode-independent, so it is spread in below rather than folded into `flags`. const note = (c.note || '').trim().slice(0, 500) const withNote = note ? { note } : {} + // Only written when there are any, so a plan that never asked for warm-ups keeps the exact + // shape it had — and reads back as 0 either way (buildSets). + const warmupSets = Math.max(0, Math.min(MAX_PLANNED_WARMUPS, Math.round(c.warmupSets) || 0)) + const withWarmups = warmupSets ? { warmupSets } : {} if (cardio) onSave({ sets, min: Math.max(1, Math.round(c.min) || 20), speed: Math.max(0, c.speed || 8), ...withNote }) - else if (mode === 'time') onSave({ sets, mode: 'time', sec: Math.max(1, Math.round(c.sec) || 45), weight: Math.max(0, c.weight || 0), ...flags, ...prog, ...withNote }) + else if (mode === 'time') onSave({ sets, mode: 'time', sec: Math.max(1, Math.round(c.sec) || 45), weight: Math.max(0, c.weight || 0), ...flags, ...prog, ...withNote, ...withWarmups }) else { // A unilateral target is stored even: the split has to divide, and a typed 15 would // otherwise plan seven reps on one side and eight on the other, every session. const typed = Math.max(1, Math.round(c.reps) || 10) const reps = perSide ? Math.ceil(typed / 2) * 2 : typed - const out = { sets, mode: 'reps', reps, weight: Math.max(0, c.weight || 0), ...flags, ...(perSide ? { side: true } : {}), ...prog, ...withNote } + const out = { sets, mode: 'reps', reps, weight: Math.max(0, c.weight || 0), ...flags, ...(perSide ? { side: true } : {}), ...prog, ...withNote, ...withWarmups } if (policyFor({ ...c, id: ex.id }, routine, 'reps') === 'double') out.repsMin = Math.min(reps, Math.max(1, Math.round(c.repsMin) || Math.max(1, reps - 2))) // A ceiling below the working reps would tell you to add a set on day one. if (bw && !(out.weight > 0) && c.repsMax > 0) out.repsMax = Math.max(reps, Math.round(c.repsMax)) @@ -622,9 +626,14 @@ function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) { return <>

{exerciseNameFor(ex)}

+ {/* The same tags the exercise detail sheet shows, secondaries included: choosing what goes + into a plan is exactly when "what else does this hit" matters, and until now that was + only visible from the Exercises tab, after the fact. */}
{cardio && {t('Cardio')}} {t(ex.tg || ex.bp)}{t(ex.eq)} + {!cardio && (ex.secondaries?.length ? ex.secondaries : smOf(ex)).slice(0, 3) + .map((s, i) => {t(s)})}
{ex.desc &&
{ex.desc}
} {!cardio &&
@@ -654,6 +663,20 @@ function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) { {c.intensifier?.type === 'restpause' &&
{t('Rest-pause always trains as one warm-up set at this rep count, then one rest-pause work set — "Sets" is not used.')}
} + {/* Planned warm-ups: the session used to start at the work weight and you added every + warm-up by hand, every time. Rest-pause is excluded because it builds its own warm-up + row, and cardio because an interval plan has no load to ramp. */} + {!cardio && c.intensifier?.type !== 'restpause' && <> +
+ setC(x => ({ ...x, warmupSets: Math.max(0, Math.min(MAX_PLANNED_WARMUPS, Math.round(v) || 0)) }))} /> +
+
+ {(c.warmupSets || 0) > 0 + ? t('Added before your work sets and left out of volume, records and progression. Each one closes half the gap to the work weight — you can still change any of them mid-session.') + : t('Ramp-up sets added before the work sets, so you do not have to add them by hand each session.')} +
+ } {mode === 'time' && !bw &&
{t('A timer runs while you hold the set. Leave the weight at 0 for bodyweight holds.')}
} @@ -890,6 +913,16 @@ export const dayAssignSheet = day => ui().openSheet(close => s.S) + const update = useStore(s => s.update) + // The session note is editable here rather than only at the finish sheet: what you want to + // record about a session is often clearer once you have looked at what you actually did. + const [note, setNote] = useState(w.note || '') + const saveNote = () => update(s => { + const rec = s.workouts.find(x => x.id === w.id) + if (!rec) return + const text = note.trim().slice(0, NOTE_MAX) + if (text) rec.note = text; else delete rec.note + }) return <>

{w.name}

{[fmtDate(w.d, true), ...durPart(w.end - w.start), fmtVol(w.vol, st.unit), ...(w.bw ? [fmtNum(w.bw) + ' ' + st.unit] : [])].join(' · ')}
@@ -898,9 +931,17 @@ function WorkoutDetail({ w, close }) { return
{ex && }
{ex ? exerciseNameFor(ex) : (e.n || e.id)} {w.prs && w.prs.includes(e.id) && PR}
-
{e.sets.filter(s => s.done).map(s => setLabel(e.id, s, e.target)).join(' · ') || t('no sets')}
+
{e.sets.filter(s => s.done).map(s => setLabel(e.id, s, e.target)).join(' · ') || t('no sets')}
+ {e.note &&
+ {e.notePin && }{e.note} +
}
})} +
{t('Session note')}
+