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
Workouts: replacing a day's workout keeps its photos and videos, and Delete says when they go
Duarte Santos82cdc7ceced6
diff --git a/frontend/src/lib/backfill.js b/frontend/src/lib/backfill.jsindex 3bf26aa6a..9ef8db1fa 100644--- a/frontend/src/lib/backfill.js+++ b/frontend/src/lib/backfill.js@@ -3,6 +3,7 @@// pure so the date arithmetic and the history surgery can be tested without the UI.import { bestWeightForEntry } from './history.js'import { isSideSet, syncSideAggregate } from './workout-model.js'+import { mergeWorkoutMedia, stampWorkout } from './sync-merge.js'export const workoutsOn = (S, iso) => (S.workouts || []).filter(w => w.d === iso)@@ -56,10 +57,18 @@ export function insertChronological(workouts, w) {// The history after a backfilled session is filed: the workout it replaces (if any) is gone// and the new one sits in date order. Returns a new array; the caller stores it.-export function completeBackfill(workouts, active, w) {+//+// Replacing re-logs that day's sets, not its photos and videos: those move onto the new record+// (after any it has), stamped like any other edit of a saved workout, so the progress photo of a+// day logged again is not dropped with the old sets. `w` is changed in place when they do.+export function completeBackfill(workouts, active, w, now = Date.now()) {const replaceId = active.backfill?.replaceId- const kept = replaceId ? workouts.filter(x => x.id !== replaceId) : workouts- return insertChronological(kept, w)+ if (!replaceId) return insertChronological(workouts, w)+ const replaced = workouts.find(x => x.id === replaceId)+ const had = Array.isArray(w.media) ? w.media.length : 0+ if (replaced) mergeWorkoutMedia(w, replaced)+ if ((Array.isArray(w.media) ? w.media.length : 0) > had) stampWorkout(w, now)+ return insertChronological(workouts.filter(x => x.id !== replaceId), w)}// "Mark all sets done" while logging a past workout (#284). A session written down after thediff --git a/frontend/src/lib/backfill.test.js b/frontend/src/lib/backfill.test.jsindex 9dbe5f867..417fd8843 100644--- a/frontend/src/lib/backfill.test.js+++ b/frontend/src/lib/backfill.test.js@@ -56,6 +56,18 @@ describe('completeBackfill', () => {expect(out.map(x => x.id)).toEqual(['a', 'x', 'd'])expect(list).toHaveLength(3)})+ it('carries the replaced workout\'s photos and videos onto the new record, stamped', () => {+ const ref = n => ({ kind: 'image', hash: String(n).repeat(64), mime: 'image/webp', size: 10, width: 8, height: 6, at: 1 })+ const withMedia = [list[0], { ...list[1], media: [ref(1), ref(2)] }, list[2]]+ const x = w('x', '2026-01-05', 30)+ const out = completeBackfill(withMedia, { backfill: { durationMin: 60, replaceId: 'b' } }, x, 777)+ expect(out.map(y => y.id)).toEqual(['a', 'x', 'd'])+ expect(out[1].media).toEqual([ref(1), ref(2)])+ expect(out[1]._ts).toBe(777)+ // Nothing to carry: no stamp, no empty list.+ const plain = completeBackfill(list, { backfill: { durationMin: 60, replaceId: 'b' } }, w('y', '2026-01-05', 30), 777)+ expect('media' in plain[1] || '_ts' in plain[1]).toBe(false)+ })})// #284: a missed Monday logged on Saturday opened at Friday's progression and saved it as Monday's.diff --git a/frontend/src/lib/pt-br-locale.test.js b/frontend/src/lib/pt-br-locale.test.jsindex d46135ddb..13f52b2b8 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('1af9daba9d909eb5fd32368632dadaf62f606e152f8f9ae808cb9339a070cac6')+ expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('9be6cc7996a836338e4c6d4aaa075dc40f350dad94c72ef67c0a021870720c49')})test('does not leak European Portuguese UI terms', () => {diff --git a/frontend/src/lib/session-edit.js b/frontend/src/lib/session-edit.jsindex 30be88d74..325b68d17 100644--- a/frontend/src/lib/session-edit.js+++ b/frontend/src/lib/session-edit.js@@ -185,6 +185,13 @@ export function saveWorkoutEdit(state, now = Date.now()) {return saved}+/** The saved record the editor is open on, as history holds it now — or null (none open, or it+ * was deleted meanwhile). */+export function editedRecord(state) {+ const key = state?.active?.editingWorkoutId+ return key == null ? null : list(state.workouts).find(w => keyOf(w) === key) || null+}+/*** Deletes the workout the editor is open on and closes the editor: what an edit that took out* every set gets instead of Save (editLeftEmpty). The record is found the way Save finds it, and@@ -193,8 +200,7 @@ export function saveWorkoutEdit(state, now = Date.now()) {* gone, and the editor just closes. Returns whether a record was removed.*/export function deleteEditedWorkout(state) {- const key = state.active?.editingWorkoutId- const current = key == null ? null : list(state.workouts).find(w => keyOf(w) === key)+ const current = editedRecord(state)state.active = nullif (!current) return falsestate.workouts = state.workouts.filter(w => w !== current)diff --git a/frontend/src/locales/ar.js b/frontend/src/locales/ar.jsindex 7d7fa580f..9fe69d7d3 100644--- a/frontend/src/locales/ar.js+++ b/frontend/src/locales/ar.js@@ -1651,4 +1651,8 @@ export default {'Previous': 'السابق','{0} photo or video': '{0} صورة أو فيديو','{0} photos or videos': '{0} من الصور أو مقاطع الفيديو',+ 'Its photo or video is deleted with it.': 'ستُحذف الصورة أو الفيديو المرفق معه أيضًا.',+ 'Its {0} photos or videos are deleted with it.': 'ستُحذف معه أيضًا الصور أو مقاطع الفيديو المرفقة ({0}).',+ 'Its photo or video moves to the new workout.': 'تنتقل الصورة أو الفيديو المرفق إلى التمرين الجديد.',+ 'Its {0} photos or videos move to the new workout.': 'تنتقل الصور أو مقاطع الفيديو المرفقة ({0}) إلى التمرين الجديد.',}diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.jsindex 965859821..1e82bf00b 100644--- a/frontend/src/locales/de.js+++ b/frontend/src/locales/de.js@@ -1618,4 +1618,8 @@ export default {'Previous': 'Zurück','{0} photo or video': '{0} Foto oder Video','{0} photos or videos': '{0} Fotos oder Videos',+ 'Its photo or video is deleted with it.': 'Das Foto oder Video darin wird mitgelöscht.',+ 'Its {0} photos or videos are deleted with it.': 'Die {0} Fotos oder Videos darin werden mitgelöscht.',+ 'Its photo or video moves to the new workout.': 'Das Foto oder Video kommt ins neue Training mit.',+ 'Its {0} photos or videos move to the new workout.': 'Die {0} Fotos oder Videos kommen ins neue Training mit.',}diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.jsindex 4d06bfe43..f40c8ac74 100644--- a/frontend/src/locales/es.js+++ b/frontend/src/locales/es.js@@ -1598,4 +1598,8 @@ export default {'Previous': 'Anterior','{0} photo or video': '{0} foto o vídeo','{0} photos or videos': '{0} fotos o vídeos',+ 'Its photo or video is deleted with it.': 'Su foto o vídeo también se elimina.',+ 'Its {0} photos or videos are deleted with it.': 'Sus {0} fotos o vídeos también se eliminan.',+ 'Its photo or video moves to the new workout.': 'Su foto o vídeo pasa al nuevo entrenamiento.',+ 'Its {0} photos or videos move to the new workout.': 'Sus {0} fotos o vídeos pasan al nuevo entrenamiento.',}diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.jsindex 8e6f982b1..dd46cd9c2 100644--- a/frontend/src/locales/fr.js+++ b/frontend/src/locales/fr.js@@ -1598,4 +1598,8 @@ export default {'Previous': 'Précédent','{0} photo or video': '{0} photo ou vidéo','{0} photos or videos': '{0} photos ou vidéos',+ 'Its photo or video is deleted with it.': 'Sa photo ou vidéo est supprimée avec elle.',+ 'Its {0} photos or videos are deleted with it.': 'Ses {0} photos ou vidéos sont supprimées avec elle.',+ 'Its photo or video moves to the new workout.': 'Sa photo ou vidéo passe à la nouvelle séance.',+ 'Its {0} photos or videos move to the new workout.': 'Ses {0} photos ou vidéos passent à la nouvelle séance.',}diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.jsindex 2bfffb7c3..943783987 100644--- a/frontend/src/locales/hi.js+++ b/frontend/src/locales/hi.js@@ -1598,4 +1598,8 @@ export default {'Previous': 'पिछला','{0} photo or video': '{0} फ़ोटो या वीडियो','{0} photos or videos': '{0} फ़ोटो या वीडियो',+ 'Its photo or video is deleted with it.': 'इसकी फ़ोटो या वीडियो भी इसके साथ हट जाएगी।',+ 'Its {0} photos or videos are deleted with it.': 'इसकी {0} फ़ोटो या वीडियो भी इसके साथ हट जाएँगी।',+ 'Its photo or video moves to the new workout.': 'इसकी फ़ोटो या वीडियो नए वर्कआउट में चली जाएगी।',+ 'Its {0} photos or videos move to the new workout.': 'इसकी {0} फ़ोटो या वीडियो नए वर्कआउट में चली जाएँगी।',}diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.jsindex 34fd7ccd3..be2249292 100644--- a/frontend/src/locales/hu.js+++ b/frontend/src/locales/hu.js@@ -1601,4 +1601,8 @@ export default {'Previous': 'Előző','{0} photo or video': '{0} fotó vagy videó','{0} photos or videos': '{0} fotó vagy videó',+ 'Its photo or video is deleted with it.': 'Vele együtt törlődik a hozzá tartozó fotó vagy videó is.',+ 'Its {0} photos or videos are deleted with it.': 'Vele együtt törlődnek a hozzá tartozó fotók és videók is ({0}).',+ 'Its photo or video moves to the new workout.': 'A hozzá tartozó fotó vagy videó átkerül az új edzéshez.',+ 'Its {0} photos or videos move to the new workout.': 'A hozzá tartozó fotók és videók ({0}) átkerülnek az új edzéshez.',}diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.jsindex ba4b3894d..673485090 100644--- a/frontend/src/locales/it.js+++ b/frontend/src/locales/it.js@@ -1598,4 +1598,8 @@ export default {'Previous': 'Prec.','{0} photo or video': '{0} foto o video','{0} photos or videos': '{0} foto o video',+ 'Its photo or video is deleted with it.': 'Anche la sua foto o il suo video viene eliminato.',+ 'Its {0} photos or videos are deleted with it.': 'Anche le sue {0} foto o video vengono eliminati.',+ 'Its photo or video moves to the new workout.': 'La sua foto o il suo video passa al nuovo allenamento.',+ 'Its {0} photos or videos move to the new workout.': 'Le sue {0} foto o video passano al nuovo allenamento.',}diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.jsindex 7a46c4ab7..f52297264 100644--- a/frontend/src/locales/ko.js+++ b/frontend/src/locales/ko.js@@ -1598,4 +1598,8 @@ export default {'Previous': '이전','{0} photo or video': '사진·동영상 {0}개','{0} photos or videos': '사진·동영상 {0}개',+ 'Its photo or video is deleted with it.': '첨부된 사진·동영상도 함께 삭제됩니다.',+ 'Its {0} photos or videos are deleted with it.': '첨부된 사진·동영상 {0}개도 함께 삭제됩니다.',+ 'Its photo or video moves to the new workout.': '첨부된 사진·동영상은 새 운동으로 옮겨집니다.',+ 'Its {0} photos or videos move to the new workout.': '첨부된 사진·동영상 {0}개는 새 운동으로 옮겨집니다.',}diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.jsindex b1a49a185..83c4ef00d 100644--- a/frontend/src/locales/pl.js+++ b/frontend/src/locales/pl.js@@ -1598,4 +1598,8 @@ export default {'Previous': 'Wstecz','{0} photo or video': 'Zdjęcia lub filmy: {0}','{0} photos or videos': 'Zdjęcia lub filmy: {0}',+ 'Its photo or video is deleted with it.': 'Jego zdjęcie lub film też zostanie usunięte.',+ 'Its {0} photos or videos are deleted with it.': 'Zdjęcia lub filmy ({0}) też zostaną usunięte.',+ 'Its photo or video moves to the new workout.': 'Zdjęcie lub film przejdzie do nowego treningu.',+ 'Its {0} photos or videos move to the new workout.': 'Zdjęcia lub filmy ({0}) przejdą do nowego treningu.',}diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.jsindex bacdadff5..36029e3b0 100644--- a/frontend/src/locales/pt-BR.js+++ b/frontend/src/locales/pt-BR.js@@ -945,6 +945,8 @@ export const PT_BR_OVERRIDES = {'{0} photo or video has not reached your server yet.': '{0} foto ou vídeo ainda não chegou ao seu servidor.',// --- a logged workout's own photos and videos ---'A progress photo or a form-check video, kept with this workout.': 'Uma foto de progresso ou um vídeo para conferir a técnica, salvos com este treino.',+ 'Its photo or video is deleted with it.': 'A foto ou o vídeo dele também é excluído.',+ 'Its {0} photos or videos are deleted with it.': 'As {0} fotos ou vídeos dele também são excluídos.',}export default { ...pt, ...PT_BR_OVERRIDES }diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.jsindex 9f444ccfc..9c241a9d8 100644--- a/frontend/src/locales/pt.js+++ b/frontend/src/locales/pt.js@@ -1598,4 +1598,8 @@ export default {'Previous': 'Anterior','{0} photo or video': '{0} foto ou vídeo','{0} photos or videos': '{0} fotos ou vídeos',+ 'Its photo or video is deleted with it.': 'A foto ou o vídeo dele também é eliminado.',+ 'Its {0} photos or videos are deleted with it.': 'As {0} fotos ou vídeos dele também são eliminados.',+ 'Its photo or video moves to the new workout.': 'A foto ou o vídeo dele passa para o novo treino.',+ 'Its {0} photos or videos move to the new workout.': 'As {0} fotos ou vídeos dele passam para o novo treino.',}diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.jsindex 2b0d665ba..cced5e39a 100644--- a/frontend/src/locales/ru.js+++ b/frontend/src/locales/ru.js@@ -1598,4 +1598,8 @@ export default {'Previous': 'Назад','{0} photo or video': 'Фото или видео: {0}','{0} photos or videos': 'Фото и видео: {0}',+ 'Its photo or video is deleted with it.': 'Фото или видео тоже будет удалено.',+ 'Its {0} photos or videos are deleted with it.': 'Фото и видео ({0}) тоже будут удалены.',+ 'Its photo or video moves to the new workout.': 'Фото или видео перейдёт в новую тренировку.',+ 'Its {0} photos or videos move to the new workout.': 'Фото и видео ({0}) перейдут в новую тренировку.',}diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.jsindex 27010b344..f682f8bd1 100644--- a/frontend/src/locales/th.js+++ b/frontend/src/locales/th.js@@ -1609,4 +1609,8 @@ export default {'Previous': 'ก่อนหน้า','{0} photo or video': 'รูปภาพหรือวิดีโอ {0} รายการ','{0} photos or videos': 'รูปภาพหรือวิดีโอ {0} รายการ',+ 'Its photo or video is deleted with it.': 'รูปภาพหรือวิดีโอที่แนบไว้จะถูกลบไปด้วย',+ 'Its {0} photos or videos are deleted with it.': 'รูปภาพหรือวิดีโอที่แนบไว้ {0} รายการจะถูกลบไปด้วย',+ 'Its photo or video moves to the new workout.': 'รูปภาพหรือวิดีโอที่แนบไว้จะย้ายไปยังการออกกำลังกายใหม่',+ 'Its {0} photos or videos move to the new workout.': 'รูปภาพหรือวิดีโอที่แนบไว้ {0} รายการจะย้ายไปยังการออกกำลังกายใหม่',}diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.jsindex ab3605bb6..3430e0eb5 100644--- a/frontend/src/locales/tr.js+++ b/frontend/src/locales/tr.js@@ -1598,4 +1598,8 @@ export default {'Previous': 'Önceki','{0} photo or video': '{0} fotoğraf veya video','{0} photos or videos': '{0} fotoğraf veya video',+ 'Its photo or video is deleted with it.': 'Fotoğrafı veya videosu da onunla birlikte silinir.',+ 'Its {0} photos or videos are deleted with it.': '{0} fotoğrafı veya videosu da onunla birlikte silinir.',+ 'Its photo or video moves to the new workout.': 'Fotoğrafı veya videosu yeni antrenmana taşınır.',+ 'Its {0} photos or videos move to the new workout.': '{0} fotoğrafı veya videosu yeni antrenmana taşınır.',}diff --git a/frontend/src/locales/uk.js b/frontend/src/locales/uk.jsindex 15f026892..d57f3100c 100644--- a/frontend/src/locales/uk.js+++ b/frontend/src/locales/uk.js@@ -1595,4 +1595,8 @@ export default {'Previous': 'Назад','{0} photo or video': 'Фото чи відео: {0}','{0} photos or videos': 'Фото й відео: {0}',+ 'Its photo or video is deleted with it.': 'Фото чи відео теж буде видалено.',+ 'Its {0} photos or videos are deleted with it.': 'Фото й відео ({0}) теж буде видалено.',+ 'Its photo or video moves to the new workout.': 'Фото чи відео перейде до нового тренування.',+ 'Its {0} photos or videos move to the new workout.': 'Фото й відео ({0}) перейдуть до нового тренування.',}diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.jsindex b0b54f4e0..dba89b157 100644--- a/frontend/src/locales/zh.js+++ b/frontend/src/locales/zh.js@@ -1598,4 +1598,8 @@ export default {'Previous': '上一个','{0} photo or video': '{0} 个照片或视频','{0} photos or videos': '{0} 个照片或视频',+ 'Its photo or video is deleted with it.': '其中的照片或视频也会一并删除。',+ 'Its {0} photos or videos are deleted with it.': '其中的 {0} 个照片或视频也会一并删除。',+ 'Its photo or video moves to the new workout.': '其中的照片或视频会移到新的训练中。',+ 'Its {0} photos or videos move to the new workout.': '其中的 {0} 个照片或视频会移到新的训练中。',}diff --git a/frontend/src/sheets.backfill.test.jsx b/frontend/src/sheets.backfill.test.jsxindex e85ca6695..fcc83e687 100644--- a/frontend/src/sheets.backfill.test.jsx+++ b/frontend/src/sheets.backfill.test.jsx@@ -56,6 +56,21 @@ describe('log a past workout', () => {expect(useStore.getState().S.active).toBeNull()})+ it('a workout with photos or videos says Replace moves them to the new one', () => {+ const ref = n => ({ kind: 'image', hash: String(n).repeat(64), mime: 'image/webp', size: 10, width: 8, height: 6, at: 1 })+ logPastWorkoutSheet()+ let host = mountTopSheet()+ act(() => { type(host.querySelector('input[type=date]'), todayISO()) })+ act(() => { button(host, 'Continue').click() })+ expect(mountTopSheet().textContent).not.toContain('new workout.')+ useStore.setState(s => ({ S: { ...s.S, workouts: [{ ...s.S.workouts[0], media: [ref(1), ref(2)] }] } }))+ logPastWorkoutSheet()+ host = mountTopSheet()+ act(() => { type(host.querySelector('input[type=date]'), todayISO()) })+ act(() => { button(host, 'Continue').click() })+ expect(mountTopSheet().textContent).toContain('Its 2 photos or videos move to the new workout.')+ })+// The Date and Start-time rows are the only .lrow rows in the app that pair a title with a// fixed-width field and nothing that can give way. A pixel floor under the title column therefore// comes straight out of the field: 104px pushed the date input 23px off a 320px screen, calendardiff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex d9cb40132..355020a87 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -15,7 +15,7 @@ import { buildStarterPlan, starterPlanDays, starterPlanOptions } from './lib/staimport Media, { Thumb } from './components/Media.jsx'import CustomMediaField from './components/CustomMediaField.jsx'import WorkoutMediaSection, { workoutMediaCount } from './components/WorkoutMedia.jsx'-import { mediaOf, normalizeMediaRef, cleanUrl } from './lib/media-refs.js'+import { mediaOf, normalizeMediaRef, cleanUrl, workoutMediaOf } from './lib/media-refs.js'import { syncMedia } from './lib/media-sync.js'import LineChart from './components/LineChart.jsx'import Stepper from './components/Stepper.jsx'@@ -46,7 +46,7 @@ import { joinSessionNoProg } from './lib/session-noprog.js'import { buildCombinedEntries, deriveSessionName } from './lib/session-merge.js'import { workoutsOn, backfillStart, backfillEnd, completeBackfill, historyAsOf, sessionHistory } from './lib/backfill.js'import { moveWorkout, sameWorkout, startTimeOf, durationMinOf, setWorkoutDuration } from './lib/workout-date.js'-import { editCompletedSession, editLeftEmpty } from './lib/session-edit.js'+import { editCompletedSession, editLeftEmpty, editedRecord } from './lib/session-edit.js'import { stampWorkout } from './lib/sync-merge.js'import { weeklyWeights } from './lib/bodyweight.js'import { workoutText } from './lib/workout-text.js'@@ -2068,9 +2068,15 @@ function WorkoutDetail({ w, close }) {<div style={{ height: 10 }} />{/* Matched the way the edits above are, not by id: a workout from before ids has none, andfiltering on `x.id !== undefined` took every other one of them with it. */}- <Button variant="danger" onClick={() => confirmSheet({ title: t('Delete workout?'), message: t('This removes it from your history for good.'), confirmText: t('Delete'), danger: true, onConfirm: () => { update(s => { s.workouts = s.workouts.filter(x => !sameWorkout(x, w)) }); close(); toast(t('Workout deleted')) } })}>{t('Delete workout')}</Button>+ <Button variant="danger" onClick={() => confirmSheet({ title: t('Delete workout?'), message: t('This removes it from your history for good.') + mediaGoesToo(S().workouts.find(x => sameWorkout(x, w))), confirmText: t('Delete'), danger: true, onConfirm: () => { update(s => { s.workouts = s.workouts.filter(x => !sameWorkout(x, w)) }); close(); toast(t('Workout deleted')) } })}>{t('Delete workout')}</Button></>}+// The sentence a workout's Delete adds when its photos and videos go with it — every file the+// record lists, shown or not. Empty when it has none.+function mediaGoesToo(rec) {+ const n = workoutMediaOf(rec, Infinity).length+ return n ? ' ' + t(n === 1 ? 'Its photo or video is deleted with it.' : 'Its {0} photos or videos are deleted with it.', n) : ''+}export const workoutDetailSheet = w => ui().openSheet(close => <WorkoutDetail w={w} close={close} />)/* ============================ calendar ============================ */@@ -2214,14 +2220,20 @@ function LogPastWorkout({ initial, close }) {</>}// Three ways out when the day already has a workout. Replacing with several on that day means-// picking which one; the rest of the day is left alone.+// picking which one; the rest of the day is left alone. A workout with photos or videos says+// they come along.function SameDayChoice({ iso, existing, onReplace, onAdd, close }) {return <div style={{ textAlign: 'center', padding: '4px 0' }}><h3 style={{ marginBottom: 8 }}>{fmtDate(iso, true)}</h3><div className="muted" style={{ marginBottom: 18, lineHeight: 1.5 }}>{t('There is already a workout on that day.')}</div>- {existing.map(w => <div key={w.id} style={{ marginBottom: 8 }}>- <button className="btn danger" onClick={() => onReplace(w.id)}>{existing.length > 1 ? t('Replace') + ' · ' + w.name : t('Replace')}</button>- </div>)}+ {existing.map(w => {+ // Replacing re-logs the sets; the photos and videos move to the new record (completeBackfill).+ const n = workoutMediaOf(w, Infinity).length+ return <div key={w.id} style={{ marginBottom: 8 }}>+ <button className="btn danger" onClick={() => onReplace(w.id)}>{existing.length > 1 ? t('Replace') + ' · ' + w.name : t('Replace')}</button>+ {n > 0 && <div className="small dim samed-media" style={{ marginTop: 4 }}>{t(n === 1 ? 'Its photo or video moves to the new workout.' : 'Its {0} photos or videos move to the new workout.', n)}</div>}+ </div>+ })}<button className="btn primary" onClick={onAdd}>{t('Add as second workout')}</button><div style={{ height: 8 }} /><Button variant="ghost" className="dim" onClick={close}>{t('Cancel')}</Button>@@ -2522,7 +2534,7 @@ export function saveWorkoutEdits(onExit = () => nav('/history')) {if (editLeftEmpty(S().active)) {confirmSheet({title: t('Delete workout?'),- message: t('No sets are left in this workout, so there is nothing to save. Delete it from your history?'),+ message: t('No sets are left in this workout, so there is nothing to save. Delete it from your history?') + mediaGoesToo(editedRecord(S())),confirmText: t('Delete workout'), cancelText: t('Keep editing'), danger: true,onConfirm: () => {useStore.getState().deleteHistoryEdit()diff --git a/frontend/src/sheets.workout-media.test.jsx b/frontend/src/sheets.workout-media.test.jsxindex 26f6d5a5d..942f229aa 100644--- a/frontend/src/sheets.workout-media.test.jsx+++ b/frontend/src/sheets.workout-media.test.jsx@@ -154,6 +154,21 @@ describe('a workout\'s photos and videos', () => {expect(host.textContent).toContain('Kept on this device only')})+ it('Delete workout in the detail sheet says its photos and videos go with it', () => {+ useStore.setState(s => ({ S: { ...s.S, workouts: [workout({ media: [refOf(1)] })] } }))+ workoutDetailSheet(S().workouts[0])+ const host = renderTop()+ act(() => [...host.querySelectorAll('button')].find(b => b.textContent.trim() === 'Delete workout').click())+ expect(renderTop().textContent).toContain('This removes it from your history for good. Its photo or video is deleted with it.')+ })++ it('Delete workout without any says nothing about them', () => {+ workoutDetailSheet(S().workouts[0])+ const host = renderTop()+ act(() => [...host.querySelectorAll('button')].find(b => b.textContent.trim() === 'Delete workout').click())+ expect(renderTop().textContent).not.toContain('deleted with it')+ })+it('the history row shows how many a workout has', () => {const plain = render(<WorkoutRow w={workout()} onClick={() => {}} />)expect(plain.querySelector('.wrow-media')).toBeNull()diff --git a/frontend/src/views/Workout.edit-empty.test.jsx b/frontend/src/views/Workout.edit-empty.test.jsxindex 4e6d70490..b2a11ad6c 100644--- a/frontend/src/views/Workout.edit-empty.test.jsx+++ b/frontend/src/views/Workout.edit-empty.test.jsx@@ -25,9 +25,9 @@ let containerlet sheetRootlet sheetContainer-function renderEditor() {+function renderEditor(extra = {}) {const S = clone(DEF)- S.workouts = [clone(other), clone(saved)]+ S.workouts = [clone(other), { ...clone(saved), ...extra }]S.workoutView = 'list'editCompletedSession(S, 'saved')useStore.setState({ S, user: null })@@ -88,6 +88,14 @@ describe('saving an edit that leaves no set', () => {expect(useUI.getState().toastMsg).toBe('')})+ it('says the workout\'s photos and videos go with it, when it has any', () => {+ const ref = n => ({ kind: 'image', hash: String(n).repeat(64), mime: 'image/webp', size: 10, width: 8, height: 6, at: 1 })+ renderEditor({ media: [ref(1), ref(2), ref(3)] })+ untickAll()+ tapSave()+ expect(renderTopSheet().textContent).toContain('Delete it from your history? Its 3 photos or videos are deleted with it.')+ })+it('Delete workout takes it out of the history and closes the editor', () => {renderEditor()untickAll()