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 }) {