diff --git a/frontend/src/components/Icon.jsx b/frontend/src/components/Icon.jsx index 9963d74..b270cd3 100644 --- a/frontend/src/components/Icon.jsx +++ b/frontend/src/components/Icon.jsx @@ -112,6 +112,7 @@ const P = { signOut: <>, shuffle: <>, info: <>, + warning: <>, } // A few keys are aliases so call sites can say what they mean. diff --git a/frontend/src/lib/equipment.js b/frontend/src/lib/equipment.js new file mode 100644 index 0000000..b2087b2 --- /dev/null +++ b/frontend/src/lib/equipment.js @@ -0,0 +1,34 @@ +import { t } from './i18n.js' +import { EXDB } from './exercises-data.js' + +// Every equipment value present in the catalogue, most common first — this becomes the +// checklist Settings shows when you build a profile. +export const ALL_EQUIPMENT = (() => { + const c = {} + EXDB.forEach(e => { if (e.eq) c[e.eq] = (c[e.eq] || 0) + 1 }) + return Object.keys(c).sort((a, b) => c[b] - c[a] || (a < b ? -1 : 1)) +})() + +// Body weight is never gated by a profile — no gym or home setup can take it away from you, +// and every profile should be able to see bodyweight exercises regardless of what's checked. +const ALWAYS_AVAILABLE = 'body weight' + +export function activeProfile(S) { + if (!S.equipFilterOn) return null + const profiles = S.equipProfiles || [] + return profiles.find(p => p.id === S.activeEquipId) || null +} + +// Whether an exercise is usable under the active profile. With filtering off, or no profile +// selected, everything is available — this is purely additive, never a trap that hides your +// whole library because you haven't set anything up yet. +export function exAvailable(S, ex) { + const p = activeProfile(S) + if (!p) return true + if (!ex.eq || ex.eq === ALWAYS_AVAILABLE) return true + return (p.equipment || []).includes(ex.eq) +} + +export function newProfile(name) { + return { id: 'eq' + Date.now().toString(36) + Math.random().toString(36).slice(2, 6), name, equipment: [] } +} diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx index d0f6d36..4d2c5ec 100644 --- a/frontend/src/sheets.jsx +++ b/frontend/src/sheets.jsx @@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react' import { useStore } from './store/useStore.js' import { useUI } from './store/useUI.js' import { EXDB, EXIDX, BODYPARTS, isCardio, isBodyweightEq, allExercises, equipmentOf, smOf } from './lib/exercises.js' +import { activeProfile, exAvailable, ALL_EQUIPMENT, newProfile } from './lib/equipment.js' import { fmtDate, fmtNum, fmtVol, fmtDur, durPart, todayISO, uid, exCount, DAYN, MONTHS_LONG, ACCENTS } from './lib/format.js' import { lastEntryFor, bestWeightFor, buildSets, effectiveRoutineId, workoutVolume, setsDone, setsDoneActive, lastBW, supersetUnits, unitOf, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, isBw, isPerSide, sideReps, workSetsDone } from './lib/history.js' import { beep, vibrate } from './lib/sound.js' @@ -11,7 +12,7 @@ import { starterRoutines } from './lib/starter.js' import Media, { Thumb } from './components/Media.jsx' import Stepper from './components/Stepper.jsx' import Icon from './components/Icon.jsx' -import { Button, Slider, Switch, Segmented, SelectRow, Row } from './components/ui.jsx' +import { Button, Slider, Switch, Segmented, SelectRow, Row, TextField } from './components/ui.jsx' import { glyphOf, GLYPH_GROUPS, DEFAULT_GLYPH } from './lib/glyphs.js' import BodyMap from './components/BodyMap.jsx' import { exerciseMuscleSnapshot, loadOfWorkouts } from './lib/muscles.js' @@ -421,22 +422,32 @@ function ExercisePicker({ onPick, close }) { const [q, setQ] = useState('') const [bp, setBp] = useState('') // '' = all, '★' = chosen, else a body part const [eq, setEq] = useState('') // '' = any equipment + const [showAll, setShowAll] = useState(false) const [shown, setShown] = useState(50) const ql = q.toLowerCase().trim() const all = allExercises(st) + const profile = activeProfile(st) let base = all.filter(e => (bp === '★' ? usage[e.id] : (!bp || e.bp === bp)) && (!ql || e.n.toLowerCase().includes(ql) || e.tg.includes(ql) || e.eq.includes(ql) || (e.desc || '').toLowerCase().includes(ql))) if (bp === '★') base = [...base].sort((a, b) => (usage[b.id] - usage[a.id]) || (a.n < b.n ? -1 : 1)) - const eqOpts = equipmentOf(base) + const eqFiltered = (profile && !showAll) ? base.filter(e => exAvailable(st, e)) : base + const eqOpts = equipmentOf(eqFiltered) // Drop the equipment filter if the search narrowed it away, so you never hit a dead end. const eqOn = eqOpts.includes(eq) ? eq : '' - const f = eqOn ? base.filter(e => e.eq === eqOn) : base + const f = eqOn ? eqFiltered.filter(e => e.eq === eqOn) : eqFiltered const chosenCount = Object.keys(usage).length return <>

{t('Add exercise')}

{ setQ(e.target.value); setShown(50) }} />
+ {profile &&
+ + {showAll ? t('Showing all equipment') : t('Showing what you have in "{0}"', profile.name)} + +
}
1 ? '10px 0 6px' : '10px 0' }}> {chosenCount > 0 && } @@ -462,6 +473,50 @@ function ExercisePicker({ onPick, close }) { } export const exercisePicker = onPick => ui().openSheet(close => ) +/* ============================ equipment profiles ============================ */ +// Create or edit one profile ("Home", "Gym", ...): a name plus a checklist of what you have. +function EquipmentProfileSheet({ profile, close }) { + const update = useStore(s => s.update) + const nameRef = useRef(null) + const [checked, setChecked] = useState(new Set(profile?.equipment || [])) + const toggle = k => setChecked(s => { const n = new Set(s); n.has(k) ? n.delete(k) : n.add(k); return n }) + const save = () => { + const name = (nameRef.current.value || '').trim() + if (!name) { return } + update(s => { + s.equipProfiles = s.equipProfiles || [] + const equipment = [...checked] + if (profile) { + const p = s.equipProfiles.find(x => x.id === profile.id) + if (p) { p.name = name; p.equipment = equipment } + } else { + const p = newProfile(name); p.equipment = equipment + s.equipProfiles.push(p) + if (!s.activeEquipId) s.activeEquipId = p.id + } + }) + close() + } + return <> +

{profile ? t('Edit profile') : t('New equipment profile')}

+
+ {t('Name it after where you train — e.g. "Home" or "Gym" — then check what you have there.')} +
+ +
+
+ {ALL_EQUIPMENT.map(k => ( + + ))} +
+
+ {t('Body-weight exercises are always available, in every profile.')} +
+
+ +} +export const equipmentProfileSheet = profile => ui().openSheet(close => ) + /* ============================ exercise config ============================ */ // Progression settings for one exercise (issue #17). Shown inside the config sheet because // "how does this lift go up" belongs next to sets and reps, not in a separate screen. Left diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.js index 6da600e..d49e6f0 100644 --- a/frontend/src/store/useStore.js +++ b/frontend/src/store/useStore.js @@ -16,7 +16,10 @@ export const DEF = { // that a profile which never chose (loaded state is overlaid on DEF, on every path: local, // server pull, backup import) still falls back to the `showRir` boolean this replaced and // keeps the column it had. See effortOf. - reminder: { on: false, time: '08:00', tz: null }, effort: null + reminder: { on: false, time: '08:00', tz: null }, effort: null, + // Equipment profiles (issue: filter Library/picker/routines by what you actually own — + // e.g. "Home" vs "Gym" — building on the session-only equipment filter from issue #6). + equipProfiles: [], activeEquipId: null, equipFilterOn: false, } const clone = o => JSON.parse(JSON.stringify(o)) diff --git a/frontend/src/views/Library.jsx b/frontend/src/views/Library.jsx index a3ba8cb..df04122 100644 --- a/frontend/src/views/Library.jsx +++ b/frontend/src/views/Library.jsx @@ -1,6 +1,7 @@ import { useState } from 'react' import { useStore } from '../store/useStore.js' import { EXDB, BODYPARTS, allExercises, equipmentOf } from '../lib/exercises.js' +import { activeProfile, exAvailable } from '../lib/equipment.js' import { bestWeightFor } from '../lib/history.js' import { fmtNum } from '../lib/format.js' import { t } from '../lib/i18n.js' @@ -14,18 +15,28 @@ export default function Library() { const [q, setQ] = useState('') const [bp, setBp] = useState('') const [eq, setEq] = useState('') + const [showAll, setShowAll] = useState(false) // ignore the active equipment profile for this session const [shown, setShown] = useState(40) const ql = q.toLowerCase().trim() + const profile = activeProfile(S) const base = allExercises(S).filter(e => (!bp || e.bp === bp) && (!ql || e.n.toLowerCase().includes(ql) || e.tg.includes(ql) || e.eq.includes(ql) || (e.desc || '').toLowerCase().includes(ql))) - const eqOpts = equipmentOf(base) + const eqFiltered = (profile && !showAll) ? base.filter(e => exAvailable(S, e)) : base + const eqOpts = equipmentOf(eqFiltered) // Drop the equipment filter if the search narrowed it away, so you never hit a dead end. const eqOn = eqOpts.includes(eq) ? eq : '' - const f = eqOn ? base.filter(e => e.eq === eqOn) : base + const f = eqOn ? eqFiltered.filter(e => e.eq === eqOn) : eqFiltered return <>

{t('Exercises')}

{t('{0} exercises with animations', EXDB.length)}
{ setQ(e.target.value); setShown(40) }} />
+ {profile &&
+ + {showAll ? t('Showing all equipment') : t('Showing what you have in "{0}"', profile.name)} + +
}
1 ? 8 : 12 }}> {BODYPARTS.map(b => )} @@ -53,3 +64,4 @@ export default function Library() { {f.length > shown && <>
} } + diff --git a/frontend/src/views/RoutineEdit.jsx b/frontend/src/views/RoutineEdit.jsx index d12adfb..0213de5 100644 --- a/frontend/src/views/RoutineEdit.jsx +++ b/frontend/src/views/RoutineEdit.jsx @@ -2,6 +2,7 @@ import { useNavigate, useParams } from 'react-router-dom' import { useEffect } from 'react' import { useStore } from '../store/useStore.js' import { exOr } from '../lib/exercises.js' +import { activeProfile, exAvailable } from '../lib/equipment.js' import { uid } from '../lib/format.js' import { t } from '../lib/i18n.js' import { supersetUnits, cleanupSg, exLine } from '../lib/history.js' @@ -36,6 +37,8 @@ export default function RoutineEdit() { const units = supersetUnits(r.ex) const unitFirst = new Set(units.filter(u => u.length > 1).map(u => u[0])) const inSS = new Set(units.filter(u => u.length > 1).flat()) + const profile = activeProfile(S) + const missingCount = profile ? r.ex.filter(e => !exAvailable(S, exOr(e.id))).length : 0 return
@@ -56,10 +59,18 @@ export default function RoutineEdit() { {t('Applies to every exercise in this routine that does not set its own rule.')}
+ {missingCount > 0 &&
+
+ +
{t('{0} of {1} exercises need equipment outside "{2}"', missingCount, r.ex.length, profile.name)}
+
+
} + {r.ex.length ?
{r.ex.map((e, i) => { // An unresolvable id is shown rather than skipped — hiding it left an entry you // could neither see nor delete, but that still turned up in the workout. const ex = exOr(e.id) + const noEquip = profile && !exAvailable(S, ex) const linkedPrev = i > 0 && e.sg && r.ex[i - 1].sg === e.sg return
{unitFirst.has(i) &&
{t('Superset')}
} @@ -68,6 +79,7 @@ export default function RoutineEdit() { }}>
{ex.n}
{exLine(e, S.unit)}
+ {noEquip && }
{i > 0 && }
diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsx index d6d071b..47b2395 100644 --- a/frontend/src/views/Settings.jsx +++ b/frontend/src/views/Settings.jsx @@ -10,7 +10,7 @@ import { wakeLockSupported } from '../lib/wakelock.js' import { t, LANGS, INSTR_LANGS } from '../lib/i18n.js' import { DEMO, REPO } from '../lib/demo.js' import { MOBILE, shareExport, syncReminder } from '../lib/mobile.js' -import { loadStarterPlan, confirmSheet, importFromApp } from '../sheets.jsx' +import { loadStarterPlan, confirmSheet, importFromApp, equipmentProfileSheet } from '../sheets.jsx' import Icon from '../components/Icon.jsx' import { Section, Row, SelectRow, Switch, Segmented, Button, TextField } from '../components/ui.jsx' @@ -142,6 +142,9 @@ export default function Settings() { {(user || MOBILE) && } + {/* ---------- equipment ---------- */} + + {/* ---------- appearance ---------- */}
@@ -328,6 +331,37 @@ function PushCard({ S, update, toast }) { } +// Equipment profiles ("Home", "Gym", ...) — each an id/name/eq-list; the active one filters +// the Library, exercise picker, and flags routine entries that need something outside it +// (see lib/equipment.js). Purely local/synced state — no server changes needed. +function EquipmentCard({ S, update }) { + const profiles = S.equipProfiles || [] + const remove = p => confirmSheet({ + title: t('Delete profile?'), message: t('"{0}" and its equipment list will be removed.', p.name), + confirmText: t('Delete'), danger: true, + onConfirm: () => update(s => { + s.equipProfiles = (s.equipProfiles || []).filter(x => x.id !== p.id) + if (s.activeEquipId === p.id) s.activeEquipId = (s.equipProfiles[0] && s.equipProfiles[0].id) || null + }), + }) + return
+ {profiles.length > 0 && + update(s => { s.equipFilterOn = v })} /> + } + {profiles.length > 0 && update(s => { s.activeEquipId = v })} + options={profiles.map(p => ({ value: p.id, label: p.name }))} />} + {profiles.map(p => ( + equipmentProfileSheet(p)}> + + + ))} + equipmentProfileSheet(null)} /> +
+} + // The same registration as the sign-in screen's, reached from Settings instead. It asks for // the invite code on the same terms: an invite-only instance rejects a registration without // one, so a form that cannot collect it is a form that cannot succeed.