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.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Plan: a day that already has a routine offers a small + in its header instead of a full-width Add routine button (#276)
Duarte Santos20df988523b6
diff --git a/frontend/src/views/Plan.add-routine.test.jsx b/frontend/src/views/Plan.add-routine.test.jsxnew file mode 100644index 000000000..437b3d623--- /dev/null+++ b/frontend/src/views/Plan.add-routine.test.jsx@@ -0,0 +1,76 @@+// @vitest-environment happy-dom+// #276: a full-width "+ Add routine" under every planned weekday made the week read as a list of+// buttons. A populated day now offers the same action as a small + in its header; an empty day+// is still one tappable row that picks its first routine.+import React, { act } from 'react'+import { createRoot } from 'react-dom/client'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import Plan from './Plan.jsx'+import { dayAddRoutineSheet, dayAssignSheet } from '../sheets.jsx'++globalThis.IS_REACT_ACT_ENVIRONMENT = true++const mocks = vi.hoisted(() => {+ const state = { S: null }+ state.snapshot = () => ({+ S: state.S,+ user: null,+ update: mut => {+ const next = structuredClone(state.S)+ mut(next)+ state.S = next+ },+ })+ return state+})+vi.mock('../store/useStore.js', () => {+ const useStore = selector => (selector ? selector(mocks.snapshot()) : mocks.snapshot())+ useStore.getState = mocks.snapshot+ return { useStore, DEF: { reminder: { time: '17:30' } }, hasData: () => false }+})+vi.mock('react-router-dom', () => ({ useNavigate: () => () => {} }))+vi.mock('../lib/mobile.js', () => ({ MOBILE: false, isAndroid: () => Promise.resolve(false), shareExport: vi.fn(), syncReminder: vi.fn() }))+vi.mock('../sheets.jsx', () => ({+ starterPlanSheet: vi.fn(), dayAssignSheet: vi.fn(), dayAddRoutineSheet: vi.fn(), planToolsSheet: vi.fn(),+}))++let host, root+beforeEach(() => {+ vi.clearAllMocks()+ mocks.S = {+ unit: 'kg', workouts: [], exWeights: {}, week: { 1: ['r1'] }, dayPlan: {},+ routines: [{ id: 'r1', name: 'Push', emoji: null, ex: [] }, { id: 'r2', name: 'Pull', emoji: null, ex: [] }],+ }+ host = document.createElement('div')+ document.body.appendChild(host)+ root = createRoot(host)+})+afterEach(() => {+ act(() => root.unmount())+ host.remove()+})++const mount = () => act(() => root.render(<Plan />))+const dayItem = day => [...host.querySelectorAll('.item')].find(el => el.querySelector('.tt')?.textContent === day)++describe('Plan — adding a routine to a day that already has one (#276)', () => {+ it('offers a compact + in the day header instead of a full-width text button', () => {+ mount()+ const monday = dayItem('Monday')+ expect(monday.textContent).not.toContain('Add routine')+ const plus = monday.querySelector('button[aria-label="Add routine"]')+ expect(plus).toBeTruthy()+ // It sits in the header row with the count, not under the routine rows.+ expect(plus.closest('.row.between')?.querySelector('.tt')?.textContent).toBe('Monday')+ act(() => plus.click())+ expect(dayAddRoutineSheet).toHaveBeenCalledWith(1)+ })++ it('leaves an empty day as one row that picks its first routine', () => {+ mount()+ const tuesday = dayItem('Tuesday')+ expect(tuesday.querySelector('button[aria-label="Add routine"]')).toBeNull()+ act(() => tuesday.click())+ expect(dayAssignSheet).toHaveBeenCalledWith(2)+ })+})diff --git a/frontend/src/views/Plan.jsx b/frontend/src/views/Plan.jsxindex ef00d8db4..5a6a277ad 100644--- a/frontend/src/views/Plan.jsx+++ b/frontend/src/views/Plan.jsx@@ -70,20 +70,25 @@ export default function Plan() {<div className="grow"><div className="tt">{t(DAYN[d])}</div></div><span className="tag">{t('Rest')}</span><Icon name="chevronRight" className="chev" /></div>- // A populated day: always-visible routine sub-rows + inline ✕, then + Add routine.+ // A populated day: always-visible routine sub-rows + inline ✕. Adding a second routine+ // is a small + in the day's header, centred over the ✕ column (#276): a full-width+ // "+ Add routine" under every planned day made the week read as a list of buttons,+ // when most people train one routine a day. The + keeps the option for those who don't.return <div key={d} className="item" style={{ display: 'block', padding: '10px 14px' }}><div className="row between" style={{ marginBottom: 6 }}><div className="tt">{t(DAYN[d])}</div>- <div className="small dim">{routineCount(dayRoutines.length)}</div>+ <div className="row" style={{ gap: 8 }}>+ <div className="small dim">{routineCount(dayRoutines.length)}</div>+ <button className="iconbtn sm" aria-label={t('Add routine')} title={t('Add routine')}+ style={{ width: 30, height: 30, margin: '-5px 3px', fontSize: 15 }}+ onClick={() => dayAddRoutineSheet(d)}><Icon name="plus" /></button>+ </div></div>{dayRoutines.map(r => <div key={r.id} className="row" style={{ gap: 8, padding: '4px 0 4px 8px' }}><span className="lrow-i" style={{ width: 26, height: 26, fontSize: 14 }}><Icon name={glyphOf(r.emoji)} /></span><div className="grow" style={{ minWidth: 0 }}><div className="tt" style={{ fontSize: 14 }}>{r.name}</div><div className="ss">{exCount(r.ex.length)}</div></div><button className="iconbtn sm" aria-label={t('Remove')} onClick={() => removeFromDay(d, r.id)}><Icon name="xmark" /></button></div>)}- <button className="btn ghost sm" style={{ marginTop: 4, marginLeft: 8 }} onClick={() => dayAddRoutineSheet(d)}>- <Icon name="plus" /> {t('Add routine')}- </button></div>})}</div>