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
Coach-Chat: Poll nach dem Anstossen neu takten, Kaltstart wartet auf den Store, Karten ohne Ueberlauf
Duarte Santos57a3a3f47802
diff --git a/frontend/src/coach.css b/frontend/src/coach.cssindex c08fdfe7a..5c6a2536c 100644--- a/frontend/src/coach.css+++ b/frontend/src/coach.css@@ -148,7 +148,7 @@.pcard-chg{display:flex;gap:12px;align-items:flex-start;padding:12px 18px;border-top:var(--hair) solid var(--sep)}.pcard-chg.stale{opacity:.5}.pcard-chg .grow{flex:1;min-width:0}-.pcard-chg-t{font-size:15px;font-weight:600;letter-spacing:-.01em;text-transform:capitalize}+.pcard-chg-t{font-size:15px;font-weight:600;letter-spacing:-.01em}.pcard-chg-v{display:flex;align-items:center;gap:6px;margin:4px 0;font-size:13px}.pcard-chg-v .tag{font-size:12px}.pcard-chg-w{font-size:13px;color:var(--label-2);line-height:1.42}@@ -195,23 +195,26 @@.chat-empty{font-size:14px;color:var(--label-2);line-height:1.45;padding:14px 4px}/* ---------- the numbers behind a card ---------- */-.ins{padding:6px 18px 4px;display:grid;gap:10px}-.ins-tiles{display:grid;grid-template-columns:repeat(4,1fr);gap:6px}+.ins{padding:6px 18px 4px;display:grid;gap:10px;min-width:0}+.ins>*{min-width:0}+.ins-tiles{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:6px}.ins-tile{background:var(--surface-2);border-radius:14px;padding:10px 6px 9px;text-align:center;min-width:0}.ins-tile-v{font-size:19px;font-weight:700;letter-spacing:-.03em;font-variant-numeric:tabular-nums;line-height:1.05;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}-.ins-tile-l{font-size:10.5px;color:var(--label-2);margin-top:4px;letter-spacing:-.004em;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}+.ins-tile-l{font-size:10.5px;color:var(--label-2);margin-top:4px;letter-spacing:-.004em;line-height:1.15;overflow-wrap:anywhere}.ins-block{background:var(--surface-2);border-radius:16px;padding:12px 14px 10px}-.ins-h{display:flex;justify-content:space-between;align-items:baseline;gap:8px;font-size:13px;font-weight:600;letter-spacing:-.008em;margin-bottom:6px}+.ins-h{display:flex;justify-content:space-between;align-items:baseline;gap:8px;font-size:13px;font-weight:600;letter-spacing:-.008em;margin-bottom:6px;min-width:0}+.ins-h>span:first-child{flex:none}+.ins-h>span:last-child{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:right}.ins-h .dim{font-weight:400;font-size:12px}.ins-block .chart{margin:2px -4px 0}-.ins-delta{font-size:12px;font-weight:600;font-variant-numeric:tabular-nums;color:var(--label-2);white-space:nowrap}+.ins-delta{font-size:12px;font-weight:600;font-variant-numeric:tabular-nums;color:var(--label-2);white-space:nowrap;flex:none}.ins-delta.up{color:var(--green)}.ins-delta.down{color:var(--red)}.ins-row{display:flex;align-items:center;gap:8px;padding:7px 0;border-top:var(--hair) solid var(--sep)}.ins-row:first-of-type{border-top:none}.ins-row-n{flex:1;min-width:0;font-size:14px;letter-spacing:-.008em;text-transform:capitalize;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ins-row-n .dim{font-size:12px;text-transform:none}-.ins-row-v{display:flex;align-items:center;gap:4px;font-size:12px}+.ins-row-v{display:flex;align-items:center;gap:4px;font-size:12px;flex:none}.ins-row-v .icn{font-size:11px;color:var(--label-3)}.ins-row-v .tag{font-size:12px;font-variant-numeric:tabular-nums}.ins-bar{display:grid;grid-template-columns:76px 1fr 28px;align-items:center;gap:8px;padding:4px 0}@@ -257,7 +260,7 @@.recap-t{font-size:17px;font-weight:600;letter-spacing:-.018em;margin-top:6px;line-height:1.2}.recap-s{font-size:13.5px;color:var(--label-2);line-height:1.42;margin-top:4px;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.recap-chips{display:flex;flex-wrap:wrap;gap:5px;margin-top:9px}-.recap-chip{display:inline-flex;align-items:center;gap:4px;font-size:12px;padding:4px 9px;border-radius:99px;background:var(--surface-2);color:var(--label-2);text-transform:capitalize;max-width:100%}+.recap-chip{display:inline-flex;align-items:center;gap:4px;font-size:12px;padding:4px 9px;border-radius:99px;background:var(--surface-2);color:var(--label-2);max-width:100%}.recap-chip .icn{font-size:11px;flex:none}.recap-chip.yes .icn{color:var(--green)}.recap-chip.no{text-decoration:line-through;opacity:.75}diff --git a/frontend/src/lib/coach-api.js b/frontend/src/lib/coach-api.jsindex dd3df5030..f4fd5c651 100644--- a/frontend/src/lib/coach-api.js+++ b/frontend/src/lib/coach-api.js@@ -80,11 +80,16 @@ export const disconnectCredential = () => api('/api/admin/coach/disconnect', { mexport function useCoachStatus(active = true) {const [state, setState] = useState({ job: null, pending: null, cap: null, loading: true })const timer = useRef(null)+ const loop = useRef(null) // the running poll loop's `tick`, so a manual refresh can re-pace itconst refresh = useCallback(async () => {try {const s = await coachStatus()setState({ ...s, loading: false })+ // A refresh that finds a job in flight — the one the caller just started — must not leave+ // the loop asleep on its idle cadence: without this the card shows up to a minute after+ // the job ended, sitting on "thinking…" the whole time.+ if (s?.job && loop.current) { clearTimeout(timer.current); timer.current = setTimeout(loop.current, POLL_MS) }return s} catch {setState(s => ({ ...s, loading: false }))@@ -98,10 +103,12 @@ export function useCoachStatus(active = true) {const tick = async () => {const s = await refresh()if (stopped) return+ clearTimeout(timer.current)timer.current = setTimeout(tick, s?.job ? POLL_MS : IDLE_MS)}+ loop.current = ticktick()- return () => { stopped = true; clearTimeout(timer.current) }+ return () => { stopped = true; loop.current = null; clearTimeout(timer.current) }}, [active, refresh])return { ...state, refresh }diff --git a/frontend/src/lib/coach.js b/frontend/src/lib/coach.jsindex 56a084888..f9e0e65f4 100644--- a/frontend/src/lib/coach.js+++ b/frontend/src/lib/coach.js@@ -14,7 +14,7 @@import { EXIDX } from './exercises.js'import { modeOf, isBw, isPerSide, cleanupSg } from './history.js'-import { uid, todayISO } from './format.js'+import { uid, todayISO, DAYN } from './format.js'import { mergePlan } from './plan-share.js'import { POLICIES } from './progression.js'import { t } from './i18n.js'@@ -568,14 +568,18 @@ export function recordDebrief(s, proposal) {/* ============================ display helpers ============================ */export const exName = id => EXIDX[id]?.n || t('Unknown exercise')+// Catalogue names are lower-case; a title reads better with each word capitalised, and doing it+// here rather than with CSS keeps a German sentence around the name from being Title Cased too.+const cap = s => String(s || '').replace(/(^|\s)(\p{L})/gu, (m, sp, ch) => sp + ch.toUpperCase())+export const exTitle = id => cap(exName(id))/** Human label for a change, used on the review screen and in the log. */-export function changeTitle(c) {- const ex = c.target?.exId ? exName(c.target.exId) : null+export function changeTitle(c, S) {+ const ex = c.target?.exId ? exTitle(c.target.exId) : nullswitch (c.type) {- case 'add-exercise': return t('Add {0}', exName(c.after?.id))+ case 'add-exercise': return t('Add {0}', exTitle(c.after?.id))case 'remove-exercise': return t('Drop {0}', ex)- case 'swap-exercise': return t('Swap {0} for {1}', ex, exName(c.after?.id))+ case 'swap-exercise': return t('Swap {0} for {1}', ex, exTitle(c.after?.id))case 'sets': return t('{0}: sets', ex)case 'reps': return t('{0}: reps', ex)case 'repsMin': return t('{0}: rep-range floor', ex)@@ -586,21 +590,23 @@ export function changeTitle(c) {case 'exercise-prog': return t('{0}: progression', ex)case 'routine-prog': return t('Routine progression')case 'reorder': return t('Reorder exercises')- case 'superset': return c.after?.link ? t('Superset {0} with {1}', ex, exName(c.after.with)) : t('Unlink superset on {0}', ex)+ case 'superset': return c.after?.link ? t('Superset {0} with {1}', ex, exTitle(c.after.with)) : t('Unlink superset on {0}', ex)case 'add-routine': return t('Add routine “{0}”', c.after?.name)case 'remove-routine': return t('Remove a routine')case 'rename-routine': return t('Rename routine to “{0}”', c.after)- case 'week': return t('Change what’s planned on one day')+ case 'week': return Number.isInteger(c.target?.weekday) ? t('{0}: what’s planned', t(DAYN[c.target.weekday])) : t('Change what’s planned on one day')default: return c.type}}/** Short before/after strings for the diff column. */-export function changeValues(c) {+export function changeValues(c, S) {+ const routineName = id => (S?.routines || []).find(r => r.id === id)?.name || idconst fmt = v => {- if (v == null) return '—'- if (typeof v === 'object') return v.id ? exName(v.id) : v.name || JSON.stringify(v)+ if (v == null) return c.type === 'week' ? t('Rest') : '—'+ if (typeof v === 'object') return v.id ? exTitle(v.id) : v.name || JSON.stringify(v)if (Array.isArray(v)) return v.length + ''+ if (c.type === 'week') return v === 'rest' ? t('Rest') : routineName(v)return String(v)}if (['add-exercise', 'add-routine', 'reorder'].includes(c.type)) return nulldiff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.jsindex b8e7d7478..836393dba 100644--- a/frontend/src/locales/de.js+++ b/frontend/src/locales/de.js@@ -1023,5 +1023,15 @@ export default {'Repeat the same loads and get every set.': 'Dieselben Gewichte wiederholen und jeden Satz schaffen.','Keep the session under an hour and a quarter.': 'Die Einheit unter eineinviertel Stunden halten.','A clean session: everything on the sheet got done and the loads held. This is exactly what progress looks like from the inside — unremarkable, repeated.': 'Eine saubere Einheit: alles auf dem Zettel wurde erledigt und die Gewichte haben gehalten. Genau so sieht Fortschritt von innen aus – unspektakulär, wiederholt.',- 'Most of the work got done. One or two sets fell short, which is fine once — it becomes a signal if the same sets miss next time.': 'Der Großteil der Arbeit ist erledigt. Ein oder zwei Sätze blieben kurz – einmal ist das in Ordnung; ein Signal wird es, wenn dieselben Sätze beim nächsten Mal wieder fehlen.'+ 'Most of the work got done. One or two sets fell short, which is fine once — it becomes a signal if the same sets miss next time.': 'Der Großteil der Arbeit ist erledigt. Ein oder zwei Sätze blieben kurz – einmal ist das in Ordnung; ein Signal wird es, wenn dieselben Sätze beim nächsten Mal wieder fehlen.',+ 'Get stronger': 'Stärker werden',+ 'Build muscle': 'Muskeln aufbauen',+ 'General fitness': 'Allgemeine Fitness',+ 'Lose fat': 'Fett verlieren',+ 'Endurance': 'Ausdauer',+ 'New to lifting': 'Neu im Krafttraining',+ 'Coming back after a break': 'Zurück nach einer Pause',+ 'Training regularly': 'Trainiere regelmäßig',+ 'Back muscles': 'Rücken',+ '{0}: what’s planned': '{0}: geplant',}diff --git a/frontend/src/views/CoachChat.jsx b/frontend/src/views/CoachChat.jsxindex 96c04bac0..079ebe2c3 100644--- a/frontend/src/views/CoachChat.jsx+++ b/frontend/src/views/CoachChat.jsx@@ -41,6 +41,7 @@ export default function CoachChat() {const config = useStore(s => s.config)const coachLocal = useStore(s => s.coachLocal)const update = useStore(s => s.update)+ const storeReady = useStore(s => s.ready)const toast = useUI(s => s.toast)const openSheet = useUI(s => s.openSheet)const { job, pending, cap, loading, lastError, last, refresh } = useCoachStatus(true)@@ -52,10 +53,13 @@ export default function CoachChat() {const ok = coachAvailable(config, user, { demo: DEMO, mobile: MOBILE, coachMode })const ready = ok && hasConsent(S) && !!S.coach?.profile+ // Not before the store has loaded: a cold start straight on #/coach would otherwise read an+ // empty state, decide there is no consent, and bounce a consenting user into the intake.useEffect(() => {+ if (!storeReady) returnif (!ok) nav('/home', { replace: true })else if (!ready) nav('/coach/intake', { replace: true })- }, [ok, ready])+ }, [storeReady, ok, ready])// A job that ends is either a proposal, "nothing to change", or a failure. The server tells// the client none of that directly — the job simply stops appearing — so the transition is@@ -399,7 +403,7 @@ function ReviewCard({ p, S, update, toast, refresh }) {{marked.changes.map(c => {const stale = c.status === 'stale'- return <ChangeRow key={c.id} c={c} stale={stale}>+ return <ChangeRow key={c.id} c={c} S={S} stale={stale}>{!stale && <Check checked={accepted.has(c.id)} onChange={() => toggle(c.id)} />}</ChangeRow>})}@@ -417,11 +421,11 @@ function ReviewCard({ p, S, update, toast, refresh }) {</div>}-function ChangeRow({ c, stale, badge, children }) {- const vals = changeValues(c)+function ChangeRow({ c, S, stale, badge, children }) {+ const vals = changeValues(c, S)return <div className={'pcard-chg' + (stale ? ' stale' : '') + (c.status === 'rejected' ? ' declined' : '')}><div className="grow">- <div className="pcard-chg-t">{changeTitle(c)}{c.routineName ? <span className="dim" style={{ fontWeight: 400 }}> · {c.routineName}</span> : null}</div>+ <div className="pcard-chg-t">{changeTitle(c, S)}{c.routineName ? <span className="dim" style={{ fontWeight: 400 }}> · {c.routineName}</span> : null}</div>{vals && <div className="pcard-chg-v"><span className="tag">{vals.before}</span><Icon name="chevronRight" style={{ fontSize: 12, color: 'var(--label-3)' }} /><span className="tag acc">{vals.after}</span></div>}<div className="pcard-chg-w">{c.why}</div>{stale && <div className="pcard-chg-stale">{t('Doesn’t match your plan any more — can’t be applied.')}</div>}@@ -437,7 +441,7 @@ const Notes = ({ notes }) => !!notes?.length && <div className="pcard-notes">/* ---------------------------------- insights ---------------------------------- */-const BP_LABEL = { back: 'Back', cardio: 'Cardio', chest: 'Chest', 'lower arms': 'Forearms', 'lower legs': 'Calves', neck: 'Neck', shoulders: 'Shoulders', 'upper arms': 'Arms', 'upper legs': 'Legs', waist: 'Core', other: 'Other' }+const BP_LABEL = { back: 'Back muscles', cardio: 'Cardio', chest: 'Chest', 'lower arms': 'Forearms', 'lower legs': 'Calves', neck: 'Neck', shoulders: 'Shoulders', 'upper arms': 'Arms', 'upper legs': 'Legs', waist: 'Core', other: 'Other' }const bpLabel = bp => t(BP_LABEL[bp] || bp)/**@@ -455,7 +459,7 @@ function Insights({ S, window: win, compact }) {<Tile v={ins.sessions} l={t('Sessions')} /><Tile v={ins.minutes != null ? ins.minutes : '—'} l={t('Min / session')} /><Tile v={ins.volume ? kfmt(ins.volume) : '—'} l={t('Volume ({0})', S.unit)} />- <Tile v={ins.sets} l={t('Work sets')} />+ <Tile v={ins.sets} l={t('Sets')} /></div>{bw.points.length > 1 && <div className="ins-block">@@ -503,7 +507,7 @@ function DebriefBody({ p, S }) {</div>}{live && <div className="ins"><div className="ins-tiles">- <Tile v={live.now.sets} l={t('Work sets')} />+ <Tile v={live.now.sets} l={t('Sets')} /><Tile v={live.now.minutes != null ? live.now.minutes : '—'} l={t('Minutes')} /><Tile v={live.now.volume ? kfmt(live.now.volume) : '—'} l={t('Volume ({0})', S.unit)} /><Tile v={live.now.prs || '—'} l={t('PRs')} />@@ -582,7 +586,7 @@ function Recap({ entry, S, openSheet }) {<div className="recap-t">{title}</div>{!!entry.summary && <div className="recap-s">{entry.summary}</div>}{kind === 'review' && !!decisions.length && <div className="recap-chips">- {decisions.slice(0, 4).map(d => <span key={d.id} className={'recap-chip ' + (d.status === 'accepted' ? 'yes' : 'no')}><Icon name={d.status === 'accepted' ? 'check' : 'xmark'} />{changeTitle(d)}</span>)}+ {decisions.slice(0, 4).map(d => <span key={d.id} className={'recap-chip ' + (d.status === 'accepted' ? 'yes' : 'no')}><Icon name={d.status === 'accepted' ? 'check' : 'xmark'} />{changeTitle(d, S)}</span>)}{decisions.length > 4 && <span className="recap-chip">+{decisions.length - 4}</span>}</div>}<div className="recap-more">{t('Show everything')}<Icon name="chevronRight" /></div>@@ -609,7 +613,7 @@ function ProposalDetail({ entry, S }) {{kind === 'review' && <><Insights S={S} window={entry.evidence} />- {(entry.decisions || []).map(d => <ChangeRow key={d.id} c={d} stale={d.status === 'stale'}+ {(entry.decisions || []).map(d => <ChangeRow key={d.id} c={d} S={S} stale={d.status === 'stale'}badge={<span className={'recap-state ' + (d.status === 'accepted' ? 'yes' : 'no')}>{d.status === 'accepted' ? t('Accepted') : d.status === 'stale' ? t('Expired') : t('Declined')}</span>} />)}<Notes notes={entry.notes} /></>}diff --git a/frontend/src/views/CoachChat.test.jsx b/frontend/src/views/CoachChat.test.jsxindex e6e87d9cd..ad88aeaee 100644--- a/frontend/src/views/CoachChat.test.jsx+++ b/frontend/src/views/CoachChat.test.jsx@@ -13,6 +13,7 @@ const mocks = vi.hoisted(() => {state.storeSnapshot = () => ({S: state.S,user: { id: 'u1' },+ ready: true,config: { coach: { enabled: true, ...(state.community ? { community: true } : {}) } },coachLocal: null,update: mut => mut(state.S),