An exercise can be logged by time instead of reps (#16)
Until now the logging model came from the body part alone: cardio meant duration, and everything else meant weight × reps. A plank, a hang, a wall sit or a loaded carry could only be timed by filing it under cardio, which then put it in the wrong charts. A routine entry can now say so itself — reps, time or cardio. Entries without a mode keep behaving exactly as before, so every existing plan, workout and shared plan file is read unchanged and nothing needs migrating. Timed sets get a work timer that counts the set itself, kept deliberately separate from the rest timer: the two mean opposite things and must never run together. Finishing early logs the time actually held, not the target, because crediting a full 45 seconds for a 38-second hold would quietly corrupt the log it exists to keep. Finished workouts now also store what the session prescribed. Without it, history cannot say whether a session hit its reps, and a timed session reads back as "0 reps".
This commit is contained in:
1 parent
a54bad2641
commit
ec46c7e20d
5 files changed
+309
-25
No files matched your search
@@ -3,21 +3,40 @@ import { useUI } from '../store/useUI.js'
|
||||
import { t } from '../lib/i18n.js'
|
||||
import { Button } from './ui.jsx'
|
||||
|
||||
const clock = sec => Math.floor(sec / 60) + ':' + String(sec % 60).padStart(2, '0')
|
||||
|
||||
// One bar, two meanings: the rest countdown between sets, and the work countdown during a
|
||||
// timed set (issue #16). They are mutually exclusive by construction — startWork() stops any
|
||||
// running rest — so the bar can never have to show both, and a work set gets its own colour
|
||||
// plus a "Done" that logs the time actually held.
|
||||
export default function RestTimer() {
|
||||
const timer = useUI(s => s.timer)
|
||||
const { addRest, stopRest } = useUI()
|
||||
const work = useUI(s => s.work)
|
||||
const { addRest, stopRest, finishWorkEarly, stopWork } = useUI()
|
||||
const on = work || timer
|
||||
// The bar is fixed above the tab bar and floats over whatever is beneath it — during a
|
||||
// rest that was the next set's row. Extra bottom padding lets the page scroll clear.
|
||||
useEffect(() => {
|
||||
document.body.classList.toggle('resting', !!timer)
|
||||
document.body.classList.toggle('resting', !!on)
|
||||
return () => document.body.classList.remove('resting')
|
||||
}, [!!timer])
|
||||
if (!timer) return null
|
||||
const pct = (timer.left / timer.total) * 100
|
||||
const m = Math.floor(timer.left / 60), s = String(timer.left % 60).padStart(2, '0')
|
||||
}, [!!on])
|
||||
if (!on) return null
|
||||
const pct = (on.left / on.total) * 100
|
||||
|
||||
if (work) return (
|
||||
<div id="timer" className="working">
|
||||
<div className="t">{clock(work.left)}</div>
|
||||
<div className="grow">
|
||||
{work.label && <div className="lbl">{work.label}</div>}
|
||||
<div className="bar"><i style={{ width: pct + '%' }} /></div>
|
||||
</div>
|
||||
<Button size="sm" onClick={stopWork}>{t('Cancel')}</Button>
|
||||
<Button size="sm" variant="primary" icon="check" onClick={finishWorkEarly}>{t('Done')}</Button>
|
||||
</div>
|
||||
)
|
||||
return (
|
||||
<div id="timer">
|
||||
<div className="t">{m}:{s}</div>
|
||||
<div className="t">{clock(timer.left)}</div>
|
||||
<div className="bar"><i style={{ width: pct + '%' }} /></div>
|
||||
<Button size="sm" icon="plus" onClick={() => addRest(15)}>15s</Button>
|
||||
<Button size="sm" variant="primary" onClick={stopRest}>{t('Skip')}</Button>
|
||||
|
||||
Reference in new issue
Block a user