diff --git a/frontend/src/components/ui.jsx b/frontend/src/components/ui.jsx index 0cd6404..3a1a672 100644 --- a/frontend/src/components/ui.jsx +++ b/frontend/src/components/ui.jsx @@ -21,15 +21,18 @@ import Icon from './Icon.jsx' // Numeric input accepting "," as decimal separator — iOS decimal keypads in many // locales only offer a comma, and type="number" reports "" for it (value snaps to // 0). Keeps a local string draft while focused so partial input like "33," survives. -export function NumberField({ value, onChange, decimal = true, className = '', ...rest }) { +// `nullable` is for fields where "nothing entered" and 0 mean different things (RIR: a +// logged 0 is a set taken to failure). Those clear back to null instead of snapping to 0. +export function NumberField({ value, onChange, decimal = true, nullable = false, className = '', ...rest }) { const [draft, setDraft] = useState(null) const committed = useRef(null) - if (draft !== null && committed.current !== value) { setDraft(null); committed.current = null } + // null and undefined are the same "empty" here — a nullable field's key is dropped once cleared. + if (draft !== null && (committed.current ?? null) !== (value ?? null)) { setDraft(null); committed.current = null } const commit = raw => { let s = raw.replace(/,/g, '.').replace(/[^0-9.]/g, '') const i = s.indexOf('.') if (i !== -1) s = decimal ? s.slice(0, i + 1) + s.slice(i + 1).replace(/\./g, '') : s.slice(0, i) - const n = s === '' || s === '.' ? 0 : Math.max(0, parseFloat(s)) + const n = s === '' || s === '.' ? (nullable ? null : 0) : Math.max(0, parseFloat(s)) committed.current = n setDraft(s) onChange(n) diff --git a/frontend/src/index.css b/frontend/src/index.css index 386bd62..5f74027 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -539,6 +539,7 @@ h4.sec{ .sethead .n-sp{width:24px;flex:none} .sethead .w-sp{flex:1.4;text-align:center} .sethead .r-sp{flex:1;text-align:center} +.sethead .rir-sp{text-align:center} .sethead .ck-sp{width:30px;flex:none} .setrow{display:flex;align-items:center;gap:8px;padding:7px 0;position:relative} .setrow+.setrow::before{ @@ -551,7 +552,20 @@ h4.sec{ } .setrow .stp.w{flex:1.4;min-width:0} .setrow .stp.r{flex:1;min-width:0} +.setrow .stp.rir{flex:1.1;min-width:0} .setrow .stp button{width:32px;height:40px} +/* a 3rd stepper (RIR) needs narrower buttons and a tighter row gap to fit next to weight+reps + on narrow phones, same technique as the exercise-config sheet's three-steppers-in-a-row + (.cfgrow below) — RIR's own value is short ("1.5") so its buttons shrink the most, weight/reps + just enough to make room since their values ("82.5", "12") need more of what's left. + The header shares the numbers so its labels stay centred over the steppers they name. */ +.setrow.rir3,.sethead.rir3{gap:6px} +.setrow.rir3 .stp.w,.sethead.rir3 .w-sp{flex:1.2} +.setrow.rir3 .stp.r,.sethead.rir3 .r-sp{flex:1} +.setrow.rir3 .stp.rir,.sethead.rir3 .rir-sp{flex:.85} +.setrow.rir3 .stp button{width:23px} +.setrow.rir3 .stp.rir button{width:20px} +.setrow.rir3 .stp .num{font-size:14px} .setrow.done .n{background:var(--acc);color:var(--on-acc)} .setrow.done{opacity:.45} /* why the next target is what it is (issue #17) */ diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.js index e9d7739..65e541e 100644 --- a/frontend/src/lib/history.js +++ b/frontend/src/lib/history.js @@ -29,7 +29,7 @@ export function setLabel(id, s, cfg) { const mode = modeOf(cfg || { id }) if (mode === 'cardio') return `${s.min || 0} min @ ${fmtNum(s.speed || 0)} km/h` if (mode === 'time') return fmtSec(s.sec) + (s.w > 0 ? ` · ${fmtNum(s.w)}` : '') - return `${fmtNum(s.w || 0)}×${s.r || 0}` + return `${fmtNum(s.w || 0)}×${s.r || 0}` + (s.rir != null ? ` (RIR ${fmtNum(s.rir)})` : '') } // Default config for a freshly added exercise. export function defaultConfig(id, mode) { diff --git a/frontend/src/lib/history.test.js b/frontend/src/lib/history.test.js index 19d3944..77bda11 100644 --- a/frontend/src/lib/history.test.js +++ b/frontend/src/lib/history.test.js @@ -63,6 +63,18 @@ describe('setLabel', () => { expect(setLabel(LIFT, { w: 0, r: 0 })).toBe('0×0') expect(setLabel(CARDIO, {})).toBe('0 min @ 0 km/h') }) + + it('appends RIR when present, including a valid 0', () => { + expect(setLabel(LIFT, { w: 60, r: 10, rir: 2 })).toBe('60×10 (RIR 2)') + expect(setLabel(LIFT, { w: 60, r: 10, rir: 1.5 })).toBe('60×10 (RIR 1.5)') + expect(setLabel(LIFT, { w: 60, r: 10, rir: 0 })).toBe('60×10 (RIR 0)') + }) + + it('says nothing about RIR on a set that never logged one', () => { + expect(setLabel(LIFT, { w: 60, r: 10 })).toBe('60×10') + // cleared in the UI: the key is dropped, but a null must read the same as absent + expect(setLabel(LIFT, { w: 60, r: 10, rir: null })).toBe('60×10') + }) }) describe('defaultConfig', () => { diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js index c21e195..b224935 100644 --- a/frontend/src/locales/de.js +++ b/frontend/src/locales/de.js @@ -511,4 +511,8 @@ export default { 'Missed reps last time — same weight again ({0} of {1} to go).': 'Letztes Mal Wiederholungen verfehlt — dasselbe Gewicht noch einmal (noch {0} von {1}).', 'Bodyweight — every rep last time, so go for {0} this time.': 'Körpergewicht — letztes Mal jede Wiederholung, also diesmal {0} anpeilen.', 'Bodyweight — same target again until every set is clean.': 'Körpergewicht — dieselbe Vorgabe, bis jeder Satz sauber sitzt.', + + // --- RIR (reps in reserve) --- + 'RIR': 'RIR', + 'Show RIR column': 'RIR-Spalte anzeigen', } diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js index e998b0a..93f8d6a 100644 --- a/frontend/src/locales/es.js +++ b/frontend/src/locales/es.js @@ -493,4 +493,8 @@ export default { 'Missed reps last time — same weight again ({0} of {1} to go).': 'Fallaste repeticiones la última vez: el mismo peso otra vez (quedan {0} de {1}).', 'Bodyweight — every rep last time, so go for {0} this time.': 'Peso corporal: la última vez todas las repeticiones, así que ve a por {0} esta vez.', 'Bodyweight — same target again until every set is clean.': 'Peso corporal: el mismo objetivo hasta que todas las series salgan limpias.', + + // --- RIR (reps in reserve) --- + 'RIR': 'RIR', + 'Show RIR column': 'Mostrar columna de RIR', } diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js index 3791da6..c4f59b7 100644 --- a/frontend/src/locales/fr.js +++ b/frontend/src/locales/fr.js @@ -493,4 +493,8 @@ export default { 'Missed reps last time — same weight again ({0} of {1} to go).': 'Répétitions manquées la dernière fois — même poids à nouveau ({0} sur {1} restants).', 'Bodyweight — every rep last time, so go for {0} this time.': 'Poids du corps — toutes les répétitions la dernière fois, alors vise {0} cette fois.', 'Bodyweight — same target again until every set is clean.': 'Poids du corps — même objectif jusqu’à ce que chaque série soit propre.', + + // --- RIR (reps in reserve) --- + 'RIR': 'RIR', + 'Show RIR column': 'Afficher la colonne RIR', } diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js index 8349e26..47e9e5e 100644 --- a/frontend/src/locales/hi.js +++ b/frontend/src/locales/hi.js @@ -493,4 +493,8 @@ export default { 'Missed reps last time — same weight again ({0} of {1} to go).': 'पिछली बार रेप्स चूके — वही वज़न दोबारा ({1} में से {0} बाकी)।', 'Bodyweight — every rep last time, so go for {0} this time.': 'बॉडीवेट — पिछली बार सारे रेप्स, तो इस बार {0} का लक्ष्य रखें।', 'Bodyweight — same target again until every set is clean.': 'बॉडीवेट — जब तक हर सेट साफ़ न हो, वही लक्ष्य।', + + // --- RIR (reps in reserve) --- + 'RIR': 'RIR', + 'Show RIR column': 'RIR कॉलम दिखाएं', } diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js index f6d6b1e..6ef1363 100644 --- a/frontend/src/locales/it.js +++ b/frontend/src/locales/it.js @@ -493,4 +493,8 @@ export default { 'Missed reps last time — same weight again ({0} of {1} to go).': 'Ripetizioni mancate l’ultima volta: stesso peso ancora ({0} di {1} rimasti).', 'Bodyweight — every rep last time, so go for {0} this time.': 'Corpo libero — l’ultima volta tutte le ripetizioni, quindi punta a {0} stavolta.', 'Bodyweight — same target again until every set is clean.': 'Corpo libero — stesso obiettivo finché ogni serie non è pulita.', + + // --- RIR (reps in reserve) --- + 'RIR': 'RIR', + 'Show RIR column': 'Mostra colonna RIR', } diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js index 9e0ff61..10f278b 100644 --- a/frontend/src/locales/ko.js +++ b/frontend/src/locales/ko.js @@ -493,4 +493,8 @@ export default { 'Missed reps last time — same weight again ({0} of {1} to go).': '지난번 목표 횟수 미달 — 같은 무게로 한 번 더 ({1}회 중 {0}회 남음).', 'Bodyweight — every rep last time, so go for {0} this time.': '맨몸 운동 — 지난번 전 세트 완수, 이번엔 {0}회를 노려보세요.', 'Bodyweight — same target again until every set is clean.': '맨몸 운동 — 모든 세트가 깔끔해질 때까지 같은 목표로.', + + // --- RIR (reps in reserve) --- + 'RIR': 'RIR', + 'Show RIR column': 'RIR 열 표시', } diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js index d529ecc..b5a5d03 100644 --- a/frontend/src/locales/pl.js +++ b/frontend/src/locales/pl.js @@ -493,4 +493,8 @@ export default { 'Missed reps last time — same weight again ({0} of {1} to go).': 'Ostatnio nieudane powtórzenia — ten sam ciężar jeszcze raz (zostało {0} z {1}).', 'Bodyweight — every rep last time, so go for {0} this time.': 'Masa własna — ostatnio wszystkie powtórzenia, więc tym razem celuj w {0}.', 'Bodyweight — same target again until every set is clean.': 'Masa własna — ten sam cel, dopóki każda seria nie będzie czysta.', + + // --- RIR (reps in reserve) --- + 'RIR': 'RIR', + 'Show RIR column': 'Pokaż kolumnę RIR', } diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js index 44dfb85..67f0a75 100644 --- a/frontend/src/locales/pt.js +++ b/frontend/src/locales/pt.js @@ -493,4 +493,8 @@ export default { 'Missed reps last time — same weight again ({0} of {1} to go).': 'Falhaste repetições da última vez — o mesmo peso outra vez (faltam {0} de {1}).', 'Bodyweight — every rep last time, so go for {0} this time.': 'Peso do corpo — da última vez todas as repetições, por isso vai a {0} desta vez.', 'Bodyweight — same target again until every set is clean.': 'Peso do corpo — o mesmo objetivo até todas as séries saírem limpas.', + + // --- RIR (reps in reserve) --- + 'RIR': 'RIR', + 'Show RIR column': 'Mostrar coluna de RIR', } diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js index af234b5..001291b 100644 --- a/frontend/src/locales/ru.js +++ b/frontend/src/locales/ru.js @@ -493,4 +493,8 @@ export default { 'Missed reps last time — same weight again ({0} of {1} to go).': 'В прошлый раз повторения не дались — тот же вес ещё раз (осталось {0} из {1}).', 'Bodyweight — every rep last time, so go for {0} this time.': 'Собственный вес — в прошлый раз все повторения, так что в этот раз целься на {0}.', 'Bodyweight — same target again until every set is clean.': 'Собственный вес — та же цель, пока все подходы не станут чистыми.', + + // --- RIR (reps in reserve) --- + 'RIR': 'RIR', + 'Show RIR column': 'Показывать столбец RIR', } diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js index cc17d37..de87f72 100644 --- a/frontend/src/locales/tr.js +++ b/frontend/src/locales/tr.js @@ -493,4 +493,8 @@ export default { 'Missed reps last time — same weight again ({0} of {1} to go).': 'Geçen sefer tekrarlar eksikti — aynı ağırlık bir kez daha ({1} denemeden {0} kaldı).', 'Bodyweight — every rep last time, so go for {0} this time.': 'Vücut ağırlığı — geçen sefer bütün tekrarlar tamamdı, bu sefer {0} hedefle.', 'Bodyweight — same target again until every set is clean.': 'Vücut ağırlığı — her set temiz çıkana kadar aynı hedef.', + + // --- RIR (reps in reserve) --- + 'RIR': 'RIR', + 'Show RIR column': 'RIR sütununu göster', } diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js index 0f85569..8b1f28d 100644 --- a/frontend/src/locales/zh.js +++ b/frontend/src/locales/zh.js @@ -493,4 +493,8 @@ export default { 'Missed reps last time — same weight again ({0} of {1} to go).': '上次次数未完成——再用同样的重量(还剩 {0}/{1} 次)。', 'Bodyweight — every rep last time, so go for {0} this time.': '徒手动作——上次全部完成,这次冲 {0} 次。', 'Bodyweight — same target again until every set is clean.': '徒手动作——保持同样的目标,直到每组都做干净。', + + // --- RIR (reps in reserve) --- + 'RIR': 'RIR', + 'Show RIR column': '显示RIR列', } diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.js index 5004767..9bdb253 100644 --- a/frontend/src/store/useStore.js +++ b/frontend/src/store/useStore.js @@ -11,7 +11,7 @@ export const DEF = { theme: 'dark', accent: 'lime', body: 'male', targetW: null, bodyweight: [], routines: [], week: {}, dayPlan: {}, exWeights: {}, workouts: [], active: null, customEx: [], gifSize: 'full', - reminder: { on: false, time: '08:00', tz: null } + reminder: { on: false, time: '08:00', tz: null }, showRir: false } const clone = o => JSON.parse(JSON.stringify(o)) diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsx index 86f8763..59fee80 100644 --- a/frontend/src/views/Settings.jsx +++ b/frontend/src/views/Settings.jsx @@ -133,6 +133,9 @@ export default function Settings() { update(s => { s.sound = v })} /> + + update(s => { s.showRir = v })} /> + {(user || MOBILE) && } diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx index b5c2329..892deff 100644 --- a/frontend/src/views/Workout.jsx +++ b/frontend/src/views/Workout.jsx @@ -75,13 +75,25 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov const col2 = cardio ? { f: 'speed', step: 0.5, dec: true, hd: t('Speed (km/h)') } : timed ? { f: 'w', step: 2.5, dec: true, hd: t('Weight ({0})', S.unit) } : { f: 'r', step: 1, dec: false, hd: t('Reps') } + // RIR (reps in reserve) only makes sense for weighted rep sets, not cardio/timed holds, + // and is opt-in (Settings) since it adds a third stepper to every row. `opt` because an + // unlogged RIR is not the same as RIR 0 — 0 says the set went to failure. + const col3 = mode === 'reps' && S.showRir ? { f: 'rir', step: 0.5, dec: true, opt: true, hd: t('RIR') } : null + // Stepping an optional field that was never filled in stays empty rather than clamping to 0: + // otherwise one stray − on a fresh row stamps "(RIR 0)" on the set for good. Going down from + // 0.5 still reaches a real 0. + const bump = (s, i, col, dir) => { + const cur = s[col.f] + if (col.opt && cur == null && dir < 0) return + onField(i, col.f, Math.max(0, Math.round(((cur || 0) + dir * col.step) * 100) / 100)) + } // Uses the shared stepper markup so a set row picks up the same control styling // as every other +/- field in the app. const cell = (s, i, col, cls) => (
- - onField(i, col.f, v)} /> - + + onField(i, col.f, v)} /> +
) return <> @@ -102,11 +114,13 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov {t(...plan.why)} }
-
{col1.hd}{col2.hd}{timed && }
- {entry.sets.map((s, i) =>
+ {/* the header carries the same rir3 sizing as the rows, or the labels drift off their columns */} +
{col1.hd}{col2.hd}{col3 && {col3.hd}}{timed && }
+ {entry.sets.map((s, i) =>
{i + 1}
{cell(s, i, col1, 'w')} {cell(s, i, col2, 'r')} + {col3 && cell(s, i, col3, 'rir')} {/* A timed set is started, not typed: the timer counts the hold down and checks the set off itself. The checkbox stays for anyone who timed it on their own watch. */} {timed &&