From 283d89776204232cb020c9c2f6c64bc520ebb26c Mon Sep 17 00:00:00 2001 From: doby-llm Date: Tue, 25 Aug 2026 22:13:48 +0200 Subject: [PATCH 1/3] feat: add Stats exercise progress picker search --- frontend/src/components/ui.jsx | 47 ++++++++++++------- frontend/src/views/Stats.jsx | 10 ++++- frontend/src/views/Stats.recovery.test.jsx | 52 +++++++++++++++++++++- 3 files changed, 90 insertions(+), 19 deletions(-) diff --git a/frontend/src/components/ui.jsx b/frontend/src/components/ui.jsx index 8c9fd0c..a65a30c 100644 --- a/frontend/src/components/ui.jsx +++ b/frontend/src/components/ui.jsx @@ -248,25 +248,12 @@ export function Row({ icon, iconTint, title, subtitle, value, accessory = 'none' // theme entirely — on dark mode it flashes a white sheet — and can't show more // than a bare label per option. This opens our own sheet with a checkmark on the // current value, which is also how iOS itself handles a long option list. -export function SelectRow({ icon, iconTint, title, value, options, onChange, sheetTitle, stackedValue = false }) { +export function SelectRow({ icon, iconTint, title, value, options, onChange, sheetTitle, stackedValue = false, search }) { const cur = options.find(o => o.value === value) const open = () => { const { openSheet } = require_ui() - const h = openSheet(close => ( - <> -

{sheetTitle || title}

-
- {options.map(o => ( - - ))} -
-
- - )) + const h = openSheet(close => ) return h } return ( @@ -275,6 +262,34 @@ export function SelectRow({ icon, iconTint, title, value, options, onChange, she ) } +function SelectSheet({ title, value, options, onChange, search, close }) { + const [query, setQuery] = useState('') + const matcher = typeof search === 'function' ? search : search?.match + const visible = matcher ? options.filter(o => matcher(o, query)) : options + return ( + <> +

{title}

+ {search &&
+ setQuery(e.target.value)} onInput={e => setQuery(e.target.value)} + onClear={() => setQuery('')} placeholder={search.placeholder} aria-label={search.label || search.placeholder} /> +
} +
+ {visible.map(o => ( + + ))} + {!visible.length && search &&
+
{search.emptyLabel} +
} +
+
+ + ) +} + /** Multi-select row for additive exercise metadata. The sheet mirrors selection locally so * each tap updates its checkmark immediately while the caller persists the value. */ export function MultiSelectRow({ icon, iconTint, title, values, options, onToggle, sheetTitle, noneLabel, doneLabel }) { diff --git a/frontend/src/views/Stats.jsx b/frontend/src/views/Stats.jsx index 3622b7b..6c02109 100644 --- a/frontend/src/views/Stats.jsx +++ b/frontend/src/views/Stats.jsx @@ -1,7 +1,7 @@ import { useEffect, useMemo, useState } from 'react' import { useNavigate } from 'react-router-dom' import { useStore } from '../store/useStore.js' -import { EXIDX } from '../lib/exercises.js' +import { EXIDX, matchExercise } from '../lib/exercises.js' import { lastBW, streakWeeks, setLabel, modeOf, effortOf, metricModeForEntry, metricRowsForEntry, bestWeightForEntry } from '../lib/history.js' import { fmtNum, fmtDate, fmtVol, todayISO, weekKey } from '../lib/format.js' import { t, exerciseNameFor, getLang } from '../lib/i18n.js' @@ -428,7 +428,13 @@ export default function Stats() { {exHist.length ? <>
({ value: id, label: nameOf(id) + (exCurrent[id].mx ? ' ' + '—' + ' ' + fmtNum(exCurrent[id].mx) + ' ' + exCurrent[id].unit : '') }))} /> + options={exHist.map(id => ({ value: id, label: nameOf(id) + (exCurrent[id].mx ? ' ' + '—' + ' ' + fmtNum(exCurrent[id].mx) + ' ' + exCurrent[id].unit : '') }))} + search={{ + placeholder: t('Search…'), + label: t('Search…'), + emptyLabel: t('No match'), + match: (option, query) => matchExercise(EXIDX[option.value] || { n: nameOf(option.value) }, query), + }} />
{exOpts.length > 1 && }
diff --git a/frontend/src/views/Stats.recovery.test.jsx b/frontend/src/views/Stats.recovery.test.jsx index 70d1e0a..8496939 100644 --- a/frontend/src/views/Stats.recovery.test.jsx +++ b/frontend/src/views/Stats.recovery.test.jsx @@ -6,6 +6,9 @@ import { MUSCLES, levelsOf } from '../lib/muscles.js' import { FATIGUE_STATES, STRENGTH_FLOOR } from '../lib/recovery.js' import { fatigueStateOf } from '../lib/recovery-view.js' import Stats from './Stats.jsx' +import Modals from '../components/Modals.jsx' +import { bindUI } from '../components/ui.jsx' +import { useUI } from '../store/useUI.js' const DAY = 86400000 const HOUR = 3600000 @@ -50,6 +53,8 @@ vi.mock('../components/BodyMap.jsx', () => ({ BodyMapLegend: () => React.createElement('div', { 'data-balance-legend': true }), })) +bindUI(useUI) + let dom let root let container @@ -105,19 +110,30 @@ function allSubfullWorkout(now = BASE_NOW) { return workout('all-subfull', now - 15 * DAY, [entry('1254', [set(true)])]) } +function exercisePickerWorkouts(now = BASE_NOW) { + return [ + workout('bench', now, [entry('0025', [set(true, { w: 80 })])]), + workout('squat', now - DAY, [entry('0043', [set(true, { w: 60 })])]), + ] +} + function resetFixture(workouts = lifecycleWorkouts()) { mocks.S.unit = 'kg' mocks.S.bodyweight = [] mocks.S.workouts = workouts mocks.maps.length = 0 mocks.mapMounts = 0 + useUI.setState({ sheets: [] }) } function installDom() { dom = new Window({ url: 'http://localhost/' }) + dom.scrollTo = vi.fn() globalThis.window = dom globalThis.document = dom.document Object.defineProperty(globalThis, 'navigator', { configurable: true, value: dom.navigator }) + Object.defineProperty(globalThis, 'location', { configurable: true, value: dom.location }) + Object.defineProperty(globalThis, 'history', { configurable: true, value: dom.history }) for (const key of ['HTMLElement', 'HTMLIFrameElement', 'Node', 'Element', 'Event', 'MouseEvent']) { globalThis[key] = dom[key] } @@ -129,7 +145,7 @@ function installDom() { async function mountStats() { installDom() - await act(async () => { root.render(React.createElement(Stats)) }) + await act(async () => { root.render(React.createElement(React.Fragment, null, React.createElement(Stats), React.createElement(Modals))) }) } async function unmountStats() { @@ -179,6 +195,7 @@ beforeEach(() => { afterEach(async () => { await unmountStats() + useUI.setState({ sheets: [] }) vi.useRealTimers() vi.restoreAllMocks() }) @@ -272,3 +289,36 @@ describe('Stats muscle recovery view runtime', () => { expect(strengthMap.thresholds.at(-1)).toEqual({ at: 1, level: 4 }) }) }) + +describe('Stats exercise progress picker', () => { + it('filters with the shared exercise matcher and still selects from the mounted sheet', async () => { + resetFixture(exercisePickerWorkouts()) + await mountStats() + + const card = [...container.querySelectorAll('.card')].find(el => el.querySelector('h2')?.textContent.trim() === 'Exercise progress') + const selector = [...card.querySelectorAll('button')].find(button => button.querySelector('.lrow-t')?.textContent.trim() === 'Exercise') + await click(selector) + + const modal = document.querySelector('#modal-root') + const input = modal.querySelector('input') + expect(input).toBeTruthy() + expect(input.getAttribute('aria-label')).toBe('Search…') + expect(input.getAttribute('placeholder')).toBe('Search…') + + const setter = Object.getOwnPropertyDescriptor(input.constructor.prototype, 'value').set + await act(async () => { + setter.call(input, 'squat full bárbell') + input.dispatchEvent(new Event('input', { bubbles: true })) + input.dispatchEvent(new Event('change', { bubbles: true })) + }) + + expect(modal.textContent).toContain('barbell full squat') + expect(modal.textContent).not.toContain('barbell bench press') + + const matching = [...modal.querySelectorAll('button')].find(button => button.textContent.includes('barbell full squat')) + await click(matching) + + expect(useUI.getState().sheets).toHaveLength(0) + expect(card.querySelector('.lrow-v').textContent).toContain('barbell full squat') + }) +}) From 40df469fd65a1277e76cbcc4132252d35fca4b26 Mon Sep 17 00:00:00 2001 From: doby-llm Date: Tue, 25 Aug 2026 22:32:27 +0200 Subject: [PATCH 2/3] fix(stats): harden historical exercise search fallback --- frontend/src/views/Stats.jsx | 35 ++++++++++++++++-- frontend/src/views/Stats.recovery.test.jsx | 41 ++++++++++++++++++++-- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/frontend/src/views/Stats.jsx b/frontend/src/views/Stats.jsx index 6c02109..e6e5c00 100644 --- a/frontend/src/views/Stats.jsx +++ b/frontend/src/views/Stats.jsx @@ -291,7 +291,38 @@ export default function Stats() { const workouts = S.workouts const monthW = workouts.filter(w => String(w.d || '').slice(0, 7) === todayISO().slice(0, 7)).length - const nameOf = id => EXIDX[id] ? exerciseNameFor(EXIDX[id]) : (workouts.flatMap(w => w.entries).find(e => e.id === id)?.n || id) + const entryOf = id => workouts.flatMap(w => w.entries).find(e => e.id === id) + const listOf = value => Array.isArray(value) ? value : value == null || value === '' ? [] : [value] + const firstAvailable = (...values) => { + for (const value of values) { + const list = listOf(value) + if (list.length) return list + } + return [] + } + const nameOf = id => { + if (EXIDX[id]) return exerciseNameFor(EXIDX[id]) + const entry = entryOf(id) + return entry?.muscleSnapshot?.n || entry?.n || id + } + const matcherOf = id => { + if (EXIDX[id]) return EXIDX[id] + const entry = entryOf(id) + const snapshot = entry?.muscleSnapshot || {} + const primaries = firstAvailable(snapshot.primaries, entry?.primaries) + const secondaries = firstAvailable( + snapshot.sm, snapshot.secondaries, snapshot.muscleGroups, + entry?.sm, entry?.secondaries, entry?.muscleGroups, + ) + return { + n: snapshot.n || entry?.n || id, + bp: snapshot.bp || entry?.bp || '', + tg: primaries[0] || snapshot.tg || entry?.tg || '', + sm: secondaries, + eq: snapshot.eq || entry?.eq || '', + desc: snapshot.desc || entry?.desc || '', + } + } const currentOf = id => { for (let i = workouts.length - 1; i >= 0; i--) { const en = workouts[i].entries.find(e => e.id === id) @@ -433,7 +464,7 @@ export default function Stats() { placeholder: t('Search…'), label: t('Search…'), emptyLabel: t('No match'), - match: (option, query) => matchExercise(EXIDX[option.value] || { n: nameOf(option.value) }, query), + match: (option, query) => matchExercise(matcherOf(option.value), query), }} />
{exOpts.length > 1 && } diff --git a/frontend/src/views/Stats.recovery.test.jsx b/frontend/src/views/Stats.recovery.test.jsx index 8496939..908c493 100644 --- a/frontend/src/views/Stats.recovery.test.jsx +++ b/frontend/src/views/Stats.recovery.test.jsx @@ -2,6 +2,7 @@ import React, { act } from 'react' import { createRoot } from 'react-dom/client' import { Window } from 'happy-dom' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { EXIDX } from '../lib/exercises.js' import { MUSCLES, levelsOf } from '../lib/muscles.js' import { FATIGUE_STATES, STRENGTH_FLOOR } from '../lib/recovery.js' import { fatigueStateOf } from '../lib/recovery-view.js' @@ -13,6 +14,7 @@ import { useUI } from '../store/useUI.js' const DAY = 86400000 const HOUR = 3600000 const BASE_NOW = Date.UTC(2026, 0, 22, 12) +const LEGACY_SNAPSHOT_ID = 'legacy-snapshot-only' const mocks = vi.hoisted(() => ({ maps: [], @@ -114,6 +116,19 @@ function exercisePickerWorkouts(now = BASE_NOW) { return [ workout('bench', now, [entry('0025', [set(true, { w: 80 })])]), workout('squat', now - DAY, [entry('0043', [set(true, { w: 60 })])]), + workout('legacy', now - 2 * DAY, [ + { + id: LEGACY_SNAPSHOT_ID, + muscleSnapshot: { + n: 'Legacy shoulder press', + bp: 'shoulders', + primaries: ['deltoids'], + secondaries: ['triceps'], + muscleGroups: ['deltoids', 'triceps'], + }, + sets: [set(true, { w: 50 })], + }, + ]), ] } @@ -294,6 +309,7 @@ describe('Stats exercise progress picker', () => { it('filters with the shared exercise matcher and still selects from the mounted sheet', async () => { resetFixture(exercisePickerWorkouts()) await mountStats() + expect(EXIDX[LEGACY_SNAPSHOT_ID]).toBeUndefined() const card = [...container.querySelectorAll('.card')].find(el => el.querySelector('h2')?.textContent.trim() === 'Exercise progress') const selector = [...card.querySelectorAll('button')].find(button => button.querySelector('.lrow-t')?.textContent.trim() === 'Exercise') @@ -304,14 +320,35 @@ describe('Stats exercise progress picker', () => { expect(input).toBeTruthy() expect(input.getAttribute('aria-label')).toBe('Search…') expect(input.getAttribute('placeholder')).toBe('Search…') + const optionButtons = () => [...modal.querySelectorAll('.sect-b button')] + const initialOptionCount = optionButtons().length + expect(initialOptionCount).toBe(3) + expect(modal.textContent).toContain('Legacy shoulder press') + expect(input.compareDocumentPosition(optionButtons()[0]) & globalThis.Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy() const setter = Object.getOwnPropertyDescriptor(input.constructor.prototype, 'value').set - await act(async () => { - setter.call(input, 'squat full bárbell') + const setSearch = async value => act(async () => { + setter.call(input, value) input.dispatchEvent(new Event('input', { bubbles: true })) input.dispatchEvent(new Event('change', { bubbles: true })) }) + await setSearch('no such historical exercise') + expect(modal.textContent).toContain('No match') + expect(optionButtons()).toHaveLength(0) + + await click(modal.querySelector('button[aria-label="Clear"]')) + expect(input.value).toBe('') + expect(optionButtons()).toHaveLength(initialOptionCount) + expect(modal.textContent).toContain('Legacy shoulder press') + + await setSearch('legacy shoulder press shoulders deltoids triceps') + expect(optionButtons()).toHaveLength(1) + expect(optionButtons()[0].textContent).toContain('Legacy shoulder press') + + await click(modal.querySelector('button[aria-label="Clear"]')) + await setSearch('squat full bárbell') + expect(modal.textContent).toContain('barbell full squat') expect(modal.textContent).not.toContain('barbell bench press') From 4422e4c3877f4c07b88e2e27a7386b3356aa50cd Mon Sep 17 00:00:00 2001 From: doby-llm Date: Tue, 25 Aug 2026 22:51:55 +0200 Subject: [PATCH 3/3] fix(ui): keep picker results above mobile keyboard --- frontend/src/components/ui.jsx | 74 ++++++++++++++++++++-- frontend/src/index.css | 12 +++- frontend/src/views/Stats.recovery.test.jsx | 19 ++++++ 3 files changed, 97 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/ui.jsx b/frontend/src/components/ui.jsx index a65a30c..b9aa100 100644 --- a/frontend/src/components/ui.jsx +++ b/frontend/src/components/ui.jsx @@ -60,11 +60,11 @@ export function TextArea({ className = '', ...rest }) { return