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
feat(settings): an AI Coach row for admins in the hosted app
TheBlackSide243006407922f8c
diff --git a/docs/AI_COACH.md b/docs/AI_COACH.mdindex cdc9bdcb0..e724159c0 100644--- a/docs/AI_COACH.md+++ b/docs/AI_COACH.md@@ -68,7 +68,8 @@ own (see [On the phone](#on-the-phone)).The entry appears only when all of these hold:- **The master switch is on.** That is **Set up the Coach** on the admin card- (**Settings → Account → Admin dashboard**, the **AI Coach** card), and afterwards the toggle at the top+ (**Settings → Account → Admin dashboard**, the **AI Coach** card; an admin also finds it as+ **Settings → AI Coach**), and afterwards the toggle at the topof the same card. A provider that is connected and passes **Test the Coach** is not enoughon its own: with the switch off, the server tells every app there is no Coach, and the cardreads *Off right now — nobody sees it anywhere in the app*.diff --git a/frontend/src/locales/ar.js b/frontend/src/locales/ar.jsindex 2f3e3c60b..18b83259b 100644--- a/frontend/src/locales/ar.js+++ b/frontend/src/locales/ar.js@@ -2578,4 +2578,5 @@ export default {"Gain {0} to {1} a week.": "زيادة {0} إلى {1} أسبوعيًا.","A cut is often 0.5 to 1 % a week, a lean bulk 0.25 to 0.5 %.": "التنشيف غالبًا 0.5 إلى 1 % أسبوعيًا، والتضخيم النظيف 0.25 إلى 0.5 %.","Remove range": "إزالة النطاق",+ 'Admin': 'المشرف',}diff --git a/frontend/src/locales/bn.js b/frontend/src/locales/bn.jsindex 98e9edaf7..b2e61da08 100644--- a/frontend/src/locales/bn.js+++ b/frontend/src/locales/bn.js@@ -2602,4 +2602,5 @@ export default {"Gain {0} to {1} a week.": "সপ্তাহে {0} থেকে {1} বাড়ানো।","A cut is often 0.5 to 1 % a week, a lean bulk 0.25 to 0.5 %.": "কাটিং সাধারণত সপ্তাহে ০.৫ থেকে ১ %, লিন বাল্ক ০.২৫ থেকে ০.৫ %।","Remove range": "সীমা সরান",+ 'Admin': 'অ্যাডমিন',}diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.jsindex fceda1721..9a644c0a6 100644--- a/frontend/src/locales/de.js+++ b/frontend/src/locales/de.js@@ -2543,4 +2543,5 @@ export default {"Gain {0} to {1} a week.": "{0} bis {1} pro Woche zunehmen.","A cut is often 0.5 to 1 % a week, a lean bulk 0.25 to 0.5 %.": "Eine Diät liegt oft bei 0,5 bis 1 % pro Woche, ein sauberer Aufbau bei 0,25 bis 0,5 %.","Remove range": "Bereich entfernen",+ 'Admin': 'Admin',}diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.jsindex 708215e26..c8668f164 100644--- a/frontend/src/locales/es.js+++ b/frontend/src/locales/es.js@@ -2523,4 +2523,5 @@ export default {"Gain {0} to {1} a week.": "Subir de {0} a {1} por semana.","A cut is often 0.5 to 1 % a week, a lean bulk 0.25 to 0.5 %.": "Una definición suele ir de 0,5 a 1 % por semana, un volumen limpio de 0,25 a 0,5 %.","Remove range": "Quitar rango",+ 'Admin': 'Admin',}diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.jsindex 3be95ba26..c28134d54 100644--- a/frontend/src/locales/fr.js+++ b/frontend/src/locales/fr.js@@ -2523,4 +2523,5 @@ export default {"Gain {0} to {1} a week.": "Prendre de {0} à {1} par semaine.","A cut is often 0.5 to 1 % a week, a lean bulk 0.25 to 0.5 %.": "Une sèche, c’est souvent 0,5 à 1 % par semaine, une prise de masse propre 0,25 à 0,5 %.","Remove range": "Retirer la fourchette",+ 'Admin': 'Admin',}diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.jsindex b1eda0456..9b190d7f1 100644--- a/frontend/src/locales/hi.js+++ b/frontend/src/locales/hi.js@@ -2523,4 +2523,5 @@ export default {"Gain {0} to {1} a week.": "हर हफ़्ते {0} से {1} बढ़ाना।","A cut is often 0.5 to 1 % a week, a lean bulk 0.25 to 0.5 %.": "कटिंग अक्सर हर हफ़्ते 0.5 से 1 % होती है, लीन बल्क 0.25 से 0.5 %।","Remove range": "सीमा हटाएँ",+ 'Admin': 'एडमिन',}diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.jsindex c5e4a9d0d..5f484166a 100644--- a/frontend/src/locales/hu.js+++ b/frontend/src/locales/hu.js@@ -2526,4 +2526,5 @@ export default {"Gain {0} to {1} a week.": "Heti {0}–{1} hízás.","A cut is often 0.5 to 1 % a week, a lean bulk 0.25 to 0.5 %.": "Szálkásításnál gyakran heti 0,5–1 %, tiszta tömegnövelésnél 0,25–0,5 %.","Remove range": "Tartomány törlése",+ 'Admin': 'Admin',}diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.jsindex 003332d16..a606ef55a 100644--- a/frontend/src/locales/it.js+++ b/frontend/src/locales/it.js@@ -2523,4 +2523,5 @@ export default {"Gain {0} to {1} a week.": "Aumentare da {0} a {1} a settimana.","A cut is often 0.5 to 1 % a week, a lean bulk 0.25 to 0.5 %.": "Una definizione è spesso 0,5-1 % a settimana, una massa pulita 0,25-0,5 %.","Remove range": "Rimuovi intervallo",+ 'Admin': 'Admin',}diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.jsindex e54f6b3f1..ce8d6c8e8 100644--- a/frontend/src/locales/ko.js+++ b/frontend/src/locales/ko.js@@ -2523,4 +2523,5 @@ export default {"Gain {0} to {1} a week.": "주당 {0}~{1} 증량.","A cut is often 0.5 to 1 % a week, a lean bulk 0.25 to 0.5 %.": "감량기는 보통 주당 0.5~1 %, 린 벌크는 0.25~0.5 % 정도예요.","Remove range": "범위 삭제",+ 'Admin': '관리자',}diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.jsindex e368429dc..0fd87d5e5 100644--- a/frontend/src/locales/pl.js+++ b/frontend/src/locales/pl.js@@ -2523,4 +2523,5 @@ export default {"Gain {0} to {1} a week.": "Przybierać od {0} do {1} tygodniowo.","A cut is often 0.5 to 1 % a week, a lean bulk 0.25 to 0.5 %.": "Redukcja to często 0,5 do 1 % tygodniowo, czysta masa 0,25 do 0,5 %.","Remove range": "Usuń zakres",+ 'Admin': 'Admin',}diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.jsindex 6367f2fe6..73c34b22a 100644--- a/frontend/src/locales/pt-BR.js+++ b/frontend/src/locales/pt-BR.js@@ -1627,6 +1627,8 @@ export const PT_BR_OVERRIDES = {"Gain {0} to {1} a week.": "Ganhar de {0} a {1} por semana.","A cut is often 0.5 to 1 % a week, a lean bulk 0.25 to 0.5 %.": "Um cutting costuma ficar em 0,5 a 1 % por semana, um bulking limpo em 0,25 a 0,5 %.","Remove range": "Remover faixa",++ 'Admin': 'Admin',}export default { ...pt, ...PT_BR_OVERRIDES }diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.jsindex 5cef1da50..2dabc1249 100644--- a/frontend/src/locales/pt.js+++ b/frontend/src/locales/pt.js@@ -2523,4 +2523,5 @@ export default {"Gain {0} to {1} a week.": "Ganhar de {0} a {1} por semana.","A cut is often 0.5 to 1 % a week, a lean bulk 0.25 to 0.5 %.": "Uma fase de definição anda muitas vezes nos 0,5 a 1 % por semana, um bulk limpo nos 0,25 a 0,5 %.","Remove range": "Remover intervalo",+ 'Admin': 'Admin',}diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.jsindex 20a2b1398..b1952e201 100644--- a/frontend/src/locales/ru.js+++ b/frontend/src/locales/ru.js@@ -2527,4 +2527,5 @@ export default {"Gain {0} to {1} a week.": "Набирать от {0} до {1} в неделю.","A cut is often 0.5 to 1 % a week, a lean bulk 0.25 to 0.5 %.": "Сушка обычно идёт по 0,5–1 % в неделю, чистый набор по 0,25–0,5 %.","Remove range": "Убрать диапазон",+ 'Admin': 'Админ',}diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.jsindex 47d61395b..468d1545d 100644--- a/frontend/src/locales/th.js+++ b/frontend/src/locales/th.js@@ -2534,4 +2534,5 @@ export default {"Gain {0} to {1} a week.": "เพิ่ม {0} ถึง {1} ต่อสัปดาห์","A cut is often 0.5 to 1 % a week, a lean bulk 0.25 to 0.5 %.": "ช่วงลดไขมันมักอยู่ที่ 0.5 ถึง 1 % ต่อสัปดาห์ ช่วงเพิ่มกล้ามแบบลีนอยู่ที่ 0.25 ถึง 0.5 %","Remove range": "ลบช่วง",+ 'Admin': 'ผู้ดูแล',}diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.jsindex 4f0f9649e..492144e52 100644--- a/frontend/src/locales/tr.js+++ b/frontend/src/locales/tr.js@@ -2523,4 +2523,5 @@ export default {"Gain {0} to {1} a week.": "Haftada {0} ile {1} arası al.","A cut is often 0.5 to 1 % a week, a lean bulk 0.25 to 0.5 %.": "Yağ yakımı genelde haftada %0,5 ile %1, temiz bulk %0,25 ile %0,5 arasıdır.","Remove range": "Aralığı kaldır",+ 'Admin': 'Yönetici',}diff --git a/frontend/src/locales/uk.js b/frontend/src/locales/uk.jsindex ef8c41314..86039b6f4 100644--- a/frontend/src/locales/uk.js+++ b/frontend/src/locales/uk.js@@ -2520,4 +2520,5 @@ export default {"Gain {0} to {1} a week.": "Набирати {0}–{1} на тиждень.","A cut is often 0.5 to 1 % a week, a lean bulk 0.25 to 0.5 %.": "Сушка часто йде по 0,5–1 % на тиждень, чистий набір по 0,25–0,5 %.","Remove range": "Прибрати діапазон",+ 'Admin': 'Адмін',}diff --git a/frontend/src/locales/zh-TW.js b/frontend/src/locales/zh-TW.jsindex b36e68e3d..1499efc1b 100644--- a/frontend/src/locales/zh-TW.js+++ b/frontend/src/locales/zh-TW.js@@ -2516,4 +2516,5 @@ export default {"Gain {0} to {1} a week.": "每週增 {0} 到 {1}。","A cut is often 0.5 to 1 % a week, a lean bulk 0.25 to 0.5 %.": "減脂期通常每週 0.5 到 1 %,乾淨增肌每週 0.25 到 0.5 %。","Remove range": "移除範圍",+ 'Admin': '管理員',}diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.jsindex 73a57da57..05818a188 100644--- a/frontend/src/locales/zh.js+++ b/frontend/src/locales/zh.js@@ -2523,4 +2523,5 @@ export default {"Gain {0} to {1} a week.": "每周增 {0} 到 {1}。","A cut is often 0.5 to 1 % a week, a lean bulk 0.25 to 0.5 %.": "减脂期通常每周 0.5 到 1 %,干净增肌每周 0.25 到 0.5 %。","Remove range": "移除范围",+ 'Admin': '管理员',}diff --git a/frontend/src/views/Admin.jsx b/frontend/src/views/Admin.jsxindex caf66c80a..ca0b42fbd 100644--- a/frontend/src/views/Admin.jsx+++ b/frontend/src/views/Admin.jsx@@ -1,5 +1,5 @@-import { useEffect, useState } from 'react'-import { useNavigate } from 'react-router-dom'+import { useEffect, useRef, useState } from 'react'+import { useLocation, useNavigate } from 'react-router-dom'import { useStore } from '../store/useStore.js'import { useUI } from '../store/useUI.js'import { api } from '../lib/api.js'@@ -310,6 +310,15 @@ function AuditCard({ tick, owner }) {export default function Admin() {const nav = useNavigate()+ // Opened from Settings → AI Coach (the hosted app's way to the Coach, which is the server's):+ // straight to the Coach card rather than the top of the page.+ const toCoach = useLocation().state?.section === 'coach'+ const coachRef = useRef(null)+ useEffect(() => {+ if (!toCoach) return+ const tm = setTimeout(() => coachRef.current?.scrollIntoView({ block: 'start' }), 50)+ return () => clearTimeout(tm)+ }, [toCoach])const user = useStore(s => s.user)const openSheet = useUI(s => s.openSheet)const [users, setUsers] = useState(null)@@ -378,7 +387,7 @@ export default function Admin() {{/* The Coach setup. Renders nothing at all unless the instance offers the Coach, so an adminpage on a box that never enabled it is byte-for-byte the page it was before. */}- <AdminCoach />+ <div ref={coachRef} className="adm-coach-anchor"><AdminCoach /></div><InvitesCard invites={invites} reload={loadInvites} inviteOnly={inviteOnly} />diff --git a/frontend/src/views/Admin.password.test.jsx b/frontend/src/views/Admin.password.test.jsxindex 42b1a33b0..13732aa85 100644--- a/frontend/src/views/Admin.password.test.jsx+++ b/frontend/src/views/Admin.password.test.jsx@@ -30,7 +30,7 @@ vi.mock('../store/useUI.js', () => {useUI.getState = snapreturn { useUI }})-vi.mock('react-router-dom', () => ({ useNavigate: () => () => {} }))+vi.mock('react-router-dom', () => ({ useNavigate: () => () => {}, useLocation: () => ({ state: null }) }))vi.mock('../sheets.jsx', () => ({ confirmSheet: (...a) => mocks.confirm(...a) }))vi.mock('./AdminCoach.jsx', () => ({ default: () => null }))diff --git a/frontend/src/views/Admin.test.jsx b/frontend/src/views/Admin.test.jsxindex cad12e039..dbf55f42c 100644--- a/frontend/src/views/Admin.test.jsx+++ b/frontend/src/views/Admin.test.jsx@@ -28,7 +28,7 @@ vi.mock('../store/useUI.js', () => {useUI.getState = snapreturn { useUI }})-vi.mock('react-router-dom', () => ({ useNavigate: () => () => {} }))+vi.mock('react-router-dom', () => ({ useNavigate: () => () => {}, useLocation: () => ({ state: null }) }))vi.mock('../sheets.jsx', () => ({ confirmSheet: vi.fn() }))vi.mock('./AdminCoach.jsx', () => ({ default: () => null }))diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsxindex a3cf8c2ac..180cd5317 100644--- a/frontend/src/views/Settings.jsx+++ b/frontend/src/views/Settings.jsx@@ -1061,6 +1061,8 @@ function SettingsRoot({ ctx, preview, open, user, sync, home, go, entryKey }) {: MOBILE ? { title: t('This phone'), sub: t('All data stays on this phone') }: { title: t('Guest'), sub: t('Your data lives on this device. Sign in to sync.') }const initial = user && !DEMO ? String(user.name || '?').trim().charAt(0).toUpperCase() : null+ const nav = useNavigate()+ const adminCoach = !MOBILE && !DEMO && !!user?.adminreturn <div className="narrow"><div className="sp-nav"><button className="sp-back" data-back="/home" onClick={home} aria-label={t('Home')}><Icon name="chevronLeft" /><span>{t('Home')}</span></button>@@ -1086,6 +1088,11 @@ function SettingsRoot({ ctx, preview, open, user, sync, home, go, entryKey }) {<Section key={g[0]}>{g.map(id => <Row key={id} icon={PAGES[id].icon} iconTint={PAGES[id].tint} title={t(PAGES[id].title)}value={preview[id]?.() || null} accessory="chevron" onClick={() => open(id)} className="sp-root-row" />)}+ {/* The phone app sets up its own Coach on the Coach page beside Look; in a hosted app the+ Coach is the server's, set up by an admin on the admin dashboard. Its admins get the+ same row, in the same place, straight to that card; nobody else has anything to set. */}+ {g[0] === 'look' && adminCoach && <Row icon={PAGES.coach.icon} iconTint={PAGES.coach.tint} title={t(PAGES.coach.title)}+ value={t('Admin')} accessory="chevron" onClick={() => nav('/admin', { state: { section: 'coach' } })} className="sp-root-row" />}</Section>))}<div className="dim small sp-version">openGym v{__APP_VERSION__}</div>diff --git a/frontend/src/views/settings-pages.test.jsx b/frontend/src/views/settings-pages.test.jsxindex d7adb6f67..863d90bbe 100644--- a/frontend/src/views/settings-pages.test.jsx+++ b/frontend/src/views/settings-pages.test.jsx@@ -149,6 +149,17 @@ describe('the root', () => {expect(mocks.navs).toEqual([['/settings/alerts'], ['/coach/setup'], ['/settings/account']])})+ it('in a hosted app, an admin gets the Coach row too, straight to the Coach card of the admin dashboard', () => {+ mocks.user = { id: 'u1', name: 'Dana' }+ mount()+ expect(titles()).not.toContain('AI Coach')+ mocks.user = { id: 'u1', name: 'Dana', admin: true }+ mount()+ expect(rowTitled('AI Coach').textContent).toContain('Admin')+ act(() => rowTitled('AI Coach').click())+ expect(mocks.navs).toEqual([['/admin', { state: { section: 'coach' } }]])+ })+it('searches every setting and a hit goes to its page with the row to flash', () => {mount()const input = host.querySelector('.sp-search input')