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
Workout settings sheet: rest timer on the wheel, sound, vibrate, flash, screen awake, layout, effort and animations without leaving the workout
Duarte Santos313c33472c0f
diff --git a/frontend/src/components/WorkoutSettingsSheet.jsx b/frontend/src/components/WorkoutSettingsSheet.jsxnew file mode 100644index 000000000..6bb40e55b--- /dev/null+++ b/frontend/src/components/WorkoutSettingsSheet.jsx@@ -0,0 +1,83 @@+import { useStore } from '../store/useStore.js'+import { useUI } from '../store/useUI.js'+import { t } from '../lib/i18n.js'+import { effortOf } from '../lib/history.js'+import { unlock, vibrateSupported, appleTouchDevice } from '../lib/sound.js'+import { wakeLockSupported } from '../lib/wakelock.js'+import { MOBILE } from '../lib/mobile.js'+import { nav } from '../lib/nav.js'+import { REST_MAX, fmtRest } from '../lib/duration.js'+import { durationSheet } from './DurationWheel.jsx'+import { Section, Row, Switch, Segmented, Button } from './ui.jsx'++// The settings people touch at the gym, without leaving the workout (v1.3.11, opened from the+// workout's ⋯ → Workout settings). Every row writes the same S.* field as Settings → Workout and+// Settings → Timer alerts, so a change here sticks for the next session too; nothing in it is+// for this session only. The one exception to "same as Settings" is Layout: the running session+// may carry its own layout from the ⋯ menu (S.active.workoutView), and choosing one here clears+// that, or the saved choice would not show until the next workout.+export function WorkoutSettings({ close }) {+ const S = useStore(s => s.S)+ const update = useStore(s => s.update)+ const canVibrate = vibrateSupported()+ const iPhone = appleTouchDevice()+ const wakeOK = wakeLockSupported()+ const layout = ['list', 'compact'].includes(S.active?.workoutView || S.workoutView) ? (S.active?.workoutView || S.workoutView) : 'cards'+ const gif = S.gifSize === 'mini' || S.gifSize === 'off' ? S.gifSize : 'full'+ const allSettings = () => { close(); nav('/settings/workout') }+ return <div className="ws-sheet">+ <div className="row between" style={{ marginBottom: 2 }}>+ <h3 style={{ margin: 0 }}>{t('Workout settings')}</h3>+ <Button size="sm" variant="ghost" onClick={close}>{t('Done')}</Button>+ </div>+ <div className="muted small" style={{ marginBottom: 12 }}>{t('Changes stick for your next workouts too.')}</div>+ <Section>+ <Row icon="timer" iconTint="var(--orange)" title={t('Rest timer')} value={fmtRest(S.restSec)} accessory="chevron"+ onClick={() => durationSheet({+ title: t('Rest timer'), value: S.restSec, max: REST_MAX, off: t('Off'),+ footer: t('Scroll to 0:00 to turn the rest timer off.'),+ onDone: v => update(s => { s.restSec = v }),+ })} />+ <Row icon="speaker" iconTint="var(--pink)" title={t('Play a sound')}>+ {/* A tap: unlock the audio now so a rest ending before the next tick can sound (iOS, #152). */}+ <Switch checked={!!S.sound} onChange={v => { if (v) unlock(true); update(s => { s.sound = v }) }} />+ </Row>+ <Row icon="vibrate" iconTint="var(--indigo)" title={t('Vibrate')} className={canVibrate ? '' : 'dis'}+ subtitle={canVibrate ? null : iPhone ? t('Not on iPhone') : t('Not supported in this browser.')}>+ <Switch checked={canVibrate && S.vibrate !== false} disabled={!canVibrate} onChange={v => update(s => { s.vibrate = v })} />+ </Row>+ <Row icon="sun" iconTint="var(--yellow)" title={t('Flash the screen')}>+ <Switch checked={!!S.timerFlash} onChange={v => update(s => { s.timerFlash = v })} />+ </Row>+ {(wakeOK || !MOBILE) && <Row icon="phoneScreen" iconTint="var(--yellow)" title={t('Keep screen awake')}+ subtitle={wakeOK ? null : t('Not supported in this browser.')}>+ <Switch checked={wakeOK && S.keepAwake !== false} disabled={!wakeOK} onChange={v => update(s => { s.keepAwake = v })} />+ </Row>}+ </Section>+ <Section>+ <Row icon="layout" iconTint="var(--blue)" title={t('Layout')}>+ <Segmented className="seg-inline"+ options={[{ value: 'cards', label: t('Cards') }, { value: 'list', label: t('List') }, { value: 'compact', label: t('Compact') }]}+ value={layout} onChange={v => update(s => { s.workoutView = v; if (s.active) delete s.active.workoutView })} />+ </Row>+ <Row icon="gauge" iconTint="var(--purple)" title={t('Effort per set')}>+ <Segmented className="seg-inline"+ options={[{ value: 'none', label: t('Off') }, { value: 'rir', label: t('RIR') }, { value: 'rpe', label: t('RPE') }]}+ value={effortOf(S)} onChange={v => update(s => { s.effort = v; delete s.showRir })} />+ </Row>+ <Row icon="image" iconTint="var(--teal)" title={t('Exercise animations')}>+ <Segmented className="seg-inline"+ options={[{ value: 'full', label: t('Full') }, { value: 'mini', label: t('Small') }, { value: 'off', label: t('Hidden') }]}+ value={gif} onChange={v => update(s => { s.gifSize = v })} />+ </Row>+ </Section>+ <Section>+ <Row icon="gear" iconTint="var(--grey)" title={t('All settings')} accessory="chevron" onClick={allSettings} />+ </Section>+ </div>+}++/** Opens the in-workout settings sheet. */+export function workoutSettingsSheet() {+ return useUI.getState().openSheet(close => <WorkoutSettings close={close} />)+}diff --git a/frontend/src/components/WorkoutSettingsSheet.test.jsx b/frontend/src/components/WorkoutSettingsSheet.test.jsxnew file mode 100644index 000000000..3d326be5d--- /dev/null+++ b/frontend/src/components/WorkoutSettingsSheet.test.jsx@@ -0,0 +1,102 @@+// @vitest-environment happy-dom+import React, { act } from 'react'+import { createRoot } from 'react-dom/client'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { WorkoutSettings } from './WorkoutSettingsSheet.jsx'+import { useUI } from '../store/useUI.js'+import { useStore } from '../store/useStore.js'++globalThis.IS_REACT_ACT_ENVIRONMENT = true++const sound = vi.hoisted(() => ({ canVibrate: true, iPhone: false }))+vi.mock('../lib/sound.js', () => ({+ unlock: vi.fn(), beep: vi.fn(), chime: vi.fn(), vibrate: vi.fn(), alertBuzz: vi.fn(),+ vibrateSupported: () => sound.canVibrate, appleTouchDevice: () => sound.iPhone,+}))+vi.mock('../lib/wakelock.js', () => ({ wakeLockSupported: () => true }))+const navTo = vi.hoisted(() => vi.fn())+vi.mock('../lib/nav.js', () => ({ nav: navTo }))++let host, root, originalS, close++beforeEach(() => {+ originalS = useStore.getState().S+ useStore.setState({ S: {+ ...originalS, restSec: 90, sound: false, vibrate: true, timerFlash: false, keepAwake: true,+ workoutView: 'cards', effort: 'none', gifSize: 'full',+ active: { id: 'a', name: 'Push', start: Date.now(), cur: 0, entries: [], workoutView: 'list' },+ } })+ useUI.setState({ sheets: [] })+ sound.canVibrate = true; sound.iPhone = false+ close = vi.fn()+ host = document.createElement('div')+ document.body.appendChild(host)+ root = createRoot(host)+ act(() => root.render(<WorkoutSettings close={close} />))+})++afterEach(() => {+ act(() => root.render(null))+ useUI.setState({ sheets: [] })+ useStore.setState({ S: originalS })+ host.remove()+ navTo.mockReset()+})++const row = title => [...host.querySelectorAll('.lrow')].find(r => r.querySelector('.lrow-t')?.textContent === title)+const S = () => useStore.getState().S++describe('the in-workout settings sheet', () => {+ it('has the rows people change at the gym, then All settings', () => {+ expect([...host.querySelectorAll('.lrow-t')].map(e => e.textContent)).toEqual([+ 'Rest timer', 'Play a sound', 'Vibrate', 'Flash the screen', 'Keep screen awake',+ 'Layout', 'Effort per set', 'Exercise animations', 'All settings',+ ])+ expect(row('Rest timer').querySelector('.lrow-v').textContent).toBe('1:30')+ })++ it('writes the same fields as Settings', () => {+ act(() => row('Play a sound').querySelector('[role=switch]').click())+ act(() => row('Vibrate').querySelector('[role=switch]').click())+ act(() => row('Flash the screen').querySelector('[role=switch]').click())+ act(() => row('Keep screen awake').querySelector('[role=switch]').click())+ act(() => [...row('Effort per set').querySelectorAll('button')].find(b => b.textContent === 'RIR').click())+ act(() => [...row('Exercise animations').querySelectorAll('button')].find(b => b.textContent === 'Small').click())+ expect(S()).toMatchObject({ sound: true, vibrate: false, timerFlash: true, keepAwake: false, effort: 'rir', gifSize: 'mini' })+ })++ it('shows this session’s layout, and a pick here is saved and replaces it', () => {+ expect(row('Layout').querySelector('button.on').textContent).toBe('List')+ act(() => [...row('Layout').querySelectorAll('button')].find(b => b.textContent === 'Compact').click())+ expect(S().workoutView).toBe('compact')+ expect(S().active.workoutView).toBeUndefined()+ })++ it('sets the rest timer on the wheel, 0:00 being off', () => {+ act(() => row('Rest timer').click())+ const sheet = useUI.getState().sheets.at(-1)+ const el = document.createElement('div')+ document.body.appendChild(el)+ const r = createRoot(el)+ act(() => r.render(sheet.render(() => useUI.getState().closeSheet(sheet.id))))+ expect(el.querySelector('h3').textContent).toBe('Rest timer')+ expect(el.querySelector('.dw-read').textContent).toBe('1:30')+ act(() => [...el.querySelectorAll('button')].find(b => b.textContent === 'Done').click())+ expect(S().restSec).toBe(90)+ act(() => r.unmount()); el.remove()+ })++ it('greys Vibrate out on an iPhone and says why', () => {+ sound.canVibrate = false; sound.iPhone = true+ act(() => root.render(<WorkoutSettings close={close} key="iphone" />))+ expect(row('Vibrate').classList.contains('dis')).toBe(true)+ expect(row('Vibrate').querySelector('.lrow-s').textContent).toBe('Not on iPhone')+ expect(row('Vibrate').querySelector('[role=switch]').disabled).toBe(true)+ })++ it('goes to Settings → Workout from All settings, closing the sheet', () => {+ act(() => row('All settings').click())+ expect(close).toHaveBeenCalled()+ expect(navTo).toHaveBeenCalledWith('/settings/workout')+ })+})diff --git a/frontend/src/locales/ar.js b/frontend/src/locales/ar.jsindex 37c8d2d07..fcf9cd51c 100644--- a/frontend/src/locales/ar.js+++ b/frontend/src/locales/ar.js@@ -1922,4 +1922,7 @@ export default {'Paused': 'متوقف مؤقتًا','Scroll to 0:00 to end the rest now.': 'مرّر إلى 0:00 لإنهاء الراحة الآن.','Time left': 'الوقت المتبقي',+ 'All settings': 'كل الإعدادات',+ 'Changes stick for your next workouts too.': 'تبقى التغييرات لتمارينك القادمة أيضًا.',+ 'Workout settings': 'إعدادات التمرين الحالي',}diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.jsindex 2770ee1a6..129b53f02 100644--- a/frontend/src/locales/de.js+++ b/frontend/src/locales/de.js@@ -1889,4 +1889,7 @@ export default {'Paused': 'Pausiert','Scroll to 0:00 to end the rest now.': 'Auf 0:00 drehen beendet die Pause sofort.','Time left': 'Restzeit',+ 'All settings': 'Alle Einstellungen',+ 'Changes stick for your next workouts too.': 'Änderungen gelten auch für deine nächsten Trainings.',+ 'Workout settings': 'Trainings-Einstellungen',}diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.jsindex 1e589aa00..e13b90087 100644--- a/frontend/src/locales/es.js+++ b/frontend/src/locales/es.js@@ -1869,4 +1869,7 @@ export default {'Paused': 'En pausa','Scroll to 0:00 to end the rest now.': 'Gira hasta 0:00 para terminar el descanso ya.','Time left': 'Tiempo restante',+ 'All settings': 'Todos los ajustes',+ 'Changes stick for your next workouts too.': 'Los cambios se quedan para tus próximos entrenamientos.',+ 'Workout settings': 'Ajustes del entrenamiento',}diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.jsindex c75625598..a426962f0 100644--- a/frontend/src/locales/fr.js+++ b/frontend/src/locales/fr.js@@ -1869,4 +1869,7 @@ export default {'Paused': 'En pause','Scroll to 0:00 to end the rest now.': 'Fais défiler jusqu’à 0:00 pour finir le repos tout de suite.','Time left': 'Temps restant',+ 'All settings': 'Tous les réglages',+ 'Changes stick for your next workouts too.': 'Tes changements valent aussi pour tes prochaines séances.',+ 'Workout settings': 'Réglages de la séance',}diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.jsindex 2aebf0f9d..9696c5725 100644--- a/frontend/src/locales/hi.js+++ b/frontend/src/locales/hi.js@@ -1869,4 +1869,7 @@ export default {'Paused': 'रुका हुआ','Scroll to 0:00 to end the rest now.': 'आराम अभी खत्म करने के लिए 0:00 तक स्क्रॉल करें।','Time left': 'बचा समय',+ 'All settings': 'सभी सेटिंग्स',+ 'Changes stick for your next workouts too.': 'बदलाव आपके अगले वर्कआउट के लिए भी रहेंगे।',+ 'Workout settings': 'वर्कआउट सेटिंग',}diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.jsindex 8ef238ae2..1efb25eba 100644--- a/frontend/src/locales/hu.js+++ b/frontend/src/locales/hu.js@@ -1872,4 +1872,7 @@ export default {'Paused': 'Szüneteltetve','Scroll to 0:00 to end the rest now.': 'Görgesd 0:00-ra, és a pihenő azonnal véget ér.','Time left': 'Hátralévő idő',+ 'All settings': 'Összes beállítás',+ 'Changes stick for your next workouts too.': 'A változások a következő edzésekre is érvényesek.',+ 'Workout settings': 'Edzés beállításai',}diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.jsindex aff09f0d6..879cfb8d6 100644--- a/frontend/src/locales/it.js+++ b/frontend/src/locales/it.js@@ -1869,4 +1869,7 @@ export default {'Paused': 'In pausa','Scroll to 0:00 to end the rest now.': 'Scorri fino a 0:00 per chiudere subito il recupero.','Time left': 'Tempo rimasto',+ 'All settings': 'Tutte le impostazioni',+ 'Changes stick for your next workouts too.': 'Le modifiche valgono anche per i prossimi allenamenti.',+ 'Workout settings': 'Impostazioni allenamento',}diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.jsindex 117e9b79c..4982f3811 100644--- a/frontend/src/locales/ko.js+++ b/frontend/src/locales/ko.js@@ -1869,4 +1869,7 @@ export default {'Paused': '일시정지됨','Scroll to 0:00 to end the rest now.': '0:00으로 돌리면 휴식이 바로 끝나요.','Time left': '남은 시간',+ 'All settings': '전체 설정',+ 'Changes stick for your next workouts too.': '변경 사항은 다음 운동에도 그대로 적용돼요.',+ 'Workout settings': '운동 중 설정',}diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.jsindex c2039f7b1..c3e60bcd5 100644--- a/frontend/src/locales/pl.js+++ b/frontend/src/locales/pl.js@@ -1869,4 +1869,7 @@ export default {'Paused': 'Wstrzymano','Scroll to 0:00 to end the rest now.': 'Przewiń do 0:00, by od razu skończyć przerwę.','Time left': 'Pozostały czas',+ 'All settings': 'Wszystkie ustawienia',+ 'Changes stick for your next workouts too.': 'Zmiany zostają też na kolejne treningi.',+ 'Workout settings': 'Ustawienia treningu',}diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.jsindex a9f3db931..8418fb4ea 100644--- a/frontend/src/locales/pt-BR.js+++ b/frontend/src/locales/pt-BR.js@@ -4,6 +4,9 @@import pt from './pt.js'export const PT_BR_OVERRIDES = {+ 'All settings': 'Todas as configurações',+ 'Changes stick for your next workouts too.': 'As mudanças valem para os próximos treinos também.',+ 'Workout settings': 'Configurações do treino','Change the time left': 'Mudar o tempo que falta','Paused': 'Pausado','Scroll to 0:00 to end the rest now.': 'Role até 0:00 para encerrar o descanso agora.',diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.jsindex 434321cb7..bec35862c 100644--- a/frontend/src/locales/pt.js+++ b/frontend/src/locales/pt.js@@ -1869,4 +1869,7 @@ export default {'Paused': 'Em pausa','Scroll to 0:00 to end the rest now.': 'Roda até 0:00 para acabar já o descanso.','Time left': 'Tempo que falta',+ 'All settings': 'Todas as definições',+ 'Changes stick for your next workouts too.': 'As alterações ficam para os próximos treinos também.',+ 'Workout settings': 'Definições do treino',}diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.jsindex 527584af7..8537fb571 100644--- a/frontend/src/locales/ru.js+++ b/frontend/src/locales/ru.js@@ -1873,4 +1873,7 @@ export default {'Paused': 'На паузе','Scroll to 0:00 to end the rest now.': 'Прокрутите до 0:00, чтобы сразу закончить отдых.','Time left': 'Осталось',+ 'All settings': 'Все настройки',+ 'Changes stick for your next workouts too.': 'Изменения сохранятся и для следующих тренировок.',+ 'Workout settings': 'Настройки тренировки',}diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.jsindex 999731eaf..9adb395be 100644--- a/frontend/src/locales/th.js+++ b/frontend/src/locales/th.js@@ -1880,4 +1880,7 @@ export default {'Paused': 'หยุดชั่วคราว','Scroll to 0:00 to end the rest now.': 'เลื่อนไปที่ 0:00 เพื่อจบการพักทันที','Time left': 'เวลาที่เหลือ',+ 'All settings': 'การตั้งค่าทั้งหมด',+ 'Changes stick for your next workouts too.': 'การเปลี่ยนแปลงจะใช้กับการออกกำลังกายครั้งต่อไปด้วย',+ 'Workout settings': 'ตั้งค่าระหว่างออกกำลังกาย',}diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.jsindex b91d891ca..781939b24 100644--- a/frontend/src/locales/tr.js+++ b/frontend/src/locales/tr.js@@ -1869,4 +1869,7 @@ export default {'Paused': 'Duraklatıldı','Scroll to 0:00 to end the rest now.': 'Dinlenmeyi hemen bitirmek için 0:00\'a kaydır.','Time left': 'Kalan süre',+ 'All settings': 'Tüm ayarlar',+ 'Changes stick for your next workouts too.': 'Değişiklikler sonraki antrenmanlarında da geçerli.',+ 'Workout settings': 'Antrenman ayarları',}diff --git a/frontend/src/locales/uk.js b/frontend/src/locales/uk.jsindex 54eb3c24b..b2993dc68 100644--- a/frontend/src/locales/uk.js+++ b/frontend/src/locales/uk.js@@ -1866,4 +1866,7 @@ export default {'Paused': 'На паузі','Scroll to 0:00 to end the rest now.': 'Прокрутіть до 0:00, щоб одразу завершити відпочинок.','Time left': 'Залишилось',+ 'All settings': 'Усі налаштування',+ 'Changes stick for your next workouts too.': 'Зміни збережуться і для наступних тренувань.',+ 'Workout settings': 'Налаштування тренування',}diff --git a/frontend/src/locales/zh-TW.js b/frontend/src/locales/zh-TW.jsindex a30224510..dd813851f 100644--- a/frontend/src/locales/zh-TW.js+++ b/frontend/src/locales/zh-TW.js@@ -1862,4 +1862,7 @@ export default {'Paused': '已暫停','Scroll to 0:00 to end the rest now.': '捲到 0:00 可立即結束休息。','Time left': '剩餘時間',+ 'All settings': '所有設定',+ 'Changes stick for your next workouts too.': '變更也會套用到之後的訓練。',+ 'Workout settings': '訓練設定',}diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.jsindex 1f0cc87e5..01df0ded5 100644--- a/frontend/src/locales/zh.js+++ b/frontend/src/locales/zh.js@@ -1869,4 +1869,7 @@ export default {'Paused': '已暂停','Scroll to 0:00 to end the rest now.': '滚到 0:00 可立即结束休息。','Time left': '剩余时间',+ 'All settings': '所有设置',+ 'Changes stick for your next workouts too.': '更改也会用于你之后的训练。',+ 'Workout settings': '训练设置',}