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:
1 parent
238b435c2b
commit
c8a68e37e1
3 files changed
+26
-12
No files matched your search
@@ -1,5 +1,5 @@
|
||||
// Formatting + date helpers (ported from the vanilla app, unit taken from the store where needed).
|
||||
import { dateLocale } from './i18n.js'
|
||||
import { dateLocale, t } from './i18n.js'
|
||||
export const todayISO = () => {
|
||||
const d = new Date()
|
||||
return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0')
|
||||
@@ -20,8 +20,17 @@ export function fmtDur(ms) {
|
||||
const m = Math.floor(ms / 60000)
|
||||
return m >= 60 ? Math.floor(m / 60) + 'h ' + (m % 60) + 'm' : m + ' min'
|
||||
}
|
||||
export const fmtNum = n => (Math.round(n * 10) / 10).toLocaleString('en-CH')
|
||||
export const fmtVol = (v, unit) => (v >= 10000 ? fmtNum(v / 1000) + 't' : fmtNum(v) + ' ' + unit)
|
||||
// Imported history has no clock — an unknown duration is left out rather than shown as "0 min".
|
||||
export const durPart = ms => (ms >= 60000 ? [fmtDur(ms)] : [])
|
||||
// Numbers follow the UI language, like the dates above — a hardcoded locale put Swiss
|
||||
// apostrophes ("7'535 kg") in front of every user, in every language.
|
||||
export const fmtNum = n => (Math.round(n * 10) / 10).toLocaleString(dateLocale())
|
||||
// Volume stays in the profile's unit throughout: the old shorthand turned anything over
|
||||
// 10 000 into "t", which is wrong for a pound profile and made one list mix "18.8t" with
|
||||
// "7'535 kg" — two numbers you can't compare at a glance.
|
||||
export const fmtVol = (v, unit) => fmtNum(v) + ' ' + unit
|
||||
// Plural forms are not automatic when the English string is the key.
|
||||
export const exCount = n => t(n === 1 ? '{0} exercise' : '{0} exercises', n)
|
||||
|
||||
export function weekKey(d) {
|
||||
const dt = new Date(d + 'T12:00:00')
|
||||
|
||||
+12
-7
@@ -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>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { DAYN, uid } from '../lib/format.js'
|
||||
import { DAYN, uid, exCount } from '../lib/format.js'
|
||||
import { t } from '../lib/i18n.js'
|
||||
import { dayAssignSheet, loadStarterPlan, planToolsSheet } from '../sheets.jsx'
|
||||
import Icon from '../components/Icon.jsx'
|
||||
@@ -41,7 +41,7 @@ export default function Plan() {
|
||||
</div>
|
||||
{S.routines.length ? <div className="list">{S.routines.map(r => <div key={r.id} className="item" onClick={() => nav('/plan/r/' + 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>
|
||||
<Icon name="chevronRight" className="chev" /></div>)}</div> : <>
|
||||
<div className="empty"><div className="ico"><Icon name="clipboard" /></div>{t('No routines yet.')}<br />{t('Create one or load the starter plan.')}</div>
|
||||
<Button icon="sparkles" onClick={loadStarterPlan}>{t('Load starter plan (Push / Pull / Legs)')}</Button>
|
||||
|
||||
Reference in new issue
Block a user