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.

Exercises as picture cards: a list/cards button beside the search in the library, the picker and the muscle explorer

Aleksey Sinkevich02c42de31d40
diff --git a/frontend/src/components/ExerciseViewToggle.jsx b/frontend/src/components/ExerciseViewToggle.jsx
new file mode 100644
index 000000000..021a36277
--- /dev/null
+++ b/frontend/src/components/ExerciseViewToggle.jsx
@@ -0,0 +1,14 @@
+import { useStore } from '../store/useStore.js'
+import { t } from '../lib/i18n.js'
+import Icon from './Icon.jsx'
+
+// The button beside the search field that switches the exercise lists (Library, picker, muscle
+// explorer) between rows and picture cards. Not in the header: on a phone the Library header
+// already leaves its title little room next to "By muscle" (Library.test.jsx), while the search
+// row is full-width everywhere a list is, and sits right above the list it changes.
+export default function ExerciseViewToggle() {
+ const cards = useStore(s => s.S.exerciseView === 'cards')
+ const update = useStore(s => s.update)
+ return <button className={'iconbtn ex-view-btn' + (cards ? ' on' : '')} aria-label={t('Cards')} aria-pressed={cards}
+ onClick={() => update(s => { s.exerciseView = cards ? 'list' : 'cards' })}><Icon name="grid" /></button>
+}
diff --git a/frontend/src/components/Icon.jsx b/frontend/src/components/Icon.jsx
index 75ba4ab81..f52850bff 100644
--- a/frontend/src/components/Icon.jsx
+++ b/frontend/src/components/Icon.jsx
@@ -97,6 +97,7 @@ const P = {
personCircle: <><circle cx="12" cy="12" r="8.4" /><circle cx="12" cy="10" r="2.9" /><path d="M6.6 18.4a5.8 5.8 0 0 1 10.8 0" /></>,
clipboard: <><rect x="5.4" y="4.8" width="13.2" height="15.8" rx="2.6" /><path d="M9 4.8a1.6 1.6 0 0 1 1.6-1.6h2.8A1.6 1.6 0 0 1 15 4.8v1.4H9Z" /><path d="M9.2 11.6h5.6M9.2 15.2h4" /></>,
list: <path d="M8.4 6.6h11.2M8.4 12h11.2M8.4 17.4h11.2M4.6 6.6h.01M4.6 12h.01M4.6 17.4h.01" />,
+ grid: <><rect x="4" y="4" width="6.5" height="6.5" rx="1.6" /><rect x="13.5" y="4" width="6.5" height="6.5" rx="1.6" /><rect x="4" y="13.5" width="6.5" height="6.5" rx="1.6" /><rect x="13.5" y="13.5" width="6.5" height="6.5" rx="1.6" /></>,
folder: <path d="M3.6 7.4a2 2 0 0 1 2-2h3.1l2 2.4h6.7a2 2 0 0 1 2 2v7.8a2 2 0 0 1-2 2H5.6a2 2 0 0 1-2-2Z" />,
globe: <><circle cx="12" cy="12" r="8.2" /><path d="M3.8 12h16.4M12 3.8c2.1 2.2 3.2 5.1 3.2 8.2s-1.1 6-3.2 8.2c-2.1-2.2-3.2-5.1-3.2-8.2s1.1-6 3.2-8.2Z" /></>,
moon: <path d="M19.4 14.2A7.8 7.8 0 0 1 9.8 4.6a8.2 8.2 0 1 0 9.6 9.6Z" />,
diff --git a/frontend/src/components/MuscleExplorer.jsx b/frontend/src/components/MuscleExplorer.jsx
index f51472f99..63273a629 100644
--- a/frontend/src/components/MuscleExplorer.jsx
+++ b/frontend/src/components/MuscleExplorer.jsx
@@ -9,6 +9,7 @@ import { t, exerciseNameFor, exerciseNameClass } from '../lib/i18n.js'
import BodyMap from './BodyMap.jsx'
import { Thumb } from './Media.jsx'
import Icon from './Icon.jsx'
+import ExerciseViewToggle from './ExerciseViewToggle.jsx'
import { Button } from './ui.jsx'
import { tappable } from '../lib/use-sheet-keyboard.js'
import { isFav, sortFavouritesFirst } from '../lib/favourites.js'
@@ -70,11 +71,11 @@ export default function MuscleExplorer({ onPick, onDetail, onPlan }) {
<h4 className="sec" style={{ margin: 0 }}>{t('Exercises for {0}', t(MUSCLE_NAME[selected]))}</h4>
<Button size="sm" variant="ghost" onClick={() => pick(selected)}>{t('Clear selection')}</Button>
</div>
- <div className={'search' + (narrowed ? ' has-count' : '') + (q ? ' has-clear' : '')} style={{ marginBottom: 10 }}><svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="7" /><path d="m21 21-4.3-4.3" /></svg>
+ <div className="search-row" style={{ marginBottom: 10 }}><div className={'search' + (narrowed ? ' has-count' : '') + (q ? ' has-clear' : '')}><svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="7" /><path d="m21 21-4.3-4.3" /></svg>
<input className="input" placeholder={t('Search…')} value={q} onChange={e => { setQ(e.target.value); setShown(40) }} />
{narrowed && <span className="search-count" role="status" aria-label={exCount(exercises.length)}>{fmtNum(exercises.length)}</span>}
{q && <button className="clear" onClick={() => { setQ(''); setShown(40) }} aria-label={t('Clear')}><Icon name="xmark" /></button>}
- </div>
+ </div><ExerciseViewToggle /></div>
{/* Changing body part keeps the equipment filter (issue #71, same rule as Library): the
eqOn fallback above drops it only for this view if the new body part has nothing under
it, without forgetting the choice. "All" clears it, since it spans every body part. */}
@@ -86,7 +87,7 @@ export default function MuscleExplorer({ onPick, onDetail, onPlan }) {
<button className={'chip nocap' + (!eqOn ? ' on' : '')} onClick={() => { setEq(''); setShown(40) }}>{t('Any equipment')}</button>
{eqOpts.map(x => <button key={x} className={'chip' + (eqOn === x ? ' on' : '')} onClick={() => { setEq(x); setShown(40) }}>{t(x)}</button>)}
</div>}
- <div className="list">
+ <div className={'list' + (S.exerciseView === 'cards' ? ' ex-grid' : '')}>
{exercises.slice(0, shown).map(e => {
const best = bestWeightFor(S, e.id)
const primary = musclesOf(e)[selected] === 1
diff --git a/frontend/src/exercise-view.test.jsx b/frontend/src/exercise-view.test.jsx
new file mode 100644
index 000000000..4bd7e17f5
--- /dev/null
+++ b/frontend/src/exercise-view.test.jsx
@@ -0,0 +1,111 @@
+// @vitest-environment happy-dom
+// List or cards (S.exerciseView): one button beside the search field switches every exercise
+// list — the Library, the add-exercise picker and the muscle explorer — between rows with a 50px
+// thumbnail and a grid of picture cards with the name under the picture. The list stays the default, so a profile that
+// never touches the button sees exactly what it saw before.
+import React, { act } from 'react'
+import { readFileSync } from 'node:fs'
+import { resolve } from 'node:path'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { createRoot } from 'react-dom/client'
+import { DEF, useStore } from './store/useStore.js'
+import { useUI } from './store/useUI.js'
+import { exercisePicker } from './sheets.jsx'
+import Library from './views/Library.jsx'
+import Muscles from './views/Muscles.jsx'
+
+vi.mock('react-router-dom', () => ({ useNavigate: () => () => {} }))
+
+const mounted = []
+const view = () => useStore.getState().S.exerciseView
+function render(node) {
+ const host = document.createElement('div')
+ document.body.appendChild(host)
+ const root = createRoot(host)
+ mounted.push(root)
+ act(() => root.render(node))
+ return host
+}
+// Renders whatever sheet is on top and returns its host element.
+function renderTop() {
+ const sheet = useUI.getState().sheets.at(-1)
+ return render(sheet.render(() => useUI.getState().closeSheet(sheet.id)))
+}
+const toggle = host => host.querySelector('button[aria-label="Cards"]')
+// The button belongs to the search row, next to the field — never in a header (see the next test).
+const besideSearch = btn => btn.parentElement.classList.contains('search-row') && !!btn.parentElement.querySelector('.search input')
+const isCards = host => host.querySelector('.list').classList.contains('ex-grid')
+const pickMuscle = host => act(() => host.querySelector('.chip[aria-pressed]').click())
+const setView = v => useStore.setState(s => ({ S: { ...s.S, exerciseView: v } }))
+
+beforeEach(() => {
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true
+ useUI.setState({ sheets: [], toastMsg: '' })
+ useStore.setState({ S: structuredClone(DEF), user: null })
+ document.body.innerHTML = ''
+})
+afterEach(() => { act(() => { mounted.splice(0).forEach(root => root.unmount()) }) })
+
+describe('exercise list or cards', () => {
+ it('Library: a list until the button beside the search turns the cards on, and back', () => {
+ const host = render(<Library />)
+ expect(isCards(host)).toBe(false)
+ expect(besideSearch(toggle(host))).toBe(true)
+ expect(toggle(host).closest('.hdr')).toBeNull()
+ expect(toggle(host).getAttribute('aria-pressed')).toBe('false')
+ act(() => toggle(host).click())
+ expect(view()).toBe('cards')
+ expect(isCards(host)).toBe(true)
+ expect(toggle(host).getAttribute('aria-pressed')).toBe('true')
+ act(() => toggle(host).click())
+ expect(view()).toBe('list')
+ expect(isCards(host)).toBe(false)
+ })
+
+ it('reads a profile saved before the setting existed as the list', () => {
+ useStore.setState(s => { const S = { ...s.S }; delete S.exerciseView; return { S } })
+ expect(isCards(render(<Library />))).toBe(false)
+ })
+
+ it('keeps "Create your own exercise" a full-width row above the cards', () => {
+ setView('cards')
+ const first = render(<Library />).querySelector('.list.ex-grid > .item')
+ expect(first.classList.contains('ex-new')).toBe(true)
+ })
+
+ it('picker: follows the same setting and switches it beside its own search, by muscle too', () => {
+ exercisePicker(vi.fn())
+ const host = renderTop()
+ expect(isCards(host)).toBe(false)
+ expect(besideSearch(toggle(host))).toBe(true)
+ act(() => toggle(host).click())
+ expect(view()).toBe('cards')
+ expect(isCards(host)).toBe(true)
+ act(() => [...host.querySelectorAll('button')].find(b => b.textContent === 'By muscle').click())
+ pickMuscle(host)
+ expect(isCards(host)).toBe(true)
+ expect(besideSearch(toggle(host))).toBe(true)
+ expect(toggle(host).getAttribute('aria-pressed')).toBe('true')
+ act(() => toggle(host).click())
+ expect(isCards(host)).toBe(false)
+ })
+
+ it('Muscles page: the results follow the setting, with the button beside their search', () => {
+ setView('cards')
+ const host = render(<Muscles />)
+ pickMuscle(host)
+ expect(isCards(host)).toBe(true)
+ expect(besideSearch(toggle(host))).toBe(true)
+ expect(toggle(host).closest('.hdr')).toBeNull()
+ })
+
+ // The desktop layout turns every #app list into two columns and forces every sheet list back
+ // into one column, both on an id selector — the grid has to win over each of them.
+ it('lays the cards out as a grid over the desktop two-column and the sheet column rules', () => {
+ const css = readFileSync(resolve(process.cwd(), 'src/index.css'), 'utf8')
+ const rule = css.match(/^([^{}\n]*\.list\.ex-grid[^{}\n]*)\{([^}]*)\}/m)
+ expect(rule?.[1]).toContain('#app .list.ex-grid')
+ expect(rule[1]).toContain('#modal-root .list.ex-grid')
+ expect(rule[2]).toContain('display:grid')
+ })
+})
diff --git a/frontend/src/index.css b/frontend/src/index.css
index f412a83b0..07735c572 100644
--- a/frontend/src/index.css
+++ b/frontend/src/index.css
@@ -547,6 +547,33 @@ h4.sec{
/* One long word (a German custom name) wraps instead of pushing the star off the screen. */
.exdetail-name{min-width:0;overflow-wrap:anywhere}
.fav-btn.on{color:var(--yellow)}
+/* Exercise cards (S.exerciseView 'cards', ExerciseViewToggle): the Library, the picker and the
+ muscle explorer as a grid of pictures with the name underneath — two across on a phone, more
+ as the page or sheet widens. The id-prefixed selectors outrank the desktop rules further down
+ that make every #app list two columns and every sheet list one. The catalogue pictures are
+ 180px, which is why a card stays near that size instead of filling a phone's width. */
+.list.ex-grid,#app .list.ex-grid,#modal-root .list.ex-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:10px}
+.ex-grid .item{position:relative;flex-direction:column;align-items:stretch;gap:8px;padding:8px}
+.ex-grid .item .thumb{width:100%;height:auto;aspect-ratio:1;border-radius:12px}
+.ex-grid .item .thumb-x{font-size:36px}
+.ex-grid .item .tt{font-size:15px}
+/* The badges ride on the picture's top corners and "+ Plan" spans the foot of the card. The
+ picker's "+" carries an inline padding/margin that widens its hit area in a row; on a card it
+ sits on the picture, so those give way here. */
+.ex-grid .item>.tag{position:absolute;top:14px;inset-inline-start:14px}
+.ex-grid .item:not(.ex-new)>.chev{position:absolute;top:14px;inset-inline-end:14px;width:32px;height:32px;margin:0 !important;padding:7px !important;border-radius:50%;background:var(--surface)}
+.ex-grid .item>.btn{width:100%}
+/* "Create your own exercise" stays a row across the top of the grid */
+.ex-grid .item.ex-new{grid-column:1/-1;flex-direction:row;align-items:center;gap:12px;padding:10px 12px}
+.ex-grid .item.ex-new .thumb{width:50px;height:50px;border-radius:9px}
+.ex-grid .item.ex-new .thumb-x{font-size:21px}
+/* The list/cards button (ExerciseViewToggle) at the end of the search field, as tall as it and
+ dressed like it; pressed while the cards are on. */
+.search-row{display:flex;gap:8px}
+.search-row>.search{flex:1;min-width:0}
+.search-row>.ex-view-btn{width:46px;height:auto;border-radius:10px;background:var(--surface-2);font-size:20px}
+:root[data-theme="light"] .search-row>.ex-view-btn{background:rgba(118,118,128,.12)}
+.search-row>.ex-view-btn.on,:root[data-theme="light"] .search-row>.ex-view-btn.on{background:var(--acc-soft);color:var(--acc)}
/* ---------------------------------------------------------------- chips -- */
.chips{
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx
index e5e4a6928..1d4f7b007 100644
--- a/frontend/src/sheets.jsx
+++ b/frontend/src/sheets.jsx
@@ -26,6 +26,7 @@ import { Button, Slider, Switch, Segmented, SelectRow, Row, TextField, NumberFie
import { glyphOf, GLYPH_GROUPS, DEFAULT_GLYPH } from './lib/glyphs.js'
import BodyMap from './components/BodyMap.jsx'
import MuscleExplorer from './components/MuscleExplorer.jsx'
+import ExerciseViewToggle from './components/ExerciseViewToggle.jsx'
import { exerciseMuscleSnapshot, loadOfWorkouts, MUSCLES, MUSCLE_NAME, muscleWeightsOf, normalizeMuscleGroups, hasExplicitMuscleMetadata, inMuscleOrder } from './lib/muscles.js'
import { parseImport, mergeImport } from './lib/import-csv.js'
import { importHevyData, HevyApiError, HEVY_DEV_SETTINGS, mergeHevyRoutines } from './lib/import-hevy.js'
@@ -1215,10 +1216,11 @@ function ExercisePicker({ onPick, title, close }) {
</div>
{/* .picker-search is what index.css keys the keyboard-aware sheet layout on: the sheet
lifts above the keys and the search stays put while the list scrolls under it. */}
- <div className="picker-search"><div className={'search' + (narrowed ? ' has-count' : '') + (q ? ' has-clear' : '')}><svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="7" /><path d="m21 21-4.3-4.3" /></svg>
+ <div className="picker-search"><div className="search-row"><div className={'search' + (narrowed ? ' has-count' : '') + (q ? ' has-clear' : '')}><svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="7" /><path d="m21 21-4.3-4.3" /></svg>
<input ref={searchRef} className="input" placeholder={t('Search {0} exercises…', all.length)} value={q} onFocus={onSearchFocus} onChange={e => { setQ(e.target.value); setShown(50) }} />
{narrowed && <span className="search-count" role="status" aria-label={exCount(f.length)}>{fmtNum(f.length)}</span>}
- {q && <button className="clear" onClick={() => { setQ(''); setShown(50) }} aria-label={t('Clear')}><Icon name="xmark" /></button>}</div></div>
+ {q && <button className="clear" onClick={() => { setQ(''); setShown(50) }} aria-label={t('Clear')}><Icon name="xmark" /></button>}</div>
+ <ExerciseViewToggle /></div></div>
{profile && <div className="small dim row" style={{ margin: '8px 0 2px', gap: 6, alignItems: 'center' }}>
<Icon name="kettlebell" style={{ fontSize: 13 }} />
{showAll ? t('Showing all equipment') : t('Showing what you have in "{0}"', profile.name)}
@@ -1240,8 +1242,8 @@ function ExercisePicker({ onPick, title, close }) {
<button className={'chip nocap' + (!eqOn ? ' on' : '')} onClick={() => { setEq(''); setShown(50) }}>{t('Any equipment')}</button>
{eqOpts.map(x => <button key={x} className={'chip' + (eqOn === x ? ' on' : '')} onClick={() => { setEq(x); setShown(50) }}>{t(x)}</button>)}
</div>}
- <div className="list">
- {!special && <div className="item" {...tappable(() => customExSheet(null, ex => onPick(ex), q.trim()))}>
+ <div className={'list' + (st.exerciseView === 'cards' ? ' ex-grid' : '')}>
+ {!special && <div className="item ex-new" {...tappable(() => customExSheet(null, ex => onPick(ex), q.trim()))}>
<div className="thumb thumb-x"><Icon name="plusCircle" /></div>
<div className="grow"><div className="tt">{t('Create your own exercise')}</div><div className="ss">{t('name + body part, and a photo or video if you like')}</div></div><Icon name="plus" className="chev" />
</div>}
diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.js
index 96842677b..637426a52 100644
--- a/frontend/src/store/useStore.js
+++ b/frontend/src/store/useStore.js
@@ -105,6 +105,10 @@ export const DEF = {
// 'cards' behaviour. beginWorkout copies the value onto s.active, so the header ⋮ menu can
// override it for the running session without touching this saved default.
workoutView: 'cards',
+ // How the Library, the exercise picker and the muscle explorer show exercises — 'list' (rows
+ // with a small thumbnail) or 'cards' (a grid of pictures with the name underneath). Switched
+ // by the button in those headers (ExerciseViewToggle); older profiles overlay onto the list.
+ exerciseView: 'list',
// Which controls the workout screen shows besides the sets themselves. The default is the
// lean layout: one "more" button per exercise and a menu on each set number. Every switch
// brings one of the old always-visible button groups back (Settings → During a workout).
diff --git a/frontend/src/views/Library.jsx b/frontend/src/views/Library.jsx
index e87150921..dd501d203 100644
--- a/frontend/src/views/Library.jsx
+++ b/frontend/src/views/Library.jsx
@@ -10,6 +10,7 @@ import { t, tn, exerciseNameFor, exerciseNameClass } from '../lib/i18n.js'
import { Thumb } from '../components/Media.jsx'
import { exerciseDetailSheet, addToRoutineSheet, customExSheet } from '../sheets.jsx'
import Icon from '../components/Icon.jsx'
+import ExerciseViewToggle from '../components/ExerciseViewToggle.jsx'
import { Button } from '../components/ui.jsx'
import { tappable, useRevealActiveChip } from '../lib/use-sheet-keyboard.js'
import { isFav, sortFavouritesFirst } from '../lib/favourites.js'
@@ -47,10 +48,11 @@ export default function Library() {
? tn('{1} animated exercises + 1 of your own', '{1} animated exercises + {0} of your own', ownCount, EXDB.length)
: t('{0} exercises with animations', EXDB.length)}</div>
</div>
- <div className={'search' + (narrowed ? ' has-count' : '') + (q ? ' has-clear' : '')} style={{ marginBottom: 10 }}><svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="7" /><path d="m21 21-4.3-4.3" /></svg>
+ <div className="search-row" style={{ marginBottom: 10 }}><div className={'search' + (narrowed ? ' has-count' : '') + (q ? ' has-clear' : '')}><svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="7" /><path d="m21 21-4.3-4.3" /></svg>
<input className="input" placeholder={t('Search…')} value={q} onChange={e => { setQ(e.target.value); setShown(40) }} />
{narrowed && <span className="search-count" role="status" aria-label={exCount(f.length)}>{fmtNum(f.length)}</span>}
{q && <button className="clear" onClick={() => { setQ(''); setShown(40) }} aria-label={t('Clear')}><Icon name="xmark" /></button>}</div>
+ <ExerciseViewToggle /></div>
{profile && <div className="small dim row" style={{ margin: '-4px 2px 10px', gap: 6, alignItems: 'center' }}>
<Icon name="kettlebell" style={{ fontSize: 13 }} />
{showAll ? t('Showing all equipment') : t('Showing what you have in "{0}"', profile.name)}
@@ -69,8 +71,8 @@ export default function Library() {
<button className={'chip nocap' + (!eqOn ? ' on' : '')} onClick={() => { setEq(''); setShown(40) }}>{t('Any equipment')}</button>
{eqOpts.map(x => <button key={x} className={'chip' + (eqOn === x ? ' on' : '')} onClick={() => { setEq(x); setShown(40) }}>{t(x)}</button>)}
</div>}
- <div className="list">
- <div className="item" {...tappable(() => customExSheet(null, ex => exerciseDetailSheet(ex), q.trim()))}>
+ <div className={'list' + (S.exerciseView === 'cards' ? ' ex-grid' : '')}>
+ <div className="item ex-new" {...tappable(() => customExSheet(null, ex => exerciseDetailSheet(ex), q.trim()))}>
<div className="thumb thumb-x"><Icon name="plusCircle" /></div>
<div className="grow"><div className="tt">{t('Create your own exercise')}</div><div className="ss">{t('name + body part, and a photo or video if you like')}</div></div><Icon name="plus" className="chev" />
</div>