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: remove one from the gallery, with Undo (#558)
Duarte Santos68273e7332de
diff --git a/frontend/src/lib/pt-br-locale.test.js b/frontend/src/lib/pt-br-locale.test.jsindex 8af967646..fb17fe237 100644--- a/frontend/src/lib/pt-br-locale.test.js+++ b/frontend/src/lib/pt-br-locale.test.js@@ -41,7 +41,7 @@ describe('Brazilian Portuguese locale', () => {// has to be taught is a number nobody reads. What the numbers stood for is asserted above.// If the hash fails, review the changed keys and wording before accepting a new one. From// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list- expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('c4fc6feddca3a51396ace0845e66bac3c623c922b477e0adb823a90436c77e03')+ expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('6ccfae3c126b654efed8d6d5f1c4599ee79b0a6b38a1ce58282d0ff2456a9651')})// pt-PT labelled Unpair 'Desfazer': Undo, in Portuguese (it is pt-BR's Undo), on the button thatdiff --git a/frontend/src/lib/workout-media.js b/frontend/src/lib/workout-media.jsindex d79be7223..83645264c 100644--- a/frontend/src/lib/workout-media.js+++ b/frontend/src/lib/workout-media.js@@ -63,3 +63,20 @@ export function removeWorkoutMedia(state, w, hash, now = Date.now()) {write(rec, left, now)return true}++/**+ * Undo of a removal: puts `ref` back on the saved workout `w` at `index` (or at the end), unless+ * that file is on it again already. The cap is not asked: the photo was there a moment ago.+ * Returns whether anything changed.+ */+export function restoreWorkoutMedia(state, w, ref, index, now = Date.now()) {+ const rec = recordOf(state, w)+ if (!rec || !ref || !ref.hash) return false+ const raw = rawOf(rec)+ if (raw.some(x => x && x.hash === ref.hash)) return false+ const list = raw.slice()+ list.splice(Math.max(0, Math.min(Number.isInteger(index) ? index : list.length, list.length)), 0, ref)+ write(rec, list, now)+ return true+}+diff --git a/frontend/src/lib/workout-media.test.js b/frontend/src/lib/workout-media.test.jsindex 71a69dcca..4278fa182 100644--- a/frontend/src/lib/workout-media.test.js+++ b/frontend/src/lib/workout-media.test.js@@ -2,7 +2,7 @@// stamp), what the sync merge keeps of it, what the history editor does with it, and the places// that must never carry it (copy as text, a routine saved from the workout, a plan file).import { describe, expect, it } from 'vitest'-import { addWorkoutMedia, removeWorkoutMedia } from './workout-media.js'+import { addWorkoutMedia, removeWorkoutMedia, restoreWorkoutMedia } from './workout-media.js'import { WORKOUT_MEDIA_MAX, workoutMediaOf, referencedHashes, referencedFiles, stateMediaRefs } from './media-refs.js'import { mergeStates } from './sync-merge.js'import { editCompletedSession, saveWorkoutEdit } from './session-edit.js'@@ -83,6 +83,29 @@ describe('addWorkoutMedia / removeWorkoutMedia', () => {})})+describe('restoreWorkoutMedia (the Undo of a removal, #558)', () => {+ it('puts the ref back where it was and stamps; a file already back, a missing workout or no ref change nothing', () => {+ const S = state(workout({ media: [photo(H(1)), photo(H(3))], _ts: 1 }))+ expect(restoreWorkoutMedia(S, { id: 'w1' }, photo(H(2)), 1, 50)).toBe(true)+ expect(S.workouts[0].media.map(m => m.hash)).toEqual([H(1), H(2), H(3)])+ expect(S.workouts[0]._ts).toBe(50)+ expect(restoreWorkoutMedia(S, { id: 'w1' }, photo(H(2)), 0, 60)).toBe(false)+ expect(restoreWorkoutMedia(S, { id: 'gone' }, photo(H(4)), 0, 60)).toBe(false)+ expect(restoreWorkoutMedia(S, { id: 'w1' }, null, 0, 60)).toBe(false)+ expect(S.workouts[0]._ts).toBe(50)+ })+ it('an index past the end, or none, appends; a removal and its undo round-trip the record', () => {+ const before = workout({ media: [photo(H(1)), photo(H(2))] })+ const S = state(structuredClone(before))+ removeWorkoutMedia(S, { id: 'w1' }, H(1), 70)+ restoreWorkoutMedia(S, { id: 'w1' }, photo(H(1)), 0, 71)+ const { _ts, ...after } = S.workouts[0]+ expect(after).toEqual(before)+ restoreWorkoutMedia(S, { id: 'w1' }, photo(H(5)), 99, 72)+ expect(S.workouts[0].media.at(-1).hash).toBe(H(5))+ })+})+describe('workoutMediaOf / the state walk', () => {it('shows only valid refs, each file once, at most six', () => {const w = workout({ media: [photo(H(1)), 'x', null, { hash: 'bad' }, photo(H(1)), ...[2, 3, 4, 5, 6, 7, 8].map(n => photo(H(n)))] })diff --git a/frontend/src/locales/ar.js b/frontend/src/locales/ar.jsindex 726e6bb36..c517f1c12 100644--- a/frontend/src/locales/ar.js+++ b/frontend/src/locales/ar.js@@ -2351,4 +2351,6 @@ export default {// --- Coach message box ---'Make the box bigger': 'تكبير مربع الكتابة','Make the box smaller': 'تصغير مربع الكتابة',+ // --- progress photos: remove ---+ 'Photo removed': 'تمت إزالة الصورة',}diff --git a/frontend/src/locales/bn.js b/frontend/src/locales/bn.jsindex c5c506639..7edc540cb 100644--- a/frontend/src/locales/bn.js+++ b/frontend/src/locales/bn.js@@ -2375,4 +2375,6 @@ export default {// --- Coach message box ---'Make the box bigger': 'লেখার বাক্স বড় করুন','Make the box smaller': 'লেখার বাক্স ছোট করুন',+ // --- progress photos: remove ---+ 'Photo removed': 'ছবি সরানো হয়েছে',}diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.jsindex b2b91befd..210442e2f 100644--- a/frontend/src/locales/de.js+++ b/frontend/src/locales/de.js@@ -2316,4 +2316,6 @@ export default {// --- Coach message box ---'Make the box bigger': 'Feld vergrößern','Make the box smaller': 'Feld verkleinern',+ // --- progress photos: remove ---+ 'Photo removed': 'Foto entfernt',}diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.jsindex a99ce1cfd..b16ea92d1 100644--- a/frontend/src/locales/es.js+++ b/frontend/src/locales/es.js@@ -2296,4 +2296,6 @@ export default {// --- Coach message box ---'Make the box bigger': 'Agrandar el cuadro','Make the box smaller': 'Achicar el cuadro',+ // --- progress photos: remove ---+ 'Photo removed': 'Foto quitada',}diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.jsindex 9a13b26e1..620bd24bd 100644--- a/frontend/src/locales/fr.js+++ b/frontend/src/locales/fr.js@@ -2296,4 +2296,6 @@ export default {// --- Coach message box ---'Make the box bigger': 'Agrandir la zone','Make the box smaller': 'Réduire la zone',+ // --- progress photos: remove ---+ 'Photo removed': 'Photo retirée',}diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.jsindex 2432a3272..fbb98d16d 100644--- a/frontend/src/locales/hi.js+++ b/frontend/src/locales/hi.js@@ -2296,4 +2296,6 @@ export default {// --- Coach message box ---'Make the box bigger': 'बॉक्स बड़ा करें','Make the box smaller': 'बॉक्स छोटा करें',+ // --- progress photos: remove ---+ 'Photo removed': 'फ़ोटो हटाई गई',}diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.jsindex afa8c354c..c54fa6ae5 100644--- a/frontend/src/locales/hu.js+++ b/frontend/src/locales/hu.js@@ -2299,4 +2299,6 @@ export default {// --- Coach message box ---'Make the box bigger': 'Nagyobb mező','Make the box smaller': 'Kisebb mező',+ // --- progress photos: remove ---+ 'Photo removed': 'Fotó eltávolítva',}diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.jsindex 15a51bae3..cf18f3894 100644--- a/frontend/src/locales/it.js+++ b/frontend/src/locales/it.js@@ -2296,4 +2296,6 @@ export default {// --- Coach message box ---'Make the box bigger': 'Ingrandisci il riquadro','Make the box smaller': 'Rimpicciolisci il riquadro',+ // --- progress photos: remove ---+ 'Photo removed': 'Foto rimossa',}diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.jsindex 23f8d08d5..09a84128f 100644--- a/frontend/src/locales/ko.js+++ b/frontend/src/locales/ko.js@@ -2296,4 +2296,6 @@ export default {// --- Coach message box ---'Make the box bigger': '입력창 크게','Make the box smaller': '입력창 작게',+ // --- progress photos: remove ---+ 'Photo removed': '사진을 지웠어요',}diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.jsindex 8f9a300ee..13f278442 100644--- a/frontend/src/locales/pl.js+++ b/frontend/src/locales/pl.js@@ -2296,4 +2296,6 @@ export default {// --- Coach message box ---'Make the box bigger': 'Powiększ pole','Make the box smaller': 'Zmniejsz pole',+ // --- progress photos: remove ---+ 'Photo removed': 'Zdjęcie usunięte',}diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.jsindex bb0df4ddd..2d4684fd9 100644--- a/frontend/src/locales/pt-BR.js+++ b/frontend/src/locales/pt-BR.js@@ -1455,6 +1455,7 @@ export const PT_BR_OVERRIDES = {// --- background check before the nudge ---'Logged a workout on another device? Before the nudge goes out, the phone checks with your server whenever it lets the app run in the background. Opening the app always catches up.': 'Registrou um treino em outro dispositivo? Antes do aviso, o celular confirma com o seu servidor, sempre que deixar o aplicativo rodar em segundo plano. Abrir o aplicativo sempre deixa tudo em dia.',// --- Coach message box ---+ // --- progress photos: remove ---}export default { ...pt, ...PT_BR_OVERRIDES }diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.jsindex 4e3fec87c..fce4043f3 100644--- a/frontend/src/locales/pt.js+++ b/frontend/src/locales/pt.js@@ -2296,4 +2296,6 @@ export default {// --- Coach message box ---'Make the box bigger': 'Aumentar a caixa','Make the box smaller': 'Diminuir a caixa',+ // --- progress photos: remove ---+ 'Photo removed': 'Foto removida',}diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.jsindex d6bf69692..6394cd611 100644--- a/frontend/src/locales/ru.js+++ b/frontend/src/locales/ru.js@@ -2300,4 +2300,6 @@ export default {// --- Coach message box ---'Make the box bigger': 'Увеличить поле','Make the box smaller': 'Уменьшить поле',+ // --- progress photos: remove ---+ 'Photo removed': 'Фото удалено',}diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.jsindex f37fb55ea..6ff1422e5 100644--- a/frontend/src/locales/th.js+++ b/frontend/src/locales/th.js@@ -2307,4 +2307,6 @@ export default {// --- Coach message box ---'Make the box bigger': 'ขยายช่องพิมพ์','Make the box smaller': 'ย่อช่องพิมพ์',+ // --- progress photos: remove ---+ 'Photo removed': 'ลบรูปแล้ว',}diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.jsindex c3b9147cc..941da4970 100644--- a/frontend/src/locales/tr.js+++ b/frontend/src/locales/tr.js@@ -2296,4 +2296,6 @@ export default {// --- Coach message box ---'Make the box bigger': 'Kutuyu büyüt','Make the box smaller': 'Kutuyu küçült',+ // --- progress photos: remove ---+ 'Photo removed': 'Fotoğraf kaldırıldı',}diff --git a/frontend/src/locales/uk.js b/frontend/src/locales/uk.jsindex 2530f2760..a28fabbca 100644--- a/frontend/src/locales/uk.js+++ b/frontend/src/locales/uk.js@@ -2293,4 +2293,6 @@ export default {// --- Coach message box ---'Make the box bigger': 'Збільшити поле','Make the box smaller': 'Зменшити поле',+ // --- progress photos: remove ---+ 'Photo removed': 'Фото видалено',}diff --git a/frontend/src/locales/zh-TW.js b/frontend/src/locales/zh-TW.jsindex 34f57662f..933f4c122 100644--- a/frontend/src/locales/zh-TW.js+++ b/frontend/src/locales/zh-TW.js@@ -2289,4 +2289,6 @@ export default {// --- Coach message box ---'Make the box bigger': '放大輸入框','Make the box smaller': '縮小輸入框',+ // --- progress photos: remove ---+ 'Photo removed': '已移除相片',}diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.jsindex 633b4c9cd..dda5cb8f2 100644--- a/frontend/src/locales/zh.js+++ b/frontend/src/locales/zh.js@@ -2296,4 +2296,6 @@ export default {// --- Coach message box ---'Make the box bigger': '放大输入框','Make the box smaller': '缩小输入框',+ // --- progress photos: remove ---+ 'Photo removed': '已移除照片',}diff --git a/frontend/src/views/ProgressPhotos.delete.test.jsx b/frontend/src/views/ProgressPhotos.delete.test.jsxnew file mode 100644index 000000000..ae8bcee9e--- /dev/null+++ b/frontend/src/views/ProgressPhotos.delete.test.jsx@@ -0,0 +1,60 @@+// @vitest-environment happy-dom+import React, { act } from 'react'+import { createRoot } from 'react-dom/client'+import { afterEach, beforeEach, describe, expect, it } from 'vitest'+import { useStore, DEF } from '../store/useStore.js'+import { useUI } from '../store/useUI.js'+import { PhotoView, progressPhotosOf } from './ProgressPhotos.jsx'++globalThis.IS_REACT_ACT_ENVIRONMENT = true++/* #558: a progress photo can be removed from the gallery's full-size view. It comes off the workout+ it belongs to and nothing else (the same photo on another workout stays), and Undo puts it back+ where it was. */+const ref = (n, extra = {}) => ({ kind: 'image', hash: String(n).padStart(64, '0'), mime: 'image/jpeg', size: 10, width: 4, height: 3, at: 1, ...extra })+const state = () => ({+ ...structuredClone(DEF),+ workouts: [+ { id: 'w1', d: '2026-10-01', start: 1, entries: [], media: [ref(1), ref(2), ref(3)] },+ { id: 'w2', d: '2026-10-05', start: 2, entries: [], media: [ref(2)] },+ ],+})++let host, root+beforeEach(() => {+ localStorage.clear()+ useStore.setState({ S: state(), user: null, ready: true })+ host = document.createElement('div'); document.body.appendChild(host); root = createRoot(host)+})+afterEach(() => { act(() => root.unmount()); host.remove(); useUI.getState().closeAll?.() })++const button = label => [...host.querySelectorAll('button')].find(b => b.getAttribute('aria-label') === label || b.textContent === label)+const media = id => useStore.getState().S.workouts.find(w => w.id === id).media++describe('removing a progress photo', () => {+ it('asks first, takes it off that workout only, and Undo puts it back in its place', () => {+ const p = progressPhotosOf(useStore.getState().S).find(x => x.w.id === 'w1' && x.m.hash === ref(2).hash)+ let closed = 0+ act(() => root.render(<PhotoView p={p} close={() => { closed++ }} />))+ act(() => button('Remove').click()) // the trash in the bar+ expect(host.textContent).toContain('Remove this photo or video?')+ act(() => [...host.querySelectorAll('.mviewer-ask button')].find(b => b.textContent === 'Remove').click())+ expect(closed).toBe(1)+ expect(media('w1').map(m => m.hash)).toEqual([ref(1).hash, ref(3).hash])+ expect(media('w2').map(m => m.hash)).toEqual([ref(2).hash])+ const ui = useUI.getState()+ expect(ui.toastMsg).toBe('Photo removed')+ expect(ui.toastAction?.label).toBe('Undo')+ act(() => ui.runToastAction())+ expect(media('w1')).toEqual([ref(1), ref(2), ref(3)])+ })++ it('Cancel leaves it as it was', () => {+ const before = structuredClone(useStore.getState().S.workouts)+ const p = progressPhotosOf(useStore.getState().S)[0]+ act(() => root.render(<PhotoView p={p} close={() => {}} />))+ act(() => button('Remove').click())+ act(() => button('Cancel').click())+ expect(useStore.getState().S.workouts).toEqual(before)+ })+})diff --git a/frontend/src/views/ProgressPhotos.jsx b/frontend/src/views/ProgressPhotos.jsxindex e4f455c6f..874349cce 100644--- a/frontend/src/views/ProgressPhotos.jsx+++ b/frontend/src/views/ProgressPhotos.jsx@@ -16,7 +16,8 @@ import { useUI } from '../store/useUI.js'import { t, tn } from '../lib/i18n.js'import { fmtDate, todayISO } from '../lib/format.js'import { workoutMediaOf, WORKOUT_MEDIA_MAX } from '../lib/media-refs.js'-import { addWorkoutMedia } from '../lib/workout-media.js'+import { addWorkoutMedia, removeWorkoutMedia, restoreWorkoutMedia } from '../lib/workout-media.js'+import { sameWorkout } from '../lib/workout-date.js'import { syncMedia } from '../lib/media-sync.js'import { useMediaPicker } from '../components/CustomMediaField.jsx'import { CustomThumb, MediaView, useMediaUrl } from '../components/CustomMedia.jsx'@@ -68,17 +69,44 @@ export function daysBetween(a, b) {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>+// A photo full size, with a way to remove it (#558): it comes off the workout it belongs to,+// exactly as the workout's own photo viewer takes it off (lib/workout-media.js), and the file is+// left to the media clean-up like there. An Undo puts it back where it was.+export function PhotoView({ p, close }) {+ const [asking, setAsking] = useState(false)+ const remove = () => {+ const st = useStore.getState()+ const rec = (st.S.workouts || []).find(w => w && sameWorkout(w, p.w)) || p.w+ const at = Array.isArray(rec?.media) ? rec.media.findIndex(x => x && x.hash === p.m.hash) : -1+ const ref = at >= 0 ? rec.media[at] : p.m+ let removed = false+ st.update(s => { removed = removeWorkoutMedia(s, p.w, p.m.hash) })+ close()+ if (!removed) return+ useUI.getState().toast(t('Photo removed'), {+ action: t('Undo'),+ onAction: () => useStore.getState().update(s => { restoreWorkoutMedia(s, p.w, ref, at) }),+ })+ }+ return <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>+ <button type="button" className="iconbtn" aria-label={t('Remove')} onClick={() => setAsking(a => !a)}><Icon name="trash" /></button></div>- ), { kind: 'viewer' })+ <div className="mviewer-stage"><MediaView m={p.m} cls="exmedia viewer" /></div>+ {asking && <div className="mviewer-ask">+ <div className="mviewer-ask-t">{t('Remove this photo or video?')}</div>+ <div className="mviewer-ask-b">+ <Button variant="ghost" size="sm" onClick={() => setAsking(false)}>{t('Cancel')}</Button>+ <Button variant="danger" size="sm" onClick={remove}>{t('Remove')}</Button>+ </div>+ </div>}+ </div>+}++function openPhotoView(p) {+ useUI.getState().openSheet(close => <PhotoView p={p} close={close} />, { kind: 'viewer' })}/** The before/after slider between two progress photos `a` (earlier) and `b` (later). */