diff --git a/frontend/src/lib/format.js b/frontend/src/lib/format.js index b5c1dfd..de25f40 100644 --- a/frontend/src/lib/format.js +++ b/frontend/src/lib/format.js @@ -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') diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx index 9a271f1..2a1fe11 100644 --- a/frontend/src/sheets.jsx +++ b/frontend/src/sheets.jsx @@ -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 }) {
{st.routines.map(r =>
pick(r.id)}> -
{r.name}
{t('{0} exercises', r.ex.length)}
+
{r.name}
{exCount(r.ex.length)}
{r.ex.some(e => e.id === ex.id) && {t('already in')}}
)}
pick('_new')}> @@ -559,7 +564,7 @@ function DayOverride({ iso, close }) {
{st.routines.map(r =>
set(r.id)}> -
{r.name}
{t('{0} exercises', r.ex.length)}
+
{r.name}
{exCount(r.ex.length)}
{effId === r.id && }
)}
set('rest')}>
{t('Rest / skip this day')}
{effId === null && }
{hasOvr &&
set('')}>
{t('Back to weekly plan')}
} @@ -577,7 +582,7 @@ function DayAssign({ day, close }) {
set('')}>
{t('Rest day')}
{!st.week[day] && }
{st.routines.map(r =>
set(r.id)}> -
{r.name}
{t('{0} exercises', r.ex.length)}
+
{r.name}
{exCount(r.ex.length)}
{st.week[day] === r.id && }
)}
@@ -589,7 +594,7 @@ function WorkoutDetail({ w, close }) { const st = useStore(s => s.S) return <>

{w.name}

-
{fmtDate(w.d, true)} · {fmtDur(w.end - w.start)} · {fmtVol(w.vol, st.unit)}{w.bw ? ' · ' + fmtNum(w.bw) + ' ' + st.unit : ''}
+
{[fmtDate(w.d, true), ...durPart(w.end - w.start), fmtVol(w.vol, st.unit), ...(w.bw ? [fmtNum(w.bw) + ' ' + st.unit] : [])].join(' · ')}
{w.entries.map((e, i) => { const ex = EXIDX[e.id] return
@@ -652,7 +657,7 @@ export function WorkoutRow({ w, onClick }) { return
{w.name}
-
{fmtDate(w.d, true)} · {fmtDur(w.end - w.start)} · {t('{0} sets', setsDone(w))} · {fmtVol(w.vol, st.unit)}
+
{[fmtDate(w.d, true), ...durPart(w.end - w.start), t('{0} sets', setsDone(w)), fmtVol(w.vol, st.unit)].join(' · ')}
{w.prs && w.prs.length > 0 && {w.prs.length} PR}
diff --git a/frontend/src/views/Plan.jsx b/frontend/src/views/Plan.jsx index f07dd4b..b35f5c5 100644 --- a/frontend/src/views/Plan.jsx +++ b/frontend/src/views/Plan.jsx @@ -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() {
{S.routines.length ?
{S.routines.map(r =>
nav('/plan/r/' + r.id)}> -
{r.name}
{t('{0} exercises', r.ex.length)}
+
{r.name}
{exCount(r.ex.length)}
)}
: <>
{t('No routines yet.')}
{t('Create one or load the starter plan.')}