Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

Body weight: refuse a typed weight no person has, no -0 on the chart

Duarte Santos917a19b73e5f
diff --git a/frontend/src/components/LineChart.jsx b/frontend/src/components/LineChart.jsx
index a1259b90a..219bf013b 100644
--- a/frontend/src/components/LineChart.jsx
+++ b/frontend/src/components/LineChart.jsx
@@ -66,7 +66,10 @@ export default function LineChart({ points, h = 150, unit = '', color = 'var(--a
const pow = Math.pow(10, Math.floor(Math.log10(raw)))
let step = 10 * pow
for (const m of [1, 2, 2.5, 5, 10]) if (raw <= m * pow) { step = m * pow; break }
- for (let v = Math.ceil(ymin / step) * step; v <= ymax + 1e-9; v += step) {
+ for (let v0 = Math.ceil(ymin / step) * step; v0 <= ymax + 1e-9; v0 += step) {
+ // Snapped to the step, so adding it up never drifts, and `|| 0` turns the -0 that
+ // Math.ceil gives a range just under zero into a plain 0 instead of a "-0" label.
+ const v = Math.round(v0 / step) * step || 0
const y = Y(v)
gridlines.push(<g key={'y' + v}>
<line x1={P.l} y1={y} x2={W - P.r} y2={y} stroke="var(--sep-op)" strokeWidth="1" strokeDasharray="2 4" />
diff --git a/frontend/src/components/LineChart.test.jsx b/frontend/src/components/LineChart.test.jsx
index 19bce1041..4df9b4453 100644
--- a/frontend/src/components/LineChart.test.jsx
+++ b/frontend/src/components/LineChart.test.jsx
@@ -102,3 +102,12 @@ describe('LineChart hover state', () => {
expect(container.querySelector('.cvl')).toBeTruthy()
})
})
+
+describe('LineChart y axis', () => {
+ it('labels the zero line 0, never -0, when the range dips just below zero', () => {
+ act(() => root.render(<LineChart points={[point(2026, 1, 1, 70), point(2026, 1, 8, 9999)]} axes unit="kg" />))
+ const labels = [...container.querySelectorAll('text')].map(n => n.textContent)
+ expect(labels).toContain('0')
+ expect(labels.some(l => /^[-\u2212]0$/.test(l))).toBe(false)
+ })
+})
diff --git a/frontend/src/locales/ar.js b/frontend/src/locales/ar.js
index f7a8deafa..4b01c4f2a 100644
--- a/frontend/src/locales/ar.js
+++ b/frontend/src/locales/ar.js
@@ -1946,4 +1946,5 @@ export default {
'Finish and save': 'إنهاء وحفظ',
'Make it a warm-up set': 'اجعلها مجموعة إحماء',
'Count it as a working set': 'احسبها مجموعة عمل',
+ 'That looks too heavy. Keep it at {0} or less.': 'يبدو هذا ثقيلًا جدًا. الحد الأقصى {0}.',
}
diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js
index b3c624839..b7c9bbd48 100644
--- a/frontend/src/locales/de.js
+++ b/frontend/src/locales/de.js
@@ -1913,4 +1913,5 @@ export default {
'Finish and save': 'Beenden und speichern',
'Make it a warm-up set': 'Zum Aufwärmsatz machen',
'Count it as a working set': 'Als Arbeitssatz zählen',
+ 'That looks too heavy. Keep it at {0} or less.': 'Das wirkt zu schwer. Höchstens {0}, bitte.',
}
diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js
index 2977380c4..a0d2f3bc7 100644
--- a/frontend/src/locales/es.js
+++ b/frontend/src/locales/es.js
@@ -1893,4 +1893,5 @@ export default {
'Finish and save': 'Terminar y guardar',
'Make it a warm-up set': 'Convertir en serie de calentamiento',
'Count it as a working set': 'Contar como serie efectiva',
+ 'That looks too heavy. Keep it at {0} or less.': 'Eso parece demasiado. Como mucho {0}.',
}
diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js
index 4f4c00634..1196b4887 100644
--- a/frontend/src/locales/fr.js
+++ b/frontend/src/locales/fr.js
@@ -1893,4 +1893,5 @@ export default {
'Finish and save': 'Terminer et enregistrer',
'Make it a warm-up set': 'En faire une série d’échauffement',
'Count it as a working set': 'Compter comme série de travail',
+ 'That looks too heavy. Keep it at {0} or less.': 'Ça semble trop lourd. Pas plus de {0}.',
}
diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js
index 1ae0d87fe..abe42e656 100644
--- a/frontend/src/locales/hi.js
+++ b/frontend/src/locales/hi.js
@@ -1893,4 +1893,5 @@ export default {
'Finish and save': 'समाप्त करें और सहेजें',
'Make it a warm-up set': 'इसे वार्म-अप सेट बनाएं',
'Count it as a working set': 'इसे वर्किंग सेट गिनें',
+ 'That looks too heavy. Keep it at {0} or less.': 'यह बहुत भारी लग रहा है। ज़्यादा से ज़्यादा {0}।',
}
diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.js
index 6e36046c0..e21791f31 100644
--- a/frontend/src/locales/hu.js
+++ b/frontend/src/locales/hu.js
@@ -1896,4 +1896,5 @@ export default {
'Finish and save': 'Befejezés és mentés',
'Make it a warm-up set': 'Legyen bemelegítő sorozat',
'Count it as a working set': 'Számítson munkasorozatnak',
+ 'That looks too heavy. Keep it at {0} or less.': 'Ez túl soknak tűnik. Legfeljebb {0}.',
}
diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js
index ec05322dd..7a2c73279 100644
--- a/frontend/src/locales/it.js
+++ b/frontend/src/locales/it.js
@@ -1893,4 +1893,5 @@ export default {
'Finish and save': 'Termina e salva',
'Make it a warm-up set': 'Rendila serie di riscaldamento',
'Count it as a working set': 'Conta come serie allenante',
+ 'That looks too heavy. Keep it at {0} or less.': 'Sembra troppo. Al massimo {0}.',
}
diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js
index afb2b98d5..57ef51f6c 100644
--- a/frontend/src/locales/ko.js
+++ b/frontend/src/locales/ko.js
@@ -1893,4 +1893,5 @@ export default {
'Finish and save': '마치고 저장',
'Make it a warm-up set': '워밍업 세트로 바꾸기',
'Count it as a working set': '본 세트로 세기',
+ 'That looks too heavy. Keep it at {0} or less.': '너무 무거워 보여요. 최대 {0}까지예요.',
}
diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js
index a9651a370..336a354e5 100644
--- a/frontend/src/locales/pl.js
+++ b/frontend/src/locales/pl.js
@@ -1893,4 +1893,5 @@ export default {
'Finish and save': 'Zakończ i zapisz',
'Make it a warm-up set': 'Zamień na serię rozgrzewkową',
'Count it as a working set': 'Licz jako serię roboczą',
+ 'That looks too heavy. Keep it at {0} or less.': 'To wygląda na za dużo. Maksymalnie {0}.',
}
diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.js
index 226862b96..cecffb3af 100644
--- a/frontend/src/locales/pt-BR.js
+++ b/frontend/src/locales/pt-BR.js
@@ -1172,6 +1172,7 @@ export const PT_BR_OVERRIDES = {
'Delete {0}': 'Excluir {0}',
'Build your loop in Plan': 'Monte seu ciclo no Plano',
'Finish and save': 'Terminar e salvar',
+ 'That looks too heavy. Keep it at {0} or less.': 'Isso parece pesado demais. No máximo {0}.',
}
export default { ...pt, ...PT_BR_OVERRIDES }
diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js
index 409f36c43..62d3b99cc 100644
--- a/frontend/src/locales/pt.js
+++ b/frontend/src/locales/pt.js
@@ -1893,4 +1893,5 @@ export default {
'Finish and save': 'Terminar e guardar',
'Make it a warm-up set': 'Tornar série de aquecimento',
'Count it as a working set': 'Contar como série de trabalho',
+ 'That looks too heavy. Keep it at {0} or less.': 'Isso parece pesado demais. No máximo {0}.',
}
diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js
index 79af1ebe8..7e709eda5 100644
--- a/frontend/src/locales/ru.js
+++ b/frontend/src/locales/ru.js
@@ -1897,4 +1897,5 @@ export default {
'Finish and save': 'Завершить и сохранить',
'Make it a warm-up set': 'Сделать разминочным подходом',
'Count it as a working set': 'Считать рабочим подходом',
+ 'That looks too heavy. Keep it at {0} or less.': 'Это слишком много. Не больше {0}.',
}
diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.js
index b327fef27..0c5c5ce68 100644
--- a/frontend/src/locales/th.js
+++ b/frontend/src/locales/th.js
@@ -1904,4 +1904,5 @@ export default {
'Finish and save': 'จบและบันทึก',
'Make it a warm-up set': 'เปลี่ยนเป็นเซ็ตวอร์มอัพ',
'Count it as a working set': 'นับเป็นเซ็ตจริง',
+ 'That looks too heavy. Keep it at {0} or less.': 'ดูหนักเกินไปนะ ใส่ได้ไม่เกิน {0}',
}
diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js
index 1df7f5264..111f739dc 100644
--- a/frontend/src/locales/tr.js
+++ b/frontend/src/locales/tr.js
@@ -1893,4 +1893,5 @@ export default {
'Finish and save': 'Bitir ve kaydet',
'Make it a warm-up set': 'Isınma setine çevir',
'Count it as a working set': 'Çalışma seti say',
+ 'That looks too heavy. Keep it at {0} or less.': 'Bu fazla ağır görünüyor. En fazla {0}.',
}
diff --git a/frontend/src/locales/uk.js b/frontend/src/locales/uk.js
index 3565a1887..bd501e491 100644
--- a/frontend/src/locales/uk.js
+++ b/frontend/src/locales/uk.js
@@ -1890,4 +1890,5 @@ export default {
'Finish and save': 'Завершити й зберегти',
'Make it a warm-up set': 'Зробити розминковим підходом',
'Count it as a working set': 'Рахувати робочим підходом',
+ 'That looks too heavy. Keep it at {0} or less.': 'Це забагато. Не більше {0}.',
}
diff --git a/frontend/src/locales/zh-TW.js b/frontend/src/locales/zh-TW.js
index 6d385d218..eb18b3cb2 100644
--- a/frontend/src/locales/zh-TW.js
+++ b/frontend/src/locales/zh-TW.js
@@ -1886,4 +1886,5 @@ export default {
'Finish and save': '結束並儲存',
'Make it a warm-up set': '改為熱身組',
'Count it as a working set': '算作正式組',
+ 'That looks too heavy. Keep it at {0} or less.': '這好像太重了。最多 {0}。',
}
diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js
index b32846b78..c7863df4c 100644
--- a/frontend/src/locales/zh.js
+++ b/frontend/src/locales/zh.js
@@ -1893,4 +1893,5 @@ export default {
'Finish and save': '结束并保存',
'Make it a warm-up set': '改为热身组',
'Count it as a working set': '算作正式组',
+ 'That looks too heavy. Keep it at {0} or less.': '这好像太重了。最多 {0}。',
}
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx
index 969c0b595..8b2750fb6 100644
--- a/frontend/src/sheets.jsx
+++ b/frontend/src/sheets.jsx
@@ -221,6 +221,14 @@ export const starterPlanSheet = () => ui().openSheet(close => <StarterPlanChoose
// below an everyday squat.
const W_LO = 1
const wHi = unit => (unit === 'lb' ? 660 : 300)
+// A typed body weight may sit past the slider (a 320 kg lifter is real), but not past any
+// person: 9999 saved, drew the chart from -0 to 10,000 and set a goal 9,922 kg away.
+const bwMax = unit => (unit === 'lb' ? 1500 : 700)
+const bwTooHeavy = (n, unit) => {
+ if (n <= bwMax(unit)) return false
+ toast(t('That looks too heavy. Keep it at {0} or less.', fmtNum(bwMax(unit)) + ' ' + unit))
+ return true
+}
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))
@@ -257,6 +265,7 @@ function BwSheet({ required, onDone, close }) {
const save = () => {
const n = Math.round((v || 0) * 10) / 10
if (!n || n <= 0) { toast(t('Enter a valid weight')); return }
+ if (bwTooHeavy(n, unit)) return
update(s => {
const iso = todayISO()
const ex = s.bodyweight.find(b => b.d === iso)
@@ -674,6 +683,7 @@ function GoalSheet({ close }) {
<Button variant="primary" onClick={() => {
const n = Math.round((v || 0) * 10) / 10
if (!n || n <= 0) { toast(t('Enter a valid weight')); return }
+ if (bwTooHeavy(n, st.unit)) return
update(s => { s.targetW = n }); close()
const b = lastBW(S()); toast(t('Goal set: {0}', fmtNum(n) + ' ' + st.unit) + (b ? ' (' + t('{0} to go', fmtNum(Math.abs(n - b.w))) + ')' : ''))
}}>{t('Save goal')}</Button>
diff --git a/frontend/src/sheets.weight-input.test.jsx b/frontend/src/sheets.weight-input.test.jsx
index 49a50e027..9e1089361 100644
--- a/frontend/src/sheets.weight-input.test.jsx
+++ b/frontend/src/sheets.weight-input.test.jsx
@@ -1,10 +1,10 @@
// @vitest-environment happy-dom
import React, { act } from 'react'
-import { afterEach, beforeEach, describe, expect, it } from 'vitest'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { createRoot } from 'react-dom/client'
import { useStore } from './store/useStore.js'
import { useUI } from './store/useUI.js'
-import { bwSheet } from './sheets.jsx'
+import { bwSheet, goalSheet } from './sheets.jsx'
// The big weight read-out (body weight, goal, top weight after an exercise) used to be text:
// the only ways to a number were the slider, ±0.1 and the ±0.5/±1 chips, so 72.3 → 85.7 was a
@@ -37,7 +37,7 @@ describe('weight read-out is a typable field', () => {
beforeEach(() => {
globalThis.IS_REACT_ACT_ENVIRONMENT = true
useUI.setState({ sheets: [] })
- useStore.setState(s => ({ S: { ...s.S, unit: 'kg', bodyweight: [] } }))
+ useStore.setState(s => ({ S: { ...s.S, unit: 'kg', bodyweight: [], targetW: null } }))
document.body.innerHTML = ''
})
@@ -90,6 +90,34 @@ describe('weight read-out is a typable field', () => {
expect(useStore.getState().S.bodyweight[0].w).toBe(320)
})
+ // 9999 typed into the field saved, and the chart and goal lines read like it was real.
+ it('refuses a typed weight no person has, says the limit, and keeps the sheet open', () => {
+ const toast = vi.fn()
+ useUI.setState({ toast })
+ const { input, button } = renderBw()
+ act(() => type(input, '9999'))
+ act(() => button('Save').click())
+ expect(useStore.getState().S.bodyweight).toHaveLength(0)
+ expect(useUI.getState().sheets).toHaveLength(1)
+ expect(toast).toHaveBeenCalledWith('That looks too heavy. Keep it at 700 kg or less.')
+ })
+
+ it('the goal sheet refuses the same', () => {
+ const toast = vi.fn()
+ useUI.setState({ toast })
+ goalSheet()
+ const sheet = useUI.getState().sheets.at(-1)
+ const host = document.createElement('div')
+ document.body.appendChild(host)
+ const root = createRoot(host)
+ mounted.push(root)
+ act(() => root.render(sheet.render(() => useUI.getState().closeSheet(sheet.id))))
+ act(() => type(host.querySelector('.bw-read input'), '9999'))
+ act(() => [...host.querySelectorAll('button')].find(b => b.textContent.trim() === 'Save goal').click())
+ expect(useStore.getState().S.targetW ?? null).toBe(null)
+ expect(toast).toHaveBeenCalledWith('That looks too heavy. Keep it at 700 kg or less.')
+ })
+
it('still refuses to save an empty field', () => {
const { input, button } = renderBw()
act(() => type(input, ''))