workout: allow renaming workout title from header menu

Add Rename workout option to the header 3-dot menu during an active workout session. Opens a bottom sheet modal with an auto-focused text field, disabled Save button when empty, and Enter key submission. Preserves custom titles when another routine is added to the session.
This commit is contained in:
ncbachh committed 2026-09-16 22:23:09 +07:00
1 parent a68a88d2da
commit 3a372b5744
5 files changed
+170 -4

No files matched your search

+38 -1
View File
@@ -1875,7 +1875,9 @@ function AddRoutineToSession({ close }) {
if (!s.active) return
s.active.entries.push(...entries)
s.active.routineIds = [...[].concat(s.active.routineIds || []), r.id]
s.active.name = deriveSessionName(s.active.routineIds.map(id => s.routines.find(x => x.id === id)?.name).filter(Boolean))
if (!s.active.customName) {
s.active.name = deriveSessionName(s.active.routineIds.map(id => s.routines.find(x => x.id === id)?.name).filter(Boolean))
}
})
close()
toast(t('{0} added — {1}', r.name, exCount(r.ex.length)))
@@ -2050,6 +2052,41 @@ function SessionNote({ close }) {
}
export const sessionNoteSheet = () => ui().openSheet(close => <SessionNote close={close} />)
function RenameWorkout({ close }) {
const inputRef = useRef(null)
const onFocus = useSheetKeyboard(inputRef)
const st = useStore(s => s.S)
const update = useStore(s => s.update)
const A = st.active
const [name, setName] = useState(A?.name || '')
useEffect(() => { if (!A) close() }, [!A])
if (!A) return null
const trimmed = name.trim().slice(0, 60)
const canSave = trimmed.length > 0
const save = () => {
if (!canSave) return
update(s => {
if (!s.active) return
s.active.name = trimmed
s.active.customName = true
})
close()
}
return <>
<h3>{t('Rename workout')}</h3>
<input ref={inputRef} className="input" type="text" autoFocus maxLength={60} value={name}
placeholder={t('Workout title')}
onFocus={onFocus} onChange={e => setName(e.target.value)}
onKeyDown={e => { if (e.key === 'Enter' && canSave) save() }} />
<div style={{ height: 18 }} />
<Button variant="primary" disabled={!canSave} onClick={save}>{t('Save')}</Button>
</>
}
export const renameWorkoutSheet = () => ui().openSheet(close => <RenameWorkout close={close} />)
/* Drop-set drops and rest-pause bursts are edited inline on the set row itself (Workout.jsx) —
no sheet, no timer. A planned exercise (see the "Intensifier" config below) arrives with them
already computed via applyIntensifierPlan; an unplanned straight set can still grow one live