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 <>