Numbers follow the UI language, volume stays in your own unit

fmtNum was pinned to en-CH, so every user in every one of the twelve
languages got Swiss apostrophes: "7'535 kg". It now uses the same locale
as the dates.

fmtVol turned anything over 10 000 into tonnes regardless of the profile's
unit — "18.8t" is meaningless for a pound profile, and inside one history
list "18.8t" next to "7'535 kg" is two numbers you can't compare. Volume
is now always shown in the unit you train in.

The weight slider's ceiling of 300 was a kg number applied to both units;
in pounds it cut off at 136 kg, below plenty of people's body weight and
well below an everyday squat. It now follows the unit.

Also: a shared exCount() so "1 exercises" reads "1 exercise", and
durPart() so imported workouts (which carry no clock) stop claiming
"0 min".
This commit is contained in:
Duarte Santos committed 2026-07-24 23:44:20 +02:00
1 parent 238b435c2b
commit c8a68e37e1
3 files changed
+26 -12

No files matched your search

+12 -7
View File
@@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from 'react'
import { useStore } from './store/useStore.js'
import { useUI } from './store/useUI.js'
import { EXDB, EXIDX, BODYPARTS, isCardio, allExercises, equipmentOf } from './lib/exercises.js'
import { fmtDate, fmtNum, fmtVol, fmtDur, todayISO, uid, DAYN, MONTHS_LONG, ACCENTS } from './lib/format.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 } from './lib/history.js'
import { beep, vibrate } from './lib/sound.js'
import { t, instrFor, getLang, INSTR_LANGS } from './lib/i18n.js'
@@ -55,8 +55,13 @@ export function loadStarterPlan() {
// attempt) makes the thumb's position unpredictable: every time it grows, everything already
// placed on it shifts toward one side. A static range never has that problem, at the cost of
// coarser precision per pixel — the +/- buttons cover exact values.
const W_LO = 1, W_HI = 300
// The ceiling follows the profile's unit: 300 covers a body weight or a working weight in
// kg, but as pounds it cut off at 136 kg — below plenty of people's body weight, and well
// below an everyday squat.
const W_LO = 1
const wHi = unit => (unit === 'lb' ? 660 : 300)
function WeightInput({ value, setValue, unit }) {
const W_HI = wHi(unit)
const clamp = x => Math.max(W_LO, Math.min(W_HI, Math.round((x || 0) * 10) / 10))
const sv = Math.max(W_LO, Math.min(W_HI, value))
const onSlide = v => setValue(clamp(v))
@@ -283,7 +288,7 @@ function AddToRoutine({ ex, close }) {
<div className="list">
{st.routines.map(r => <div key={r.id} className="item" onClick={() => pick(r.id)}>
<span className="lrow-i"><Icon name={glyphOf(r.emoji)} /></span>
<div className="grow"><div className="tt">{r.name}</div><div className="ss">{t('{0} exercises', r.ex.length)}</div></div>
<div className="grow"><div className="tt">{r.name}</div><div className="ss">{exCount(r.ex.length)}</div></div>
{r.ex.some(e => e.id === ex.id) && <span className="tag">{t('already in')}</span>}<Icon name="plus" className="chev" />
</div>)}
<div className="item" onClick={() => pick('_new')}><span className="lrow-i" style={{ background: 'var(--surface-3)' }}><Icon name="sparkles" /></span>
@@ -559,7 +564,7 @@ function DayOverride({ iso, close }) {
<div className="list">
{st.routines.map(r => <div key={r.id} className="item" onClick={() => set(r.id)}>
<span className="lrow-i"><Icon name={glyphOf(r.emoji)} /></span>
<div className="grow"><div className="tt">{r.name}</div><div className="ss">{t('{0} exercises', r.ex.length)}</div></div>
<div className="grow"><div className="tt">{r.name}</div><div className="ss">{exCount(r.ex.length)}</div></div>
{effId === r.id && <Icon name="check" className="accent" />}</div>)}
<div className="item" onClick={() => set('rest')}><span className="lrow-i" style={{ background: 'var(--surface-3)' }}><Icon name="moon" /></span><div className="grow"><div className="tt">{t('Rest / skip this day')}</div></div>{effId === null && <Icon name="check" className="accent" />}</div>
{hasOvr && <div className="item" onClick={() => set('')}><span className="lrow-i" style={{ background: 'var(--surface-3)' }}><Icon name="reset" /></span><div className="grow"><div className="tt">{t('Back to weekly plan')}</div></div></div>}
@@ -577,7 +582,7 @@ function DayAssign({ day, close }) {
<div className="item" onClick={() => set('')}><span className="lrow-i" style={{ background: 'var(--surface-3)' }}><Icon name="moon" /></span><div className="grow"><div className="tt">{t('Rest day')}</div></div>{!st.week[day] && <Icon name="check" className="accent" />}</div>
{st.routines.map(r => <div key={r.id} className="item" onClick={() => set(r.id)}>
<span className="lrow-i"><Icon name={glyphOf(r.emoji)} /></span>
<div className="grow"><div className="tt">{r.name}</div><div className="ss">{t('{0} exercises', r.ex.length)}</div></div>
<div className="grow"><div className="tt">{r.name}</div><div className="ss">{exCount(r.ex.length)}</div></div>
{st.week[day] === r.id && <Icon name="check" className="accent" />}</div>)}
</div>
</>
@@ -589,7 +594,7 @@ function WorkoutDetail({ w, close }) {
const st = useStore(s => s.S)
return <>
<h3>{w.name}</h3>
<div className="muted small" style={{ marginBottom: 12 }}>{fmtDate(w.d, true)} · {fmtDur(w.end - w.start)} · {fmtVol(w.vol, st.unit)}{w.bw ? ' · ' + fmtNum(w.bw) + ' ' + st.unit : ''}</div>
<div className="muted small" style={{ marginBottom: 12 }}>{[fmtDate(w.d, true), ...durPart(w.end - w.start), fmtVol(w.vol, st.unit), ...(w.bw ? [fmtNum(w.bw) + ' ' + st.unit] : [])].join(' · ')}</div>
{w.entries.map((e, i) => {
const ex = EXIDX[e.id]
return <div key={i} className="row" style={{ marginBottom: 12, alignItems: 'flex-start' }}>
@@ -652,7 +657,7 @@ export function WorkoutRow({ w, onClick }) {
return <div className="item" onClick={onClick}>
<span className="lrow-i" style={{ width: 34, height: 34, borderRadius: 8, fontSize: 19 }}><Icon name={glyph} /></span>
<div className="grow"><div className="tt">{w.name}</div>
<div className="ss">{fmtDate(w.d, true)} · {fmtDur(w.end - w.start)} · {t('{0} sets', setsDone(w))} · {fmtVol(w.vol, st.unit)}</div></div>
<div className="ss">{[fmtDate(w.d, true), ...durPart(w.end - w.start), t('{0} sets', setsDone(w)), fmtVol(w.vol, st.unit)].join(' · ')}</div></div>
{w.prs && w.prs.length > 0 && <span className="pr"><Icon name="trophy" />{w.prs.length} PR</span>}
<Icon name="chevronRight" className="chev" />
</div>