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.

Plan: swipe left to delete a routine, matching the exercise rows in RoutineEdit

Horus Gonzalez320c1d4d1ea8
diff --git a/frontend/src/views/Plan.jsx b/frontend/src/views/Plan.jsx
index ef00d8db4..7bb9c84a6 100644
--- a/frontend/src/views/Plan.jsx
+++ b/frontend/src/views/Plan.jsx
@@ -2,9 +2,10 @@ import { useNavigate } from 'react-router-dom'
import { useStore } from '../store/useStore.js'
import { DAYN, weekOrder, weekStartOf, uid, exCount, routineCount } from '../lib/format.js'
import { t } from '../lib/i18n.js'
-import { dayAssignSheet, dayAddRoutineSheet, starterPlanSheet, planToolsSheet } from '../sheets.jsx'
+import { dayAssignSheet, dayAddRoutineSheet, starterPlanSheet, planToolsSheet, confirmSheet } from '../sheets.jsx'
import Icon from '../components/Icon.jsx'
import { Button } from '../components/ui.jsx'
+import SwipeToDelete from '../components/SwipeToDelete.jsx'
import { tappable } from '../lib/use-sheet-keyboard.js'
import { glyphOf, DEFAULT_GLYPH } from '../lib/glyphs.js'
import { DEMO } from '../lib/demo.js'
@@ -46,6 +47,21 @@ export default function Plan() {
if (next.length) s.week[d] = next; else delete s.week[d]
})
+ // Same delete RoutineEdit's own "Delete routine" button does (id, name confirmed there) —
+ // duplicated here rather than shared, since RoutineEdit's version also navigates back to
+ // /plan afterwards, which this screen is already on.
+ const deleteRoutine = r => confirmSheet({
+ title: t('Delete routine?'), message: t('“{0}” and its exercises will be removed.', r.name), confirmText: t('Delete'), danger: true,
+ onConfirm: () => update(s => {
+ s.routines = s.routines.filter(x => x.id !== r.id)
+ Object.keys(s.week).forEach(k => {
+ const next = [].concat(s.week[k]).filter(rid => rid !== r.id)
+ if (next.length) s.week[k] = next; else delete s.week[k]
+ })
+ Object.keys(s.dayPlan).forEach(k => { if (s.dayPlan[k] === r.id) delete s.dayPlan[k] })
+ })
+ })
+
return <>
<div className="hdr">
<div><h1>{t('Plan')}</h1><div className="sub">{t('Your weekly routine')}</div></div>
@@ -92,7 +108,8 @@ export default function Plan() {
<h4 className="sec" style={{ margin: 0 }}>{t('Routines')}</h4>
<Button size="sm" variant="tinted" icon="plus" onClick={addRoutine}>{t('New')}</Button>
</div>
- {S.routines.length ? <div className="list">{S.routines.map((r, i) => <div key={r.id} className="item" {...tappable(() => nav('/plan/r/' + r.id))}>
+ {S.routines.length ? <div className="list">{S.routines.map((r, i) => <SwipeToDelete key={r.id} className="item"
+ deleteLabel={t('Delete routine')} onDelete={() => deleteRoutine(r)} onClick={() => nav('/plan/r/' + r.id)}>
<span className="lrow-i"><Icon name={glyphOf(r.emoji)} /></span>
<div className="grow"><div className="tt">{r.name}</div><div className="ss">{exCount(r.ex.length)}</div></div>
{/* The order of this list is the order of `S.routines`, and every other screen reads the
@@ -106,7 +123,7 @@ export default function Plan() {
style={{ width: 28, height: 24, borderRadius: 7, fontSize: 12 }}
onClick={ev => { ev.stopPropagation(); moveRoutine(i, 1) }}><Icon name="chevronDown" /></button>
</div>}
- <Icon name="chevronRight" className="chev" /></div>)}</div> : <>
+ <Icon name="chevronRight" className="chev" /></SwipeToDelete>)}</div> : <>
<div className="empty"><div className="ico"><Icon name="clipboard" /></div>{t('No routines yet.')}<br />{t('Create one or load the starter plan.')}</div>
<Button icon="sparkles" onClick={starterPlanSheet}>{t('Load starter plan')}</Button>
</>}