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
Menus: a menu sheet can come in groups, each with a small header
Duarte Santos5efe95e43571
diff --git a/frontend/src/index.css b/frontend/src/index.cssindex 296cd4ec1..05ba2bbc5 100644--- a/frontend/src/index.css+++ b/frontend/src/index.css@@ -1200,6 +1200,18 @@ body.chips-dragging *{cursor:inherit}.menu-list .menu-item.disabled{opacity:.4;pointer-events:none}.menu-on{color:transparent;font-size:16px;flex:none}.menu-on.is-on{color:var(--acc)}+/* A grouped menu (menuSheet's `sections`): groups sit apart, each with a small header, so a long+ list reads as four short ones. */+.menu-group.grouped+.menu-group.grouped{margin-top:14px}+.menu-group.grouped .menu-list{gap:0;background:var(--surface);border-radius:var(--r-card);overflow:hidden}+.menu-group.grouped .menu-item{border-radius:0;position:relative}+.menu-group.grouped .menu-item+.menu-item::before{+ content:'';position:absolute;top:0;inset-inline-start:56px;inset-inline-end:0;height:var(--hair);background:var(--sep-op);+}+.menu-sec{font-size:13px;font-weight:600;color:var(--label-2);padding:0 6px 6px;letter-spacing:.005em}+.menu-list .menu-item.accent .lrow-i{background:var(--acc);color:var(--on-acc)}+.menu-chev{color:var(--label-3);font-size:14px;flex:none}+[dir="rtl"] .menu-chev{transform:scaleX(-1)}.setextra{display:flex;flex-wrap:wrap;gap:6px;margin:2px 0 8px 32px}.setextra .chip.add{display:inline-flex;align-items:center;gap:4px;color:var(--acc)}.setextra .chip.add svg{width:13px;height:13px}diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex 8bce98146..9c303097b 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -99,23 +99,33 @@ export function askAddDeviceData(extras) {// everything that is not a set you are about to log: the point of a single "more" button is// that the ten things you do once a session stop competing with the two you do every set.// items: [{ icon, label, sub, onClick, danger, disabled, on }] — `on` draws a check for toggles.+// sections: [{ title, items }] instead of `items` splits a longer menu into groups, each with an+// optional small header; a group whose items are all falsy is left out, header and all.+// `accent` tints a row's icon, for the one entry a menu leads with.// A title is shown as written: most are sentences ("Convert to lb?", "Set 2"), which a default// title-casing turned into "Convert To Lb?". An exercise name passes exerciseNameClass as// titleClass, which title-cases the lower-case packs and leaves a cased one alone.-function MenuSheet({ title, titleClass = '', subtitle, items, close }) {+function MenuSheet({ title, titleClass = '', subtitle, items, sections, close }) {+ const groups = (sections || [{ items }])+ .map(g => ({ title: g.title, items: (g.items || []).filter(Boolean) }))+ .filter(g => g.items.length)return <>{title && <h3 className={titleClass || undefined} style={{ marginBottom: subtitle ? 2 : 10 }}>{title}</h3>}{subtitle && <div className="muted small" style={{ marginBottom: 10 }}>{subtitle}</div>}- <div className="list menu-list">- {items.filter(Boolean).map((it, i) => <div key={i}- className={'item menu-item' + (it.danger ? ' danger' : '') + (it.disabled ? ' disabled' : '')}- aria-disabled={it.disabled || undefined}- {...tappable(it.disabled ? null : () => { close(); it.onClick && it.onClick() })}>- {it.icon && <span className="lrow-i"><Icon name={it.icon} /></span>}- <div className="grow"><div className="tt">{it.label}</div>{it.sub && <div className="ss">{it.sub}</div>}</div>- {it.on != null && <span className={'menu-on' + (it.on ? ' is-on' : '')}><Icon name="check" /></span>}- </div>)}- </div>+ {groups.map((g, gi) => <div key={gi} className={'menu-group' + (sections ? ' grouped' : '')}>+ {g.title && <div className="menu-sec">{g.title}</div>}+ <div className="list menu-list">+ {g.items.map((it, i) => <div key={i}+ className={'item menu-item' + (it.danger ? ' danger' : '') + (it.disabled ? ' disabled' : '') + (it.accent ? ' accent' : '')}+ aria-disabled={it.disabled || undefined}+ {...tappable(it.disabled ? null : () => { close(); it.onClick && it.onClick() })}>+ {it.icon && <span className="lrow-i"><Icon name={it.icon} /></span>}+ <div className="grow"><div className="tt">{it.label}</div>{it.sub && <div className="ss">{it.sub}</div>}</div>+ {it.on != null && <span className={'menu-on' + (it.on ? ' is-on' : '')}><Icon name="check" /></span>}+ {it.chevron && <Icon name="chevronRight" className="menu-chev" />}+ </div>)}+ </div>+ </div>)}</>}export function menuSheet(opts) {diff --git a/frontend/src/sheets.menu-sections.test.jsx b/frontend/src/sheets.menu-sections.test.jsxnew file mode 100644index 000000000..ce30d1297--- /dev/null+++ b/frontend/src/sheets.menu-sections.test.jsx@@ -0,0 +1,51 @@+// @vitest-environment happy-dom+import React, { act } from 'react'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { createRoot } from 'react-dom/client'+import { useUI } from './store/useUI.js'+import { menuSheet } from './sheets.jsx'++// menuSheet's `sections` (v1.3.11): a long menu in groups with small headers; a group with+// nothing left in it after the falsy items are dropped goes, header and all.+let host, root+beforeEach(() => {+ globalThis.IS_REACT_ACT_ENVIRONMENT = true+ useUI.setState({ sheets: [] })+ host = document.createElement('div')+ document.body.appendChild(host)+ root = createRoot(host)+})+afterEach(() => { act(() => root.unmount()); host.remove(); useUI.setState({ sheets: [] }) })++const show = () => {+ const sheet = useUI.getState().sheets.at(-1)+ act(() => root.render(sheet.render(() => useUI.getState().closeSheet(sheet.id))))+}++describe('menuSheet sections', () => {+ it('renders each group with its header, skips empty ones, and runs the tapped action', () => {+ const swap = vi.fn()+ menuSheet({ title: 'Bench', sections: [+ { title: 'Today', items: [{ icon: 'swap', label: 'Swap exercise', onClick: swap }, false] },+ { title: 'Nothing here', items: [null, false] },+ { items: [{ icon: 'gear', label: 'Workout settings', accent: true, chevron: true }] },+ { items: [{ icon: 'trash', label: 'Remove exercise', danger: true }] },+ ] })+ show()+ const groups = [...host.querySelectorAll('.menu-group')]+ expect(groups.map(g => g.querySelector('.menu-sec')?.textContent ?? null)).toEqual(['Today', null, null])+ expect(groups.map(g => [...g.querySelectorAll('.menu-item .tt')].map(e => e.textContent))).toEqual([['Swap exercise'], ['Workout settings'], ['Remove exercise']])+ expect(host.querySelector('.menu-item.accent .menu-chev')).toBeTruthy()+ expect(host.querySelector('.menu-item.danger .tt').textContent).toBe('Remove exercise')+ act(() => host.querySelector('.menu-item').click())+ expect(swap).toHaveBeenCalledOnce()+ expect(useUI.getState().sheets).toEqual([])+ })++ it('still takes a flat `items` list', () => {+ menuSheet({ items: [{ label: 'One' }, null, { label: 'Two' }] })+ show()+ expect([...host.querySelectorAll('.menu-item .tt')].map(e => e.textContent)).toEqual(['One', 'Two'])+ expect(host.querySelector('.menu-sec')).toBeNull()+ })+})