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.

Merge v1.3.8 main into contribution #205

Space-Hermesa3ed15392a4b
diff --cc frontend/src/components/Heatmap.jsx
index cb672c255,8ecc29aa2..aa3297327
--- a/frontend/src/components/Heatmap.jsx
+++ b/frontend/src/components/Heatmap.jsx
@@@ -1,53 -1,34 +1,59 @@@
-import { useEffect, useRef } from 'react'
+import { useEffect, useRef, useState } from 'react'
- import { fmtVol, isoOf, todayISO, MONTHS } from '../lib/format.js'
+ import { fmtVol, isoOf, todayISO, MONTHS, weekStartOf, weekDayOffset } from '../lib/format.js'
+import { workoutDay, workoutDuration, workoutVolume } from '../lib/history.js'
import { t } from '../lib/i18n.js'
import { tappable } from '../lib/use-sheet-keyboard.js'
+import { Segmented } from './ui.jsx'
-// GitHub-style activity heatmap, shaded by time trained per day.
-export default function Heatmap({ S, onDay }) {
+const normalizeMetric = value => value === 'vol' ? 'vol' : 'time'
+
+// Legacy records without entries only have the cached volume available. Current records are
+// always recomputed from their completed sets so unit changes and warm-up/per-side rules stay
+// authoritative.
+const volumeOf = w => {
+ if (Array.isArray(w?.entries)) return Math.max(0, Number(workoutVolume(w)) || 0)
+ const volume = Number(w?.vol)
+ return Number.isFinite(volume) ? Math.max(0, volume) : 0
+}
+
+// GitHub-style activity heatmap, shaded by the selected time or volume metric per day.
+export default function Heatmap({ S, onDay, metric: selectedMetric, onMetricChange }) {
const wrapRef = useRef(null)
+ const [localMetric, setLocalMetric] = useState(() => normalizeMetric(selectedMetric ?? S?.heatmapMetric))
useEffect(() => { if (wrapRef.current) wrapRef.current.scrollLeft = wrapRef.current.scrollWidth }, [])
+ const metric = normalizeMetric(selectedMetric ?? localMetric)
+ const metricValue = metric === 'vol' ? 'vol' : 'min'
+ const changeMetric = value => {
+ const next = normalizeMetric(value)
+ if (selectedMetric == null) setLocalMetric(next)
+ onMetricChange?.(next)
+ }
+
const agg = {}
- S.workouts.forEach(w => {
- const a = agg[w.d] = agg[w.d] || { n: 0, vol: 0, min: 0 }
- a.n++; a.vol += w.vol || 0
- a.min += Math.max(0, Math.round(((w.end || w.start) - w.start) / 60000))
+ ;(S.workouts || []).forEach(w => {
+ const day = workoutDay(w)
+ if (!day) return
+ const a = agg[day] = agg[day] || { n: 0, vol: 0, min: 0 }
+ a.n++
+ a.vol += volumeOf(w)
+ a.min += Math.max(0, Math.round(workoutDuration(w) / 60000))
})
- const mins = Object.values(agg).map(a => a.min).filter(v => v > 0).sort((a, b) => a - b)
- const q = p => (mins.length ? mins[Math.min(mins.length - 1, Math.floor(p * mins.length))] : 0)
+ const values = Object.values(agg).map(a => a[metricValue]).filter(v => v > 0).sort((a, b) => a - b)
+ const q = p => (values.length ? values[Math.min(values.length - 1, Math.floor(p * values.length))] : 0)
const t1 = q(0.25), t2 = q(0.5), t3 = q(0.75)
- const level = a => !a ? 0 : !a.min ? 1 : a.min >= t3 ? 4 : a.min >= t2 ? 3 : a.min >= t1 ? 2 : 1
+ const level = a => !a ? 0 : !a[metricValue] ? 1 : a[metricValue] >= t3 ? 4 : a[metricValue] >= t2 ? 3 : a[metricValue] >= t1 ? 2 : 1
const today = new Date(); today.setHours(12, 0, 0, 0)
- const end = new Date(today); end.setDate(today.getDate() - ((today.getDay() + 6) % 7))
+ const ws = weekStartOf(S)
+ const end = new Date(today); end.setDate(today.getDate() - weekDayOffset(today.getDay(), ws))
const start = new Date(end); start.setDate(end.getDate() - 52 * 7)
+ const dayLabels = Array(7).fill(null)
+ dayLabels[weekDayOffset(1, ws)] = 'Mon'
+ dayLabels[weekDayOffset(3, ws)] = 'Wed'
+ dayLabels[weekDayOffset(5, ws)] = 'Fri'
+
const months = [], cols = []
let lastMonth = -1
for (let wk = 0; wk <= 52; wk++) {
diff --cc frontend/src/components/Heatmap.test.jsx
index 0ce9bd6b0,158a0517c..4485f97c8
--- a/frontend/src/components/Heatmap.test.jsx
+++ b/frontend/src/components/Heatmap.test.jsx
@@@ -1,68 -1,53 +1,114 @@@
// @vitest-environment happy-dom
-// The heatmap used to hardcode Monday-first weeks. It should follow S.weekStart like every
-// other "this week" surface (see lib/week-start.test.js and views/week-start.test.jsx).
import React, { act } from 'react'
import { createRoot } from 'react-dom/client'
- import { afterEach, expect, it, vi } from 'vitest'
-import { afterEach, beforeEach, describe, expect, it } from 'vitest'
++import { afterEach, describe, expect, it, vi } from 'vitest'
import Heatmap from './Heatmap.jsx'
import { isoOf } from '../lib/format.js'
+import { workoutDay } from '../lib/history.js'
+let root, host
globalThis.IS_REACT_ACT_ENVIRONMENT = true
- afterEach(() => { act(() => root?.unmount()); host?.remove() })
++afterEach(() => { act(() => root?.unmount()); host?.remove(); root = null; host = null })
-let container, root
-beforeEach(() => {
- container = document.createElement('div')
- document.body.appendChild(container)
- root = createRoot(container)
+it('changes shading and legend by metric while retaining day actions and history', () => {
+ const now = new Date(), workouts = [1, 2, 3, 4].map((n, i) => {
+ const d = new Date(now); d.setDate(d.getDate() - n)
+ return { d: isoOf(d), start: +d, end: +d + n * 60000, vol: (4 - i) * 100 }
+ })
+ const S = { workouts, unit: 'kg' }, before = structuredClone(S), onDay = vi.fn(), onMetricChange = vi.fn()
+ host = document.createElement('div'); document.body.appendChild(host); root = createRoot(host)
+ act(() => root.render(<Heatmap S={S} onDay={onDay} onMetricChange={onMetricChange} />))
+ const first = () => [...host.querySelectorAll('.hm-c[title]')].find(e => e.title.startsWith(workouts[0].d))
+ expect(first().classList.contains('l1')).toBe(true)
+ act(() => [...host.querySelectorAll('button')].find(e => e.textContent === 'Volume').click())
+ expect(first().classList.contains('l4')).toBe(true); expect(host.textContent).toContain('More volume')
+ expect(onMetricChange).toHaveBeenCalledWith('vol')
+ act(() => first().click()); expect(onDay).toHaveBeenCalledWith(workouts[0].d)
+ expect(S).toEqual(before)
+})
+
+it('uses the local session day and canonical completed volume', () => {
+ const start = new Date(); start.setDate(start.getDate() - 1); start.setHours(8, 0, 0, 0)
+ const day = isoOf(start)
+ const workout = {
+ d: 'not-a-day', start: +start, end: +start + 15 * 60000, vol: 999,
+ entries: [{ sets: [
+ { w: 100, r: 10, done: true, phase: 'warmup' },
+ { w: 14, r: 16, done: true, sides: {
+ L: { w: 14, r: 10, done: true }, R: { w: 12.5, r: 6, done: true },
+ } },
+ ] }],
+ }
+ expect(workoutDay(workout)).toBe(day)
+ host = document.createElement('div'); document.body.appendChild(host); root = createRoot(host)
+ act(() => root.render(<Heatmap S={{ workouts: [workout], unit: 'lb' }} />))
+ const cell = () => [...host.querySelectorAll('.hm-c[title]')].find(e => e.title.startsWith(day))
+ expect(cell().title).toContain('15 min · 215 lb')
+ act(() => [...host.querySelectorAll('button')].find(e => e.textContent === 'Volume').click())
+ expect(cell().classList.contains('l4')).toBe(true)
})
-afterEach(() => {
- act(() => root.unmount())
- container.remove()
+
+it('keeps a valid saved day ahead of a mismatched timestamp', () => {
+ const timestamp = new Date(); timestamp.setDate(timestamp.getDate() - 2)
+ const savedDay = isoOf(new Date(timestamp)); timestamp.setDate(timestamp.getDate() - 1)
+ expect(workoutDay({ d: savedDay, start: +timestamp })).toBe(savedDay)
+})
+
+it('leaves malformed history out of the activity map', () => {
+ host = document.createElement('div'); document.body.appendChild(host); root = createRoot(host)
+ act(() => root.render(<Heatmap S={{ workouts: [{ d: 'not-a-day', start: NaN, end: NaN, vol: 100 }], unit: 'kg' }} />))
+ expect(host.querySelectorAll('.hm-grid .hm-c:not(.l0)')).toHaveLength(0)
+})
+
+it('honors a saved volume preference on the next render', () => {
+ host = document.createElement('div'); document.body.appendChild(host); root = createRoot(host)
+ act(() => root.render(<Heatmap S={{ workouts: [], unit: 'kg', heatmapMetric: 'vol' }} />))
+ expect(host.textContent).toContain('More volume')
+ expect([...host.querySelectorAll('button')].find(e => e.textContent === 'Volume').getAttribute('aria-pressed')).toBe('true')
})
+
+ const baseS = { workouts: [], unit: 'kg' }
-const render = weekStart => act(() => root.render(<Heatmap S={{ ...baseS, weekStart }} onDay={() => {}} />))
-const dayLabels = () => [...container.querySelectorAll('.hm-days span')].map(s => s.textContent)
++const render = weekStart => {
++ if (!host) { host = document.createElement('div'); document.body.appendChild(host); root = createRoot(host) }
++ act(() => root.render(<Heatmap S={{ ...baseS, weekStart }} onDay={() => {}} />))
++}
++const dayLabels = () => [...host.querySelectorAll('.hm-days span')].map(s => s.textContent)
+ const lastColumn = () => {
- const cols = container.querySelectorAll('.hm-grid .hm-col')
++ const cols = host.querySelectorAll('.hm-grid .hm-col')
+ return [...cols[cols.length - 1].querySelectorAll('.hm-c')]
+ }
+
+ describe('Heatmap — week start', () => {
+ it('rows read Mon/Wed/Fri for a Monday-first week (default)', () => {
+ render(undefined)
+ expect(dayLabels()).toEqual(['Mon', '', 'Wed', '', 'Fri', '', ''])
+ })
+
+ it('shifts the same three labels down a row for a Sunday-first week', () => {
+ render(0)
+ expect(dayLabels()).toEqual(['', 'Mon', '', 'Wed', '', 'Fri', ''])
+ })
+
+ it('the current (rightmost) column starts on the chosen week-start day and includes today', () => {
+ render(1)
+ let cells = lastColumn()
+ expect(new Date(cells[0].title.slice(0, 10) + 'T12:00:00').getDay()).toBe(1)
+ expect(cells.map(c => c.title.slice(0, 10))).toContain(isoOf(new Date()))
+
+ render(0)
+ cells = lastColumn()
+ expect(new Date(cells[0].title.slice(0, 10) + 'T12:00:00').getDay()).toBe(0)
+ expect(cells.map(c => c.title.slice(0, 10))).toContain(isoOf(new Date()))
+ })
+ })
++
++it.each([0, 1])('retains week start %i when switching the activity metric', weekStart => {
++ render(weekStart)
++ const firstDay = lastColumn()[0].title.slice(0, 10)
++ const labels = dayLabels()
++ act(() => [...host.querySelectorAll('button')].find(e => e.textContent === 'Volume').click())
++ expect(lastColumn()[0].title.slice(0, 10)).toBe(firstDay)
++ expect(new Date(firstDay + 'T12:00:00').getDay()).toBe(weekStart)
++ expect(dayLabels()).toEqual(labels)
++ expect(host.textContent).toContain('More volume')
++})
diff --cc frontend/src/lib/pt-br-locale.test.js
index c5a0f6b4a,05eaeab8c..ec2967c8c
--- a/frontend/src/lib/pt-br-locale.test.js
+++ b/frontend/src/lib/pt-br-locale.test.js
@@@ -27,11 -27,11 +27,11 @@@ describe('Brazilian Portuguese locale'
.sort(byCodeUnit)
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
- expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(644)
- expect(inherited).toHaveLength(649)
+ expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(645)
- expect(inherited).toHaveLength(660)
++ expect(inherited).toHaveLength(662)
// If this fails, review the changed keys and wording before accepting a new hash. From
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
- expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('b67cc1616ce4f805dba8c87315bb47a7ea28e1cc8a468ed9395b9fe378d0c848')
- expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('a2027d64b3944dcef644b11b4d9688b88fe5cff0693acf04c73f0667e2b86825')
++ expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('ad8b9c1187e93a12f532bef848ad98de80da0e5477a897e0493deedd938aaf7e')
})
test('does not leak European Portuguese UI terms', () => {
diff --cc frontend/src/sheets.calendar.test.jsx
index 000000000,000000000..67c42b6a6
new file mode 100644
--- /dev/null
+++ b/frontend/src/sheets.calendar.test.jsx
@@@ -1,0 -1,0 +1,59 @@@
++// @vitest-environment happy-dom
++import React, { act } from 'react'
++import { afterEach, beforeEach, describe, expect, it } from 'vitest'
++import { createRoot } from 'react-dom/client'
++import { useStore } from './store/useStore.js'
++import { useUI } from './store/useUI.js'
++import { todayISO } from './lib/format.js'
++import { calendarSheet } from './sheets.jsx'
++
++const mounted = []
++
++function renderTop() {
++ 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))))
++ return host
++}
++
++describe('Calendar canonical workout days', () => {
++ let original
++
++ beforeEach(() => {
++ globalThis.IS_REACT_ACT_ENVIRONMENT = true
++ original = useStore.getState().S
++ useUI.setState({ sheets: [] })
++ document.body.innerHTML = ''
++ })
++
++ afterEach(() => {
++ act(() => { mounted.splice(0).forEach(root => root.unmount()) })
++ useStore.setState({ S: original })
++ })
++
++ it('keeps multiple legacy sessions on the heatmap fallback day clickable in Calendar', () => {
++ const day = todayISO()
++ const start = new Date(day + 'T09:00:00').getTime()
++ useStore.setState({ S: {
++ ...original,
++ workouts: [
++ { id: 'legacy-a', d: '', start, end: start + 15 * 60000, name: 'Legacy A', vol: 100, entries: [] },
++ { id: 'legacy-b', d: 'not-a-day', start: start + 30 * 60000, end: start + 45 * 60000, name: 'Legacy B', vol: 200, entries: [] },
++ ],
++ } })
++
++ calendarSheet(day)
++ const host = renderTop()
++ expect(host.textContent).toContain('2 workouts')
++ const trainedDay = host.querySelector('button.cal-d.has')
++ expect(trainedDay).toBeTruthy()
++
++ act(() => trainedDay.click())
++ const sessions = renderTop()
++ expect(sessions.textContent).toContain('Legacy A')
++ expect(sessions.textContent).toContain('Legacy B')
++ })
++})
diff --cc frontend/src/sheets.jsx
index 4c04e4720,e484bdf87..3fdbaf572
--- a/frontend/src/sheets.jsx
+++ b/frontend/src/sheets.jsx
@@@ -1,11 -1,11 +1,11 @@@
import { useEffect, useMemo, useRef, useState } from 'react'
import { useStore } from './store/useStore.js'
import { useUI } from './store/useUI.js'
- import { EXDB, EXIDX, BODYPARTS, isCardio, isBodyweightEq, allExercises, equipmentOf, smOf, matchExercise, exOr } from './lib/exercises.js'
+ import { EXDB, EXIDX, BODYPARTS, isCardio, isBodyweightEq, allExercises, equipmentOf, smOf, searchExercises, exOr, isAssisted, betterWeight, beatsWeight } from './lib/exercises.js'
import { activeProfile, exAvailable, ALL_EQUIPMENT, newProfile } from './lib/equipment.js'
- import { fmtDate, fmtNum, capWords, fmtVol, fmtDur, durPart, todayISO, isoOf, uid, exCount, DAYN, DAYS, weekOrder, weekStartOf, weekDayOffset, MONTHS_LONG, ACCENTS } from './lib/format.js'
- import { lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, effectiveRoutineIds, workoutVolume, setsDone, setsDoneActive, setUnitsTotal, lastBW, supersetUnits, unitOf, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, EFFORT, capEffort, stepEffort, isBw, isPerSide, sideReps, workSetsDone, applyIntensifierPlan, MAX_PLANNED_WARMUPS, NOTE_MAX } from './lib/history.js'
- import { usesBar, barWeightFor, defaultBarWeight, hasBarOverride } from './lib/bar.js'
+ import { fmtDate, fmtNum, capWords, fmtVol, fmtDur, durPart, todayISO, isoOf, uid, exCount, routineCount, DAYN, DAYS, weekOrder, weekStartOf, weekDayOffset, MONTHS_LONG, ACCENTS } from './lib/format.js'
-import { lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, effectiveRoutineIds, workoutVolume, setsDone, setsDoneActive, setUnitsTotal, lastBW, supersetUnits, unitOf, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, EFFORT, capEffort, stepEffort, isBw, isPerSide, sideReps, workSetsDone, applyIntensifierPlan, MAX_PLANNED_WARMUPS, NOTE_MAX } from './lib/history.js'
++import { lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, effectiveRoutineIds, workoutDay, workoutVolume, setsDone, setsDoneActive, setUnitsTotal, lastBW, supersetUnits, unitOf, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, EFFORT, capEffort, stepEffort, isBw, isPerSide, sideReps, workSetsDone, applyIntensifierPlan, MAX_PLANNED_WARMUPS, NOTE_MAX } from './lib/history.js'
+ import { usesBar, barWeightFor, defaultBarWeight, hasBarOverride, isNoBar } from './lib/bar.js'
import { toScale, rirOf, EFFORT_PRESETS, effortColor } from './lib/effort.js'
import { beep, vibrate } from './lib/sound.js'
import { t, dateLocale, instrFor, exerciseNameFor, getLang, INSTR_LANGS } from './lib/i18n.js'
@@@ -1701,12 -1747,12 +1747,15 @@@ function Calendar({ start, close })
const [cur, setCur] = useState(() => { const d = start ? new Date(start) : new Date(); d.setDate(1); return d })
const y = cur.getFullYear(), mo = cur.getMonth()
const byDay = {}
-- st.workouts.forEach(w => (byDay[w.d] = byDay[w.d] || []).push(w))
++ st.workouts.forEach(w => {
++ const day = workoutDay(w)
++ if (day) (byDay[day] = byDay[day] || []).push(w)
++ })
// Which column the 1st sits in, and therefore how many blanks come before it.
const ws = weekStartOf(st)
const startOffset = weekDayOffset(new Date(y, mo, 1).getDay(), ws)
const daysIn = new Date(y, mo + 1, 0).getDate()
-- const monthWs = st.workouts.filter(w => w.d.startsWith(y + '-' + String(mo + 1).padStart(2, '0')))
++ const monthWs = st.workouts.filter(w => workoutDay(w)?.startsWith(y + '-' + String(mo + 1).padStart(2, '0')))
const monthVol = monthWs.reduce((a, w) => a + (w.vol || 0), 0)
const monthMs = monthWs.reduce((a, w) => a + Math.max(0, (w.end || w.start) - w.start), 0)
const cells = []
diff --cc frontend/src/views/Stats.jsx
index 17c432565,3af72bb3b..dbdcd8d8e
--- a/frontend/src/views/Stats.jsx
+++ b/frontend/src/views/Stats.jsx
@@@ -1,11 -1,11 +1,11 @@@
import { useEffect, useMemo, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { useStore } from '../store/useStore.js'
- import { EXIDX, matchExercise } from '../lib/exercises.js'
+ import { EXIDX, matchExercise, betterWeight } from '../lib/exercises.js'
-import { lastBW, streakWeeks, setLabel, modeOf, effortOf, metricModeForEntry, metricRowsForEntry, bestWeightForEntry } from '../lib/history.js'
+import { lastBW, streakWeeks, setLabel, modeOf, effortOf, metricModeForEntry, metricRowsForEntry, bestWeightForEntry, workoutDay } from '../lib/history.js'
import { fmtNum, fmtDate, fmtVol, todayISO, weekStartOf } from '../lib/format.js'
import { t, exerciseNameFor, getLang } from '../lib/i18n.js'
- import { bwSheet, goalSheet, calendarSheet, workoutDetailSheet, WorkoutRow, bwDeltaColor } from '../sheets.jsx'
+ import { bwSheet, goalSheet, calendarSheet, workoutDetailSheet, exerciseHistorySheet, WorkoutRow, bwDeltaColor } from '../sheets.jsx'
import LineChart from '../components/LineChart.jsx'
import Heatmap from '../components/Heatmap.jsx'
import Icon from '../components/Icon.jsx'
@@@ -297,7 -299,7 +299,7 @@@ export default function Stats()
const bw30 = S.bodyweight.filter(b => (b.t || new Date(b.d).getTime()) > now - 30 * 86400000)
const bwDelta30 = bw30.length > 1 ? bw30[bw30.length - 1].w - bw30[0].w : null
const workouts = S.workouts
-- const monthW = workouts.filter(w => String(w.d || '').slice(0, 7) === todayISO().slice(0, 7)).length
++ const monthW = workouts.filter(w => workoutDay(w)?.slice(0, 7) === todayISO().slice(0, 7)).length
const entryOf = id => workouts.flatMap(w => w.entries).find(e => e.id === id)
const listOf = value => Array.isArray(value) ? value : value == null || value === '' ? [] : [value]