From 37d6cf895a7aa726003779b1f5e5d8557a0ea4db Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Tue, 25 Aug 2026 20:00:10 +0200 Subject: [PATCH] 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')}
+