Merge PR #21: optional RIR column on reps-mode sets
octaviodimarco's RIR (reps in reserve) stepper for reps-mode sets, opt-in under Settings → Units & timer, plus a fixup for the leftover RIR-0 stamp and the header alignment.
This commit is contained in:
commit
fa978a1bb4
18 files changed
+105
-11
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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) */
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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',
|
||||
}
|
||||
@@ -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',
|
||||
}
|
||||
@@ -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',
|
||||
}
|
||||
@@ -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 कॉलम दिखाएं',
|
||||
}
|
||||
@@ -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',
|
||||
}
|
||||
@@ -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 열 표시',
|
||||
}
|
||||
@@ -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',
|
||||
}
|
||||
@@ -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',
|
||||
}
|
||||
@@ -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',
|
||||
}
|
||||
@@ -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',
|
||||
}
|
||||
@@ -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列',
|
||||
}
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -133,6 +133,9 @@ export default function Settings() {
|
||||
<Row icon="bell" iconTint="var(--pink)" title={t('Sounds')}>
|
||||
<Switch checked={!!S.sound} onChange={v => update(s => { s.sound = v })} />
|
||||
</Row>
|
||||
<Row icon="target" iconTint="var(--purple)" title={t('Show RIR column')}>
|
||||
<Switch checked={!!S.showRir} onChange={v => update(s => { s.showRir = v })} />
|
||||
</Row>
|
||||
</Section>
|
||||
|
||||
{(user || MOBILE) && <NotificationsCard S={S} update={update} toast={toast} />}
|
||||
|
||||
@@ -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) => (
|
||||
<div className={'stp ' + cls}>
|
||||
<button aria-label="Decrease" onClick={() => onField(i, col.f, Math.max(0, Math.round(((s[col.f] || 0) - col.step) * 100) / 100))}><Icon name="minus" /></button>
|
||||
<span className="val"><NumberField decimal={col.dec} value={s[col.f] ?? ''} onChange={v => onField(i, col.f, v)} /></span>
|
||||
<button aria-label="Increase" onClick={() => onField(i, col.f, Math.max(0, Math.round(((s[col.f] || 0) + col.step) * 100) / 100))}><Icon name="plus" /></button>
|
||||
<button aria-label="Decrease" onClick={() => bump(s, i, col, -1)}><Icon name="minus" /></button>
|
||||
<span className="val"><NumberField decimal={col.dec} nullable={col.opt} value={s[col.f] ?? ''} onChange={v => onField(i, col.f, v)} /></span>
|
||||
<button aria-label="Increase" onClick={() => bump(s, i, col, 1)}><Icon name="plus" /></button>
|
||||
</div>
|
||||
)
|
||||
return <>
|
||||
@@ -102,11 +114,13 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov
|
||||
<span>{t(...plan.why)}</span>
|
||||
</div>}
|
||||
<div className="card" style={{ marginTop: 10, marginBottom: 0 }}>
|
||||
<div className="sethead"><span className="n-sp" /><span className="w-sp">{col1.hd}</span><span className="r-sp">{col2.hd}</span>{timed && <span className="ck-sp" />}<span className="ck-sp" /></div>
|
||||
{entry.sets.map((s, i) => <div key={i} className={'setrow' + (s.done ? ' done' : '')}>
|
||||
{/* the header carries the same rir3 sizing as the rows, or the labels drift off their columns */}
|
||||
<div className={'sethead' + (col3 ? ' rir3' : '')}><span className="n-sp" /><span className="w-sp">{col1.hd}</span><span className="r-sp">{col2.hd}</span>{col3 && <span className="rir-sp">{col3.hd}</span>}{timed && <span className="ck-sp" />}<span className="ck-sp" /></div>
|
||||
{entry.sets.map((s, i) => <div key={i} className={'setrow' + (s.done ? ' done' : '') + (col3 ? ' rir3' : '')}>
|
||||
<div className="n">{i + 1}</div>
|
||||
{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 && <button className="setgo" aria-label={t('Start set')} disabled={s.done || !!working}
|
||||
@@ -139,7 +153,11 @@ function ActiveWorkout() {
|
||||
const done = setsDoneActive(A)
|
||||
|
||||
const mutEntry = (idx, fn) => update(s => { fn(s.active.entries[idx]) }, true)
|
||||
const setField = (idx, i, field, v) => mutEntry(idx, e => { e.sets[i][field] = v })
|
||||
// Clearing an optional field drops the key rather than storing null, so a set only carries
|
||||
// what was actually logged — in the session, in history and in a backup.
|
||||
const setField = (idx, i, field, v) => mutEntry(idx, e => {
|
||||
if (v == null) delete e.sets[i][field]; else e.sets[i][field] = v
|
||||
})
|
||||
const modeAt = idx => modeOf({ ...(A.entries[idx].target || {}), id: A.entries[idx].id })
|
||||
const addSet = idx => mutEntry(idx, e => {
|
||||
const l = e.sets[e.sets.length - 1]
|
||||
|
||||
Reference in new issue
Block a user