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.

Tab bar: a minimized session shows its running time on the play button

Duarte Santosff88900fc0b1
diff --git a/frontend/src/components/Elapsed.jsx b/frontend/src/components/Elapsed.jsx
new file mode 100644
index 000000000..0bf45fc86
--- /dev/null
+++ b/frontend/src/components/Elapsed.jsx
@@ -0,0 +1,13 @@
+import { useEffect, useState } from 'react'
+
+// A session's running time, "12:34" since `start`. Its own little component so the only thing
+// that re-renders every second is this text: the workout header and the tab bar's Resume button
+// both show it.
+export default function Elapsed({ start }) {
+ const [t, setT] = useState('0:00')
+ useEffect(() => {
+ const tick = () => { const s = Math.max(0, Math.floor((Date.now() - start) / 1000)); setT(Math.floor(s / 60) + ':' + String(s % 60).padStart(2, '0')) }
+ tick(); const iv = setInterval(tick, 1000); return () => clearInterval(iv)
+ }, [start])
+ return <span>{t}</span>
+}
diff --git a/frontend/src/components/TabBar.jsx b/frontend/src/components/TabBar.jsx
index 8dd833fe9..db089dd7b 100644
--- a/frontend/src/components/TabBar.jsx
+++ b/frontend/src/components/TabBar.jsx
@@ -4,6 +4,7 @@ import { effectiveRoutineIds, effectiveRoutines } from '../lib/history.js'
import { todayISO } from '../lib/format.js'
import { t } from '../lib/i18n.js'
import Icon from './Icon.jsx'
+import Elapsed from './Elapsed.jsx'
import { useConnectionTrouble } from './SyncBanner.jsx'
// Module scope, not TabBar's render body. Declared inside it, `Tab` was a new function on every
@@ -31,6 +32,7 @@ export default function TabBar({ onStart }) {
const cur = loc.pathname.split('/')[1] || 'home'
const on = k => cur === k || (cur === 'history' && k === 'stats') || (cur === 'settings' && k === 'home') || (cur === 'muscles' && k === 'library') || (cur === 'structural-balance' && k === 'stats')
+ const running = !!S.active && cur !== 'workout' && !S.active.editingWorkoutId && !S.active.backfill && S.active.start > 0
const startWorkout = () => {
if (!S.active) {
// A weekday can hold several routines; start the combined session if any of them has
@@ -47,10 +49,15 @@ export default function TabBar({ onStart }) {
{/* On the workout screen itself there is nothing to resume, so the button reads as the
tab it is and stays lit (#29); anywhere else it brings you back to the exercise you
were on — the marker is kept in S.active.cur and never moves on its own (#21). The
- glyph is always play: start and resume are one concept, and an exercise is a dumbbell. */}
- <button className={'start' + (S.active ? ' rec' : '') + (S.active && cur === 'workout' ? ' on' : '')} onClick={startWorkout}>
+ glyph is always play: start and resume are one concept, and an exercise is a dumbbell.
+ A live session you stepped away from shows its running time instead of a word, the
+ button still named Resume; a past workout being edited or logged after the fact has no
+ clock to run. */}
+ <button className={'start' + (S.active ? ' rec' : '') + (S.active && cur === 'workout' ? ' on' : '')} onClick={startWorkout}
+ aria-label={running ? t('Resume') : undefined}>
<span className="cir"><Icon name="play" /></span>
- <span>{S.active ? (cur === 'workout' ? t('Workout') : S.active.editingWorkoutId ? t('Edit workout') : t('Resume')) : t('Start')}</span>
+ {running ? <span className="tab-time"><Elapsed start={S.active.start} /></span>
+ : <span>{S.active ? (cur === 'workout' ? t('Workout') : S.active.editingWorkoutId ? t('Edit workout') : t('Resume')) : t('Start')}</span>}
</button>
<Tab active={on('stats')} icon="chart" label={t('Stats')} onClick={() => nav('/stats')} />
<Tab active={on('library')} icon="dumbbell" label={t('Exercises')} onClick={() => nav('/library')} />
diff --git a/frontend/src/components/TabBar.test.jsx b/frontend/src/components/TabBar.test.jsx
index 415af5183..921c1d94d 100644
--- a/frontend/src/components/TabBar.test.jsx
+++ b/frontend/src/components/TabBar.test.jsx
@@ -95,4 +95,23 @@ describe('the tab icons and labels', () => {
expect(icon(tabs()[2])).toBe('play')
expect(label(tabs()[2])).toBe('Resume')
})
+
+ it('shows a minimized session’s running time, still named Resume', () => {
+ vi.useFakeTimers()
+ try {
+ vi.setSystemTime(new Date(2026, 9, 5, 18, 0, 0))
+ act(() => { useStore.getState().update(s => { s.active = { id: 'a', entries: [], cur: 0, start: Date.now() - 754_000 } }, false) })
+ act(() => { root.render(<TabBar onStart={() => {}} />) })
+ const start = tabs()[2]
+ expect(label(start)).toBe('12:34')
+ expect(start.getAttribute('aria-label')).toBe('Resume')
+ act(() => { vi.advanceTimersByTime(2000) })
+ expect(label(start)).toBe('12:36')
+ expect(tabs()[2]).toBe(start) // the same button, only its text ticks
+
+ // a past workout being edited has no clock running
+ act(() => { useStore.getState().update(s => { s.active.editingWorkoutId = 'w1' }, false) })
+ expect(label(tabs()[2])).toBe('Edit workout')
+ } finally { vi.useRealTimers() }
+ })
})
diff --git a/frontend/src/index.css b/frontend/src/index.css
index a74f7ceba..2a33dd8a6 100644
--- a/frontend/src/index.css
+++ b/frontend/src/index.css
@@ -426,6 +426,7 @@ h4.sec{
#tabbar button.start:active .cir{transform:scale(.93)}
#tabbar button.start .cir .icn{font-size:26px;--icon-stroke:2;color:inherit;opacity:1}
#tabbar button.start span{color:var(--acc);font-weight:600}
+#tabbar button.start .tab-time{font-variant-numeric:tabular-nums}
/* `.cir` is itself a <span>, so the label rules above and below reach it too and
outrank the `.cir` block — which is how the running state ended up painting an
orange play glyph onto an orange disc. Both states restate their own colour.
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx
index a6c3e6310..2a1fca9fa 100644
--- a/frontend/src/views/Workout.jsx
+++ b/frontend/src/views/Workout.jsx
@@ -24,6 +24,7 @@ import { REST_MAX, fmtRest } from '../lib/duration.js'
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, finishWorkout, exitWorkoutEdit, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet, renameWorkoutSheet, swapActiveWorkoutExercise, barWeightSheet, menuSheet, effortPickerSheet, exerciseHistorySheet, addRoutineToSessionSheet } from '../sheets.jsx'
import { afterScrollRestore, scrollRestorePending } from '../components/Modals.jsx'
import { effortColor } from '../lib/effort.js'
+import Elapsed from '../components/Elapsed.jsx'
import Icon from '../components/Icon.jsx'
import { Button, Check, NumberField } from '../components/ui.jsx'
import { defaultIncrement, weightIncrement, stepWeight } from '../lib/progression.js'
@@ -75,15 +76,6 @@ function StartChooser() {
</div>
}
-/* ---------- elapsed clock (isolated so the workout tree doesn't re-render every second) ---------- */
-function Elapsed({ start }) {
- const [t, setT] = useState('0:00')
- useEffect(() => {
- const tick = () => { const s = Math.floor((Date.now() - start) / 1000); setT(Math.floor(s / 60) + ':' + String(s % 60).padStart(2, '0')) }
- tick(); const iv = setInterval(tick, 1000); return () => clearInterval(iv)
- }, [start])
- return <span>{t}</span>
-}
// A set-row column's number as it is shown. Most columns show what is stored; one with a `view`
// (cardio speed, stored in km/h) converts it for the screen.