Skip to content

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.

The line under each exercise can show your best set instead of last time (#173)

Duarte Santos618096667c5c
diff --git a/frontend/src/index.css b/frontend/src/index.css
index 61c20c44c..dbad7cbb2 100644
--- a/frontend/src/index.css
+++ b/frontend/src/index.css
@@ -1022,6 +1022,10 @@ body.chips-dragging *{cursor:inherit}
}
.progline.warn{color:var(--yellow)}
.progline svg{flex:none;margin-top:2px}
+/* "Last time" / "Best set" under the plan line (#173): a button that switches between the two,
+ looking like the plain line it replaced, with a small icon to say it can be tapped. */
+.refline{width:100%;display:flex;align-items:flex-start;gap:6px;margin-bottom:4px;padding:0;text-align:left}
+.refline svg{flex:none;margin-top:2px;font-size:12px}
/* start a timed set (issue #16) — sits where you'd otherwise reach for the checkbox */
.setrow .setgo{
diff --git a/frontend/src/lib/exercise-history.js b/frontend/src/lib/exercise-history.js
index 72b205b76..4042fc41c 100644
--- a/frontend/src/lib/exercise-history.js
+++ b/frontend/src/lib/exercise-history.js
@@ -1,6 +1,7 @@
import { metricModeForEntry, metricRowsForEntry, bestWeightForEntry, modeOf } from './history.js'
import { completedVolumeOf } from './workout-model.js'
import { bestSetOf } from './onerm.js'
+import { beatsWeight } from './exercises.js'
// One exercise's past, read back for the history sheet (issue #43): a chart series and the
// last few sessions, derived in a single pass over the log so the sheet can memoise the
@@ -81,3 +82,38 @@ export function exerciseHistory(S, exId, { limit = HISTORY_SESSIONS } = {}) {
points, e1rmPoints,
}
}
+
+/**
+ * The best set ever logged of an exercise, for the "Best set" reference on the workout card
+ * (#173) — the answer to "last time was a bad day, what can I actually do". It is the heaviest
+ * completed work set, and of equally heavy ones the one with the most reps: the same "heaviest"
+ * the Best chip and a PR mean, which on an assistance machine is the least help. A timed exercise
+ * compares holds, then their load; cardio compares minutes, then speed. An exercise never loaded
+ * (pull-ups) comes down to its reps that way.
+ *
+ * Unlike "Last time" this looks across every routine: a record belongs to the exercise, not to
+ * the slot it was set in. Only sets logged in `mode` count, so a hold is never measured against
+ * a rep set. A tie keeps the first time it was reached, as the PR marker does.
+ * Returns { d, set, target } or null.
+ */
+export function bestSetFor(S, exId, mode = modeOf({ id: exId })) {
+ const keys = s => mode === 'cardio' ? [Number(s.min) || 0, Number(s.speed) || 0]
+ : mode === 'time' ? [Number(s.sec) || 0, Number(s.w) || 0]
+ : [Number(s.w) || 0, Number(s.r) || 0]
+ const better = (a, b) => {
+ const [a1, a2] = keys(a), [b1, b2] = keys(b)
+ if (a1 !== b1) return mode === 'reps' ? beatsWeight(exId, a1, b1) : a1 > b1
+ return a2 > b2
+ }
+ let best = null
+ const logged = [...(S?.workouts || [])].sort((a, b) => startOf(a) - startOf(b))
+ for (const w of logged) {
+ for (const en of w.entries || []) {
+ if (en.id !== exId) continue
+ for (const set of metricRowsForEntry(en, mode)) {
+ if (!best || better(set, best.set)) best = { d: w.d, set, target: en.target || null }
+ }
+ }
+ }
+ return best
+}
diff --git a/frontend/src/lib/exercise-history.test.js b/frontend/src/lib/exercise-history.test.js
index a6b8e2159..8f01e649e 100644
--- a/frontend/src/lib/exercise-history.test.js
+++ b/frontend/src/lib/exercise-history.test.js
@@ -1,5 +1,6 @@
import { describe, it, expect } from 'vitest'
-import { exerciseHistory, HISTORY_SESSIONS } from './exercise-history.js'
+import { exerciseHistory, HISTORY_SESSIONS, bestSetFor } from './exercise-history.js'
+import { EXDB } from './exercises-data.js'
import { estimate1RM } from './onerm.js'
const DAY = 86400000
@@ -110,3 +111,41 @@ describe('exerciseHistory', () => {
expect(h.sessions.map(s => [s.id, s.value])).toEqual([['b', 20], ['a', null]])
})
})
+
+// #173: the workout card can hold today's rows against your best set instead of last time.
+describe('bestSetFor', () => {
+ it('is the heaviest work set, the most reps of equally heavy ones, first time reached', () => {
+ const S = { workouts: [
+ session(0, [warm(120, 1), work(100, 5), work(100, 6)]),
+ session(2, [work(100, 6), work(90, 12)]),
+ session(4, [work(95, 8), work(110, 3, false)]),
+ ] }
+ const best = bestSetFor(S, 'bench', 'reps')
+ expect(best).toMatchObject({ d: iso(0), set: { w: 100, r: 6 }, target: { mode: 'reps' } })
+ })
+
+ it('looks across every routine and ignores the order workouts are stored in', () => {
+ const later = { ...session(3, [work(80, 5)]), entries: [{ id: 'bench', rid: 'b', target: { mode: 'reps' }, sets: [work(80, 5)] }] }
+ const earlier = { ...session(1, [work(80, 5)]), entries: [{ id: 'bench', rid: 'a', target: { mode: 'reps' }, sets: [work(80, 5)] }] }
+ expect(bestSetFor({ workouts: [later, earlier] }, 'bench', 'reps').d).toBe(iso(1))
+ })
+
+ it('compares holds by their length and cardio by its minutes, never across modes', () => {
+ const hold = (i, sec, w = 0) => ({ id: 'h' + i, d: iso(i), start: T0 + i * DAY, entries: [{ id: 'plank', target: { mode: 'time' }, sets: [{ sec, w, done: true }] }] })
+ const S = { workouts: [hold(0, 60), hold(1, 90), hold(2, 90, 10), session(3, [work(20, 5)])] }
+ expect(bestSetFor(S, 'plank', 'time')).toMatchObject({ d: iso(2), set: { sec: 90, w: 10 } })
+ // the rep sets of another exercise, and a mode the exercise was never logged in, give nothing
+ expect(bestSetFor(S, 'plank', 'reps')).toBeNull()
+ const run = (i, min, speed) => ({ id: 'r' + i, d: iso(i), start: T0 + i * DAY, entries: [{ id: 'run', target: { mode: 'cardio' }, sets: [{ min, speed, done: true }] }] })
+ expect(bestSetFor({ workouts: [run(0, 30, 9), run(1, 30, 10), run(2, 25, 12)] }, 'run', 'cardio').set).toMatchObject({ min: 30, speed: 10 })
+ })
+
+ it('takes the least help on an assistance machine, and nothing when nothing was logged', () => {
+ const id = EXDB.find(e => e.eq === 'leverage machine' && /assist/i.test(e.n)).id
+ const S = { workouts: [0, 1, 2].map(i => ({ id: 'a' + i, d: iso(i), start: T0 + i * DAY,
+ entries: [{ id, target: { mode: 'reps' }, sets: [work([30, 20, 0][i], 8)] }] })) }
+ expect(bestSetFor(S, id, 'reps').set).toMatchObject({ w: 20, r: 8 })
+ expect(bestSetFor({ workouts: [] }, 'bench', 'reps')).toBeNull()
+ expect(bestSetFor({}, 'bench')).toBeNull()
+ })
+})
diff --git a/frontend/src/lib/pt-br-locale.test.js b/frontend/src/lib/pt-br-locale.test.js
index b0bd84359..c8c9e0dd0 100644
--- a/frontend/src/lib/pt-br-locale.test.js
+++ b/frontend/src/lib/pt-br-locale.test.js
@@ -27,11 +27,11 @@ describe('Brazilian Portuguese locale', () => {
.sort(byCodeUnit)
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
- expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(680)
- expect(inherited).toHaveLength(684)
+ expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(685)
+ expect(inherited).toHaveLength(685)
// 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('c7856e07f5fae071e1729b8169b7799ef88684080a7dd7fa565e405851ddcf24')
+ expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('a94cd1e53a609359677f076b349bdefe9f964086a31a70c32aa40cc4d3e58d3c')
})
test('does not leak European Portuguese UI terms', () => {
diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js
index 920ee3e6f..c919971a2 100644
--- a/frontend/src/locales/de.js
+++ b/frontend/src/locales/de.js
@@ -1334,4 +1334,11 @@ export default {
'Weekly average': 'Wochendurchschnitt',
'Week of {0}': 'Woche vom {0}',
'Average {0}': 'Schnitt {0}',
+ // --- last time or best set under each exercise (#173) ---
+ 'Best set': 'Bester Satz',
+ 'Show last time instead': 'Stattdessen das letzte Mal zeigen',
+ 'Show your best set instead': 'Stattdessen deinen besten Satz zeigen',
+ 'Shown under each exercise': 'Unter jeder Übung angezeigt',
+ 'What you did the last time, in that routine.': 'Was du beim letzten Mal in dieser Routine gemacht hast.',
+ 'Your heaviest set of the exercise, from any workout.': 'Dein schwerster Satz der Übung, aus allen Trainings.',
}
diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js
index 229a693fc..4683dbe89 100644
--- a/frontend/src/locales/es.js
+++ b/frontend/src/locales/es.js
@@ -1314,4 +1314,11 @@ export default {
'Weekly average': 'Media semanal',
'Week of {0}': 'Semana del {0}',
'Average {0}': 'Media {0}',
+ // --- last time or best set under each exercise (#173) ---
+ 'Best set': 'Mejor serie',
+ 'Show last time instead': 'Mostrar la última vez',
+ 'Show your best set instead': 'Mostrar tu mejor serie',
+ 'Shown under each exercise': 'Debajo de cada ejercicio',
+ 'What you did the last time, in that routine.': 'Lo que hiciste la última vez en esa rutina.',
+ 'Your heaviest set of the exercise, from any workout.': 'Tu serie más pesada del ejercicio, de cualquier entrenamiento.',
}
diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js
index c63248e17..61697c232 100644
--- a/frontend/src/locales/fr.js
+++ b/frontend/src/locales/fr.js
@@ -1314,4 +1314,11 @@ export default {
'Weekly average': 'Moyenne hebdomadaire',
'Week of {0}': 'Semaine du {0}',
'Average {0}': 'Moyenne {0}',
+ // --- last time or best set under each exercise (#173) ---
+ 'Best set': 'Meilleure série',
+ 'Show last time instead': 'Afficher plutôt la dernière fois',
+ 'Show your best set instead': 'Afficher plutôt ta meilleure série',
+ 'Shown under each exercise': 'Sous chaque exercice',
+ 'What you did the last time, in that routine.': 'Ce que tu as fait la dernière fois dans cette routine.',
+ 'Your heaviest set of the exercise, from any workout.': 'Ta série la plus lourde de l’exercice, toutes séances confondues.',
}
diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js
index cb940db53..2a023396d 100644
--- a/frontend/src/locales/hi.js
+++ b/frontend/src/locales/hi.js
@@ -1314,4 +1314,11 @@ export default {
'Weekly average': 'साप्ताहिक औसत',
'Week of {0}': '{0} वाला सप्ताह',
'Average {0}': 'औसत {0}',
+ // --- last time or best set under each exercise (#173) ---
+ 'Best set': 'सर्वश्रेष्ठ सेट',
+ 'Show last time instead': 'इसके बजाय पिछली बार दिखाएँ',
+ 'Show your best set instead': 'इसके बजाय अपना सर्वश्रेष्ठ सेट दिखाएँ',
+ 'Shown under each exercise': 'हर व्यायाम के नीचे दिखाया जाता है',
+ 'What you did the last time, in that routine.': 'उस रूटीन में पिछली बार आपने जो किया।',
+ 'Your heaviest set of the exercise, from any workout.': 'किसी भी वर्कआउट से, इस व्यायाम का आपका सबसे भारी सेट।',
}
diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.js
index 994457b88..5c6f8bd97 100644
--- a/frontend/src/locales/hu.js
+++ b/frontend/src/locales/hu.js
@@ -1317,4 +1317,11 @@ export default {
'Weekly average': 'Heti átlag',
'Week of {0}': 'Hét: {0}',
'Average {0}': 'Átlag {0}',
+ // --- last time or best set under each exercise (#173) ---
+ 'Best set': 'Legjobb sorozat',
+ 'Show last time instead': 'Inkább a legutóbbit mutasd',
+ 'Show your best set instead': 'Inkább a legjobb sorozatodat mutasd',
+ 'Shown under each exercise': 'Minden gyakorlat alatt',
+ 'What you did the last time, in that routine.': 'Amit legutóbb abban a rutinban csináltál.',
+ 'Your heaviest set of the exercise, from any workout.': 'A gyakorlat legnehezebb sorozata, bármelyik edzésedből.',
}
diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js
index 96cbbc95d..4afa2d986 100644
--- a/frontend/src/locales/it.js
+++ b/frontend/src/locales/it.js
@@ -1314,4 +1314,11 @@ export default {
'Weekly average': 'Media settimanale',
'Week of {0}': 'Settimana del {0}',
'Average {0}': 'Media {0}',
+ // --- last time or best set under each exercise (#173) ---
+ 'Best set': 'Serie migliore',
+ 'Show last time instead': 'Mostra invece l’ultima volta',
+ 'Show your best set instead': 'Mostra invece la tua serie migliore',
+ 'Shown under each exercise': 'Sotto ogni esercizio',
+ 'What you did the last time, in that routine.': 'Quello che hai fatto l’ultima volta in quella routine.',
+ 'Your heaviest set of the exercise, from any workout.': 'La tua serie più pesante dell’esercizio, da qualsiasi allenamento.',
}
diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js
index b2ef74bd1..e373acd90 100644
--- a/frontend/src/locales/ko.js
+++ b/frontend/src/locales/ko.js
@@ -1314,4 +1314,11 @@ export default {
'Weekly average': '주간 평균',
'Week of {0}': '{0} 주',
'Average {0}': '평균 {0}',
+ // --- last time or best set under each exercise (#173) ---
+ 'Best set': '최고 세트',
+ 'Show last time instead': '대신 지난번 보기',
+ 'Show your best set instead': '대신 최고 세트 보기',
+ 'Shown under each exercise': '각 운동 아래에 표시',
+ 'What you did the last time, in that routine.': '그 루틴에서 지난번에 한 내용.',
+ 'Your heaviest set of the exercise, from any workout.': '모든 운동 중 이 운동의 가장 무거운 세트.',
}
diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js
index e2fb24bcd..11aa43421 100644
--- a/frontend/src/locales/pl.js
+++ b/frontend/src/locales/pl.js
@@ -1314,4 +1314,11 @@ export default {
'Weekly average': 'Średnia tygodniowa',
'Week of {0}': 'Tydzień od {0}',
'Average {0}': 'Średnio {0}',
+ // --- last time or best set under each exercise (#173) ---
+ 'Best set': 'Najlepsza seria',
+ 'Show last time instead': 'Pokaż zamiast tego ostatni raz',
+ 'Show your best set instead': 'Pokaż zamiast tego najlepszą serię',
+ 'Shown under each exercise': 'Pod każdym ćwiczeniem',
+ 'What you did the last time, in that routine.': 'Ostatni trening w tym planie treningowym.',
+ 'Your heaviest set of the exercise, from any workout.': 'Najcięższa seria tego ćwiczenia, z dowolnego treningu.',
}
diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.js
index f41fb6d45..21d82fc4e 100644
--- a/frontend/src/locales/pt-BR.js
+++ b/frontend/src/locales/pt-BR.js
@@ -712,6 +712,13 @@ export const PT_BR_OVERRIDES = {
// a missed day logged afterwards (#284) — pt-PT's "Registar" reads as Portugal; "Marcar todas
// as séries como feitas" is shared and inherits
'Log this workout': 'Registrar este treino',
+ // last time or best set under each exercise (#173) — pt-PT's "Por baixo" and tu-forms read as
+ // Portugal; "Melhor série" is shared and inherits
+ 'Show last time instead': 'Mostrar a última vez',
+ 'Show your best set instead': 'Mostrar sua melhor série',
+ 'Shown under each exercise': 'Abaixo de cada exercício',
+ 'What you did the last time, in that routine.': 'O que você fez da última vez nessa rotina.',
+ 'Your heaviest set of the exercise, from any workout.': 'Sua série mais pesada do exercício, de qualquer treino.',
}
export default { ...pt, ...PT_BR_OVERRIDES }
diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js
index 51b2d265e..e8e12a1cc 100644
--- a/frontend/src/locales/pt.js
+++ b/frontend/src/locales/pt.js
@@ -1314,4 +1314,11 @@ export default {
'Weekly average': 'Média semanal',
'Week of {0}': 'Semana de {0}',
'Average {0}': 'Média {0}',
+ // --- last time or best set under each exercise (#173) ---
+ 'Best set': 'Melhor série',
+ 'Show last time instead': 'Mostrar antes a última vez',
+ 'Show your best set instead': 'Mostrar antes a tua melhor série',
+ 'Shown under each exercise': 'Por baixo de cada exercício',
+ 'What you did the last time, in that routine.': 'O que fizeste da última vez nessa rotina.',
+ 'Your heaviest set of the exercise, from any workout.': 'A tua série mais pesada do exercício, de qualquer treino.',
}
diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js
index 3ffb150ea..d3db42499 100644
--- a/frontend/src/locales/ru.js
+++ b/frontend/src/locales/ru.js
@@ -1314,4 +1314,11 @@ export default {
'Weekly average': 'Среднее за неделю',
'Week of {0}': 'Неделя с {0}',
'Average {0}': 'В среднем {0}',
+ // --- last time or best set under each exercise (#173) ---
+ 'Best set': 'Лучший подход',
+ 'Show last time instead': 'Показать прошлый раз',
+ 'Show your best set instead': 'Показать ваш лучший подход',
+ 'Shown under each exercise': 'Под каждым упражнением',
+ 'What you did the last time, in that routine.': 'Что вы сделали в прошлый раз в этой программе.',
+ 'Your heaviest set of the exercise, from any workout.': 'Ваш самый тяжёлый подход в этом упражнении, из любой тренировки.',
}
diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.js
index a8ff62fe8..15c12dac1 100644
--- a/frontend/src/locales/th.js
+++ b/frontend/src/locales/th.js
@@ -1325,4 +1325,11 @@ export default {
'Weekly average': 'ค่าเฉลี่ยรายสัปดาห์',
'Week of {0}': 'สัปดาห์เริ่ม {0}',
'Average {0}': 'เฉลี่ย {0}',
+ // --- last time or best set under each exercise (#173) ---
+ 'Best set': 'เซ็ตที่ดีที่สุด',
+ 'Show last time instead': 'แสดงครั้งก่อนแทน',
+ 'Show your best set instead': 'แสดงเซ็ตที่ดีที่สุดของคุณแทน',
+ 'Shown under each exercise': 'แสดงใต้แต่ละท่า',
+ 'What you did the last time, in that routine.': 'สิ่งที่คุณทำครั้งก่อนในรูทีนนั้น',
+ 'Your heaviest set of the exercise, from any workout.': 'เซ็ตที่หนักที่สุดของท่านี้ จากทุกการฝึก',
}
diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js
index 0f0eb548a..80a20370a 100644
--- a/frontend/src/locales/tr.js
+++ b/frontend/src/locales/tr.js
@@ -1314,4 +1314,11 @@ export default {
'Weekly average': 'Haftalık ortalama',
'Week of {0}': '{0} haftası',
'Average {0}': 'Ortalama {0}',
+ // --- last time or best set under each exercise (#173) ---
+ 'Best set': 'En iyi set',
+ 'Show last time instead': 'Bunun yerine geçen seferi göster',
+ 'Show your best set instead': 'Bunun yerine en iyi setini göster',
+ 'Shown under each exercise': 'Her egzersizin altında',
+ 'What you did the last time, in that routine.': 'O rutinde geçen sefer yaptıkların.',
+ 'Your heaviest set of the exercise, from any workout.': 'Bu egzersizdeki en ağır setin, herhangi bir antrenmandan.',
}
diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js
index 48196c56b..9d6893446 100644
--- a/frontend/src/locales/zh.js
+++ b/frontend/src/locales/zh.js
@@ -1314,4 +1314,11 @@ export default {
'Weekly average': '每周平均',
'Week of {0}': '{0} 起的一周',
'Average {0}': '平均 {0}',
+ // --- last time or best set under each exercise (#173) ---
+ 'Best set': '最佳组',
+ 'Show last time instead': '改为显示上次',
+ 'Show your best set instead': '改为显示你的最佳组',
+ 'Shown under each exercise': '每个动作下方显示',
+ 'What you did the last time, in that routine.': '上次在该训练日完成的内容。',
+ 'Your heaviest set of the exercise, from any workout.': '该动作在所有训练中最重的一组。',
}
diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.js
index b97f9cc7b..e17c41153 100644
--- a/frontend/src/store/useStore.js
+++ b/frontend/src/store/useStore.js
@@ -101,6 +101,10 @@ export const DEF = {
// weight; 'last' carries the reps over from the last session, the way it always worked before.
// Absent reads as 'plan' too, which is what the MCP bridge sees on a raw state file.
startFrom: 'plan',
+ // What the line under an exercise holds today's rows against (#173, views/Workout.jsx): 'last'
+ // is the last time in that routine, 'best' the best set of the exercise ever logged. Tapping
+ // the line switches it. Absent reads as 'last', the line as it always was.
+ logRef: 'last',
}
const clone = o => JSON.parse(JSON.stringify(o))
diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsx
index a82efcf33..71f86bca3 100644
--- a/frontend/src/views/Settings.jsx
+++ b/frontend/src/views/Settings.jsx
@@ -311,6 +311,14 @@ export default function Settings() {
{ value: 'plan', label: t('Your plan'), subtitle: t('The routine’s sets and reps. Your history decides the weight.') },
{ value: 'last', label: t('Your last session'), subtitle: t('The reps you logged last time in that routine, carried over.') },
]} />
+ {/* The line under each exercise that the rows are held against (#173). Tapping the line in
+ a workout switches it too; this is where the choice can be found without knowing that. */}
+ <SelectRow icon="history" iconTint="var(--blue)" title={t('Shown under each exercise')}
+ value={S.logRef === 'best' ? 'best' : 'last'} onChange={v => update(s => { s.logRef = v })}
+ options={[
+ { value: 'last', label: t('Last time'), subtitle: t('What you did the last time, in that routine.') },
+ { value: 'best', label: t('Best set'), subtitle: t('Your heaviest set of the exercise, from any workout.') },
+ ]} />
{/* The lean workout screen keeps the sets and one "more" button per exercise; each switch
brings one of the old always-visible button groups back for people who liked them. */}
<Row icon="wrench" iconTint="var(--purple)" title={t('Workout controls')} accessory="chevron"
diff --git a/frontend/src/views/Settings.logref.test.jsx b/frontend/src/views/Settings.logref.test.jsx
new file mode 100644
index 000000000..7a3518906
--- /dev/null
+++ b/frontend/src/views/Settings.logref.test.jsx
@@ -0,0 +1,106 @@
+// @vitest-environment happy-dom
+import React, { act } from 'react'
+import { createRoot } from 'react-dom/client'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import Settings from './Settings.jsx'
+import { bindUI } from '../components/ui.jsx'
+
+globalThis.IS_REACT_ACT_ENVIRONMENT = true
+
+const mocks = vi.hoisted(() => {
+ const state = { S: null }
+ state.snapshot = () => ({
+ S: state.S,
+ user: null,
+ update: mut => {
+ const next = structuredClone(state.S)
+ mut(next)
+ state.S = next
+ },
+ replaceState: vi.fn(), setUser: vi.fn(), pullState: vi.fn(), pushState: vi.fn(),
+ signOut: vi.fn(), signOutAll: vi.fn(), resetDemo: vi.fn(), disconnectServer: vi.fn(),
+ })
+ return state
+})
+vi.mock('../store/useStore.js', () => {
+ const useStore = selector => selector ? selector(mocks.snapshot()) : mocks.snapshot()
+ useStore.getState = mocks.snapshot
+ return { useStore, DEF: { reminder: { time: '17:30' } }, hasData: () => false }
+})
+vi.mock('../store/useUI.js', () => {
+ const snap = () => ({ toast: vi.fn(), openSheet: vi.fn() })
+ const useUI = selector => selector ? selector(snap()) : snap()
+ useUI.getState = snap
+ return { useUI }
+})
+vi.mock('react-router-dom', () => ({ useNavigate: () => () => {} }))
+vi.mock('../lib/api.js', () => ({
+ api: vi.fn(), webauthnOK: () => false, passkeyLogin: vi.fn(), passkeyRegister: vi.fn(), IS_ANDROID: false,
+}))
+vi.mock('../lib/push.js', () => ({ pushSupported: () => false, enablePush: vi.fn(), disablePush: vi.fn(), sendTestPush: vi.fn() }))
+vi.mock('../lib/wakelock.js', () => ({ wakeLockSupported: () => false }))
+vi.mock('../lib/mobile.js', () => ({ MOBILE: false, isAndroid: () => Promise.resolve(false), shareExport: vi.fn(), syncReminder: vi.fn() }))
+vi.mock('./MobileOnboarding.jsx', () => ({ ConnectSheet: () => null }))
+vi.mock('../sheets.jsx', () => ({
+ loadStarterPlan: vi.fn(), starterPlanSheet: vi.fn(), confirmSheet: vi.fn(), importFromApp: vi.fn(),
+ importFromHevy: vi.fn(), equipmentProfileSheet: vi.fn(),
+}))
+
+// The Settings view reads the build-time version constant at render time.
+globalThis.__APP_VERSION__ ??= 'test'
+
+// SelectRow opens its choices through the bound UI store; capture the sheet to render it here.
+let sheet = null
+bindUI({ getState: () => ({ openSheet: render => { sheet = render; return { close: () => {} } } }) })
+
+let host, root
+beforeEach(() => {
+ sheet = null
+ mocks.S = {
+ unit: 'kg', restSec: 90, restPauseSec: 15, sound: false, effort: 'none',
+ gifSize: 'full', workouts: [], routines: [], exWeights: {},
+ }
+ host = document.createElement('div')
+ document.body.appendChild(host)
+ root = createRoot(host)
+})
+afterEach(() => {
+ act(() => root.unmount())
+ host.remove()
+})
+
+const mount = () => act(() => root.render(<Settings />))
+const row = () => [...host.querySelectorAll('.lrow')].find(r => r.textContent.includes('Shown under each exercise'))
+const choose = label => {
+ act(() => { row().click() })
+ expect(sheet).toBeTypeOf('function')
+ const box = document.createElement('div')
+ document.body.appendChild(box)
+ const sheetRoot = createRoot(box)
+ act(() => sheetRoot.render(sheet(() => {})))
+ const option = [...box.querySelectorAll('button.lrow')].find(b => b.querySelector('.lrow-t')?.textContent === label)
+ expect(option).toBeTruthy()
+ act(() => { option.click() })
+ act(() => sheetRoot.unmount())
+ box.remove()
+}
+
+// #173: the line under each exercise can hold the rows against the best set instead of last time.
+// The workout switches it with a tap on the line; Settings is where the choice can be found.
+describe('Settings — shown under each exercise', () => {
+ it('reads an older profile without the setting as last time', () => {
+ mount()
+ expect(row()).toBeTruthy()
+ expect(row().textContent).toContain('Last time')
+ })
+
+ it('switches to the best set and back, writing logRef to the store', () => {
+ mount()
+ choose('Best set')
+ expect(mocks.S.logRef).toBe('best')
+ mount()
+ expect(row().textContent).toContain('Best set')
+ choose('Last time')
+ expect(mocks.S.logRef).toBe('last')
+ })
+})
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx
index 306bcec53..c1021fce1 100644
--- a/frontend/src/views/Workout.jsx
+++ b/frontend/src/views/Workout.jsx
@@ -21,6 +21,7 @@ import { progressionGuidance } from '../lib/progression-copy.js'
import { buildPlannedEntry, plannedConfigOf } from '../lib/session-start.js'
import { glyphOf } from '../lib/glyphs.js'
import { markAllSetsDone } from '../lib/backfill.js'
+import { bestSetFor } from '../lib/exercise-history.js'
import { isWarmupRow, isDropSet, isRestPauseSet, dropsOf, clustersOf, addDrop, addCluster, removeDropAt, removeClusterAt, setDropAt, setClusterAt, nextDropWeight, nextBurstReps, isSideSet, makeSideSet, setSideField, toggleSide, addSideDrop, removeSideDropAt, setSideDropAt, addSideCluster, removeSideClusterAt, setSideClusterAt } from '../lib/workout-model.js'
import { canMoveActiveWorkoutUnit, moveActiveWorkoutUnit } from '../lib/active-workout-order.js'
import { MUSCLE_NAME } from '../lib/muscles.js'
@@ -169,6 +170,18 @@ function ExerciseBlock({ entryIdx, compact, dense, onToggle, onToggleSide, onFie
{t('Plan: {0}', setsRepsOf({ ...planned, mode }))}{note ? ' · ' + note : ''}
</div>
})()
+ // What the rows are held against (#173): the last time in this routine (#216), or the best set
+ // of the exercise ever logged — after a bad day, "last time" puts the bad day on the screen as
+ // the number to beat. Tapping the line switches between the two, and the choice is the
+ // profile's (S.logRef), so every exercise and the next session follow it.
+ const refBest = S.logRef === 'best'
+ const ref = refBest ? bestSetFor(S, entry.id, mode) : last
+ const refLine = ref ? <button type="button" className="refline small dim"
+ title={refBest ? t('Show last time instead') : t('Show your best set instead')}
+ onClick={() => update(s => { s.logRef = refBest ? 'last' : 'best' })}>
+ <span>{refBest ? t('Best set') : t('Last time')} ({fmtDate(ref.d)}): {(refBest ? [ref.set] : ref.sets).map(s => setLabel(entry.id, s, ref.target)).join(', ')}</span>
+ <Icon name="shuffle" />
+ </button> : null
// A bodyweight set has no weight to type, so the column is not there (issue #32) — one
// stepper instead of two, which is the whole point of the flag. Adding a belt weight in the
// config brings it back, now labelled as the addition it is.
@@ -431,7 +444,7 @@ function ExerciseBlock({ entryIdx, compact, dense, onToggle, onToggleSide, onFie
</div>}
{entry.note && <div className="exnote">{entry.note}</div>}
{planLine}
- {last && <div className="small dim" style={{ marginBottom: 4 }}>{t('Last time')} ({fmtDate(last.d)}): {last.sets.map(s => setLabel(entry.id, s, last.target)).join(', ')}</div>}
+ {refLine}
{/* Bar + plates for barbell work: what to load per side for the set in front of you
(first undone set; the heaviest row once everything is checked). The logged number
stays the total — this chip is the split, and tapping it edits the bar's own weight
diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsx
index 4179b7349..85795a87e 100644
--- a/frontend/src/views/Workout.test.jsx
+++ b/frontend/src/views/Workout.test.jsx
@@ -1706,6 +1706,31 @@ describe('set-row column header', () => {
})
})
+// #173: the line under an exercise holds the rows against the last time in this routine, or
+// against the best set of the exercise; tapping the line switches, for every exercise.
+describe('the reference line: last time or best set', () => {
+ const session = (d, rid, w, r) => ({ d, start: Date.parse(d + 'T18:00:00'), routineIds: [rid], entries: [{ id: 'plain-bench', rid, target: { reps: r, weight: w }, sets: [{ w, r, done: true }] }] })
+ const history = [session('2026-08-10', 'B', 80, 5), session('2026-08-24', 'A', 60, 10), session('2026-08-26', 'A', 55, 8)]
+ const line = () => container.querySelector('.refline')
+
+ it('reads last time in this routine by default, and the best set once switched', async () => {
+ await mount([exercise('plain-bench', [false], { rid: 'A' })], 0, { workouts: history })
+ expect(line().textContent).toMatch(/^Last time \(.+\): 55×8$/)
+ await act(async () => { line().dispatchEvent(new dom.Event('click', { bubbles: true })) })
+ expect(mocks.S.logRef).toBe('best')
+ await rerender()
+ // the heaviest set of the exercise from any routine, not just this one
+ expect(line().textContent).toMatch(/^Best set \(.+\): 80×5$/)
+ await act(async () => { line().dispatchEvent(new dom.Event('click', { bubbles: true })) })
+ expect(mocks.S.logRef).toBe('last')
+ })
+
+ it('is not there before the exercise was ever logged', async () => {
+ await mount([exercise('plain-bench', [false])], 0, { logRef: 'best' })
+ expect(line()).toBeNull()
+ })
+})
+
// #284: logging a past workout that went as planned takes one tap, not one per set.
describe('mark all sets done while logging a past workout', () => {
const openMenu = async () => {