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
Progress photos: a timeline of every photo, and a before/after slider
Suroh Susejd5b48f17d11e
diff --git a/frontend/src/App.jsx b/frontend/src/App.jsxindex 0117a2b9d..bc575ea50 100644--- a/frontend/src/App.jsx+++ b/frontend/src/App.jsx@@ -36,6 +36,7 @@ import History from './views/History.jsx'import Library from './views/Library.jsx'import Muscles from './views/Muscles.jsx'import StructuralBalance from './views/StructuralBalance.jsx'+import ProgressPhotos from './views/ProgressPhotos.jsx'import Settings from './views/Settings.jsx'import Admin from './views/Admin.jsx'import CoachChat from './views/CoachChat.jsx'@@ -187,6 +188,7 @@ function Shell() {<Route path="/library" element={<Library />} /><Route path="/muscles" element={<Muscles />} /><Route path="/structural-balance" element={<StructuralBalance />} />+ <Route path="/progress-photos" element={<ProgressPhotos />} /><Route path="/settings" element={<Settings />} />{/* The Coach screens gate themselves on the instance config; the routes existunconditionally so a deep link from a notification lands somewhere sanediff --git a/frontend/src/index.css b/frontend/src/index.cssindex a167187e5..066e34fa7 100644--- a/frontend/src/index.css+++ b/frontend/src/index.css@@ -851,6 +851,30 @@ body.chips-dragging *{cursor:inherit}.wmedia-add:disabled{opacity:.5;cursor:default}.wmedia-note{margin:6px 2px 0;line-height:1.35}.wrow-media{display:inline-flex;align-items:center;gap:3px;font-size:12px;color:var(--label-2);flex:none}++.pp-selected{outline:3px solid var(--acc);outline-offset:-3px}+.pp-check{+ position:absolute;inset-inline-end:5px;top:5px;width:20px;height:20px;border-radius:99px;+ display:flex;align-items:center;justify-content:center;background:var(--acc);color:#fff;font-size:11px;+}+.pp-cta{position:sticky;bottom:calc(var(--sab) + 10px);display:flex;justify-content:center;margin-top:14px}+.pp-compare{position:relative;flex:1;min-height:0;overflow:hidden;background:#000;touch-action:none}+.pp-img{+ position:absolute;inset:0;width:100%;height:100%;object-fit:contain;background:#000;+ -webkit-user-select:none;user-select:none;+}+.pp-handle{+ position:absolute;inset-block:0;transform:translateX(-50%);width:0;+ display:flex;align-items:center;justify-content:center;pointer-events:none;+}+.pp-handle::before{content:'';position:absolute;inset-block:0;width:2px;background:#fff;box-shadow:0 0 0 1px rgba(0,0,0,.3)}+.pp-grip{width:36px;height:36px;border-radius:99px;background:#fff;box-shadow:0 1px 6px rgba(0,0,0,.4)}+.pp-label{+ position:absolute;bottom:14px;font-size:12px;font-weight:600;color:#fff;+ background:rgba(0,0,0,.55);padding:4px 9px;border-radius:99px;pointer-events:none;+}+.pp-label-before{inset-inline-start:10px}+.pp-label-after{inset-inline-end:10px}.wrow-media .icn{font-size:13px}.mviewer{position:absolute;inset:0;background:#000;color:#fff;display:flex;flex-direction:column;diff --git a/frontend/src/views/ProgressPhotos.jsx b/frontend/src/views/ProgressPhotos.jsxnew file mode 100644index 000000000..71d33a503--- /dev/null+++ b/frontend/src/views/ProgressPhotos.jsx@@ -0,0 +1,176 @@+// Every progress photo across every logged workout, in one place, newest first — and a+// before/after comparison between any two of them.+//+// WorkoutMedia.jsx already lets a photo or video be attached to a finished workout, and that is+// still where one is added or removed; this view only reads what is already there (workoutMediaOf,+// the same list WorkoutMedia.jsx shows per workout) and lines every still up chronologically, plus+// a slider to compare two dates directly. Nothing new to store, sync or back up — one more way to+// look at data the media system already keeps, private to the account the same way everything+// else there is (DATA_DIR/uploads/<uid>/, api/media.js).+import { useMemo, useRef, useState } from 'react'+import { useNavigate } from 'react-router-dom'+import { useStore } from '../store/useStore.js'+import { useUI } from '../store/useUI.js'+import { t } from '../lib/i18n.js'+import { fmtDate } from '../lib/format.js'+import { workoutMediaOf } from '../lib/media-refs.js'+import { CustomThumb, MediaView, useMediaUrl } from '../components/CustomMedia.jsx'+import { Button } from '../components/ui.jsx'+import Icon from '../components/Icon.jsx'++/**+ * Every still photo (no video — the comparison wants two stills, not two clips) across every+ * logged workout, newest first. Each entry carries the date and the workout it came from, so the+ * grid and the comparator can both say when a photo was taken without re-deriving it.+ */+export function progressPhotosOf(S) {+ const out = []+ for (const w of (S && S.workouts) || []) {+ for (const m of workoutMediaOf(w)) {+ if (m.kind === 'video') continue+ out.push({ d: w.d, start: w.start || 0, w, m })+ }+ }+ out.sort((a, b) => (a.d < b.d ? 1 : a.d > b.d ? -1 : b.start - a.start))+ return out+}++/** Runs an already-sorted progressPhotosOf() list into { d, items }[] groups of the same date. */+export function groupByDate(photos) {+ const out = []+ for (const p of photos) {+ const last = out[out.length - 1]+ if (last && last.d === p.d) last.items.push(p)+ else out.push({ d: p.d, items: [p] })+ }+ return out+}++/** Whole days between two ISO dates, always ≥ 0 regardless of which comes first. */+export function daysBetween(a, b) {+ const ms = new Date(b + 'T00:00:00') - new Date(a + 'T00:00:00')+ return Math.abs(Math.round(ms / 86400000))+}++function openPhotoView(p) {+ useUI.getState().openSheet(close => (+ <div className="mviewer" role="dialog" aria-modal="true" aria-label={t('Photo')}>+ <div className="mviewer-bar">+ <button type="button" className="iconbtn" aria-label={t('Close')} onClick={close}><Icon name="xmark" /></button>+ <span className="mviewer-count">{fmtDate(p.d, true, true)}</span>+ <span style={{ width: 36 }} />+ </div>+ <div className="mviewer-stage"><MediaView m={p.m} cls="exmedia viewer" /></div>+ </div>+ ), { kind: 'viewer' })+}++/** The before/after slider between two progress photos `a` (earlier) and `b` (later). */+function ProgressCompare({ a, b, close }) {+ const before = useMediaUrl(a.m)+ const after = useMediaUrl(b.m)+ const [pct, setPct] = useState(50)+ const stageRef = useRef(null)+ const dragging = useRef(false)++ const setFromClientX = x => {+ const el = stageRef.current+ if (!el) return+ const rect = el.getBoundingClientRect()+ if (!rect.width) return+ setPct(Math.max(0, Math.min(100, ((x - rect.left) / rect.width) * 100)))+ }+ const onPointerDown = e => { dragging.current = true; e.currentTarget.setPointerCapture?.(e.pointerId); setFromClientX(e.clientX) }+ const onPointerMove = e => { if (dragging.current) setFromClientX(e.clientX) }+ const endDrag = () => { dragging.current = false }++ const days = daysBetween(a.d, b.d)++ return <div className="mviewer" role="dialog" aria-modal="true" aria-label={t('Compare photos')}>+ <div className="mviewer-bar">+ <button type="button" className="iconbtn" aria-label={t('Close')} onClick={close}><Icon name="xmark" /></button>+ <span className="mviewer-count">{days > 0 ? t('{0} days apart', days) : t('Same day')}</span>+ <span style={{ width: 36 }} />+ </div>+ <div className="pp-compare" ref={stageRef} data-swipe-ignore+ onPointerDown={onPointerDown} onPointerMove={onPointerMove} onPointerUp={endDrag} onPointerCancel={endDrag}>+ {after.url && <img className="pp-img" src={after.url} alt="" draggable={false} />}+ {before.url && <img className="pp-img" src={before.url} alt="" draggable={false}+ style={{ clipPath: `inset(0 ${100 - pct}% 0 0)` }} />}+ <div className="pp-handle" style={{ insetInlineStart: pct + '%' }}><div className="pp-grip" /></div>+ <div className="pp-label pp-label-before">{fmtDate(a.d, true)}</div>+ <div className="pp-label pp-label-after">{fmtDate(b.d, true)}</div>+ </div>+ </div>+}++/** Opens the before/after slider between two progressPhotosOf() entries, in date order either way. */+export function openProgressCompare(x, y) {+ const [a, b] = x.d <= y.d ? [x, y] : [y, x]+ useUI.getState().openSheet(close => <ProgressCompare a={a} b={b} close={close} />, { kind: 'viewer' })+}++export default function ProgressPhotos() {+ const nav = useNavigate()+ const S = useStore(s => s.S)+ const photos = useMemo(() => progressPhotosOf(S), [S.workouts])+ const groups = useMemo(() => groupByDate(photos), [photos])+ const [comparing, setComparing] = useState(false)+ const [picked, setPicked] = useState([]) // up to 2 hashes, in tap order++ const toggle = p => setPicked(cur => {+ if (cur.includes(p.m.hash)) return cur.filter(h => h !== p.m.hash)+ return cur.length >= 2 ? [cur[1], p.m.hash] : [...cur, p.m.hash]+ })+ const cancelCompare = () => { setComparing(false); setPicked([]) }+ const runCompare = () => {+ if (picked.length !== 2) return+ const [ha, hb] = picked+ const a = photos.find(p => p.m.hash === ha)+ const b = photos.find(p => p.m.hash === hb)+ cancelCompare()+ if (a && b) openProgressCompare(a, b)+ }++ return <>+ <div className="hdr"><button className="iconbtn" onClick={() => nav('/stats')} aria-label={t('Stats')}><Icon name="chevronLeft" /></button>+ <div style={{ flex: 1, marginInlineStart: 12 }}><h1>{t('Progress photos')}</h1>+ <div className="sub">{t('{0} photos', photos.length)}</div></div>+ {photos.length >= 2 && (comparing+ ? <Button size="sm" variant="ghost" onClick={cancelCompare}>{t('Cancel')}</Button>+ : <Button size="sm" variant="tinted" onClick={() => setComparing(true)}>{t('Compare')}</Button>)}+ </div>++ {comparing && <div className="small dim" style={{ margin: '0 0 12px' }}>+ {picked.length < 2 ? t('Pick two photos to compare.') : t('Ready — open the comparison.')}+ </div>}++ {!photos.length+ ? <div className="empty"><div className="ico"><Icon name="image" /></div>+ {t('No progress photos yet — add one from a workout’s finish screen, or from its entry in History.')}+ </div>+ : groups.map(g => (+ <div key={g.d} style={{ marginBottom: 18 }}>+ <div className="small muted" style={{ marginBottom: 6 }}>{fmtDate(g.d, true, true)}</div>+ <div className="wmedia-grid">+ {g.items.map(p => {+ const selected = picked.includes(p.m.hash)+ return (+ <button key={p.m.hash} type="button" data-swipe-ignore+ className={'wmedia-item' + (selected ? ' pp-selected' : '')}+ aria-label={fmtDate(p.d, true)}+ onClick={() => (comparing ? toggle(p) : openPhotoView(p))}>+ <CustomThumb ex={{ custom: true, media: p.m }} />+ {selected && <span className="pp-check"><Icon name="check" /></span>}+ </button>+ )+ })}+ </div>+ </div>+ ))}++ {comparing && picked.length === 2 && <div className="pp-cta">+ <Button variant="primary" onClick={runCompare}>{t('Compare')}</Button>+ </div>}+ </>+}diff --git a/frontend/src/views/ProgressPhotos.test.js b/frontend/src/views/ProgressPhotos.test.jsnew file mode 100644index 000000000..9584d7ee3--- /dev/null+++ b/frontend/src/views/ProgressPhotos.test.js@@ -0,0 +1,82 @@+// @vitest-environment happy-dom+import { describe, it, expect } from 'vitest'+import { progressPhotosOf, groupByDate, daysBetween } from './ProgressPhotos.jsx'++// normalizeMediaRef (lib/media-refs.js) only accepts a 64-hex-char hash — workoutMediaOf drops+// anything else, so the fixtures need real ones. A short label maps to a stable fake hash.+let n = 0+const labels = {}+const hashOf = label => labels[label] || (labels[label] = (++n).toString(16).padStart(64, '0'))++const img = label => ({ kind: 'image', hash: hashOf(label), mime: 'image/jpeg', size: 1000, width: 10, height: 10 })+const gif = label => ({ kind: 'gif', hash: hashOf(label), mime: 'image/gif', size: 1000, width: 10, height: 10 })+const video = label => ({ kind: 'video', hash: hashOf(label), mime: 'video/mp4', size: 1000, width: 10, height: 10, dur: 5 })+const hashes = photos => photos.map(p => Object.keys(labels).find(l => labels[l] === p.m.hash))++describe('progressPhotosOf', () => {+ it('collects every still across every workout, newest first', () => {+ const S = {+ workouts: [+ { d: '2026-01-01', start: 100, media: [img('a')] },+ { d: '2026-02-01', start: 100, media: [img('b'), img('c')] },+ ],+ }+ const out = progressPhotosOf(S)+ expect(hashes(out)).toEqual(['b', 'c', 'a'])+ expect(out[0].d).toBe('2026-02-01')+ })++ it('leaves videos out — the comparator wants two stills, not two clips', () => {+ const S = { workouts: [{ d: '2026-01-01', start: 0, media: [img('still'), video('clip')] }] }+ expect(hashes(progressPhotosOf(S))).toEqual(['still'])+ })++ it('keeps a gif — it is a still image plus motion, not a clip', () => {+ const S = { workouts: [{ d: '2026-01-01', start: 0, media: [gif('animated')] }] }+ expect(hashes(progressPhotosOf(S))).toEqual(['animated'])+ })++ it('breaks a same-day tie by the later workout, most recent first', () => {+ const S = {+ workouts: [+ { d: '2026-01-01', start: 100, media: [img('morning')] },+ { d: '2026-01-01', start: 200, media: [img('evening')] },+ ],+ }+ expect(hashes(progressPhotosOf(S))).toEqual(['evening', 'morning'])+ })++ it('is empty for no workouts, and for workouts with no media', () => {+ expect(progressPhotosOf({ workouts: [] })).toEqual([])+ expect(progressPhotosOf({ workouts: [{ d: '2026-01-01', start: 0 }] })).toEqual([])+ expect(progressPhotosOf(null)).toEqual([])+ })+})++describe('groupByDate', () => {+ it('runs consecutive same-date entries into one group, in the order given', () => {+ const photos = [+ { d: '2026-02-01', m: { hash: hashOf('b') } }, { d: '2026-02-01', m: { hash: hashOf('c') } },+ { d: '2026-01-01', m: { hash: hashOf('a') } },+ ]+ expect(groupByDate(photos)).toEqual([+ { d: '2026-02-01', items: [photos[0], photos[1]] },+ { d: '2026-01-01', items: [photos[2]] },+ ])+ })++ it('is empty for an empty list', () => {+ expect(groupByDate([])).toEqual([])+ })+})++describe('daysBetween', () => {+ it('counts whole days regardless of which date comes first', () => {+ expect(daysBetween('2026-01-01', '2026-01-15')).toBe(14)+ expect(daysBetween('2026-01-15', '2026-01-01')).toBe(14)+ })++ it('is zero for the same day', () => {+ expect(daysBetween('2026-01-01', '2026-01-01')).toBe(0)+ })+})diff --git a/frontend/src/views/Stats.jsx b/frontend/src/views/Stats.jsxindex d96d0ab47..73549c6e2 100644--- a/frontend/src/views/Stats.jsx+++ b/frontend/src/views/Stats.jsx@@ -477,6 +477,11 @@ export default function Stats() {<div className="muted small" style={{ marginTop: 4 }}>{t('See which lift is holding back the rest.')}</div></div><Button size="sm" variant="tinted" trailingIcon="chevronRight" style={{ flexShrink: 0 }} onClick={() => nav('/structural-balance')}>{t('Open')}</Button></div>}+ {workouts.length > 0 && <div className="card row between" style={{ alignItems: 'center', gap: 12 }}>+ <div style={{ minWidth: 0 }}><h2 style={{ margin: 0 }}>{t('Progress photos')}</h2>+ <div className="muted small" style={{ marginTop: 4 }}>{t('Every photo you kept with a workout, lined up by date — and a before/after slider.')}</div></div>+ <Button size="sm" variant="tinted" trailingIcon="chevronRight" style={{ flexShrink: 0 }} onClick={() => nav('/progress-photos')}>{t('Open')}</Button>+ </div>}{hasEffort(S) && <EffortCard S={S} />}<div className="cols">