Skip to content

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.

Custom exercises: where the browser cannot keep a file (IndexedDB blocked), Add stays in place but off, with the sentence saying why

Duarte Santos70f7636a0b35
diff --git a/frontend/src/components/CustomMediaField.jsx b/frontend/src/components/CustomMediaField.jsx
index eebab2716..41b5d2001 100644
--- a/frontend/src/components/CustomMediaField.jsx
+++ b/frontend/src/components/CustomMediaField.jsx
@@ -56,7 +56,6 @@ export default function CustomMediaField({ media, url, onChange }) {
// MEDIA_UPLOADS=0. Nothing would ever reach it. A config not known yet (an offline start) is
// not that answer — a file picked then waits here and goes up once the server is reached.
const serverLacks = !!user && !!config && !config.media
- const canAdd = storable && !serverLacks
const onFile = async ev => {
const file = ev.target.files && ev.target.files[0]
@@ -96,7 +95,9 @@ export default function CustomMediaField({ media, url, onChange }) {
<Row icon="image" iconTint="var(--blue)" title={t('Photo, GIF or video')} subtitle={subtitle}>
<div className="cmf-act">
{m && <span className="cmf-thumb"><CustomThumb ex={{ custom: true, media: m }} /></span>}
- {canAdd && <Button variant="tinted" size="sm" icon={busy ? undefined : 'image'} disabled={busy} onClick={() => fileRef.current?.click()}>
+ {/* Hidden on a server that will never take a file; shown but off where this browser
+ cannot keep one, with the note below saying why. */}
+ {!serverLacks && <Button variant="tinted" size="sm" icon={busy ? undefined : 'image'} disabled={busy || !storable} onClick={() => fileRef.current?.click()}>
{busy ? t('Loading…') : m ? t('Change') : t('Add')}
</Button>}
{m && <Button variant="ghost" size="sm" icon="xmark" aria-label={t('Remove')} title={t('Remove')} disabled={busy} onClick={() => { setWarning(null); onChange({ media: null }) }} />}
diff --git a/frontend/src/sheets.custom-media.test.jsx b/frontend/src/sheets.custom-media.test.jsx
index 67dfa8c61..ad8d23274 100644
--- a/frontend/src/sheets.custom-media.test.jsx
+++ b/frontend/src/sheets.custom-media.test.jsx
@@ -170,4 +170,15 @@ describe('custom exercise photo, GIF or video, and link', () => {
expect([...form.querySelectorAll('button')].some(b => b.textContent.trim() === 'Add')).toBe(false)
expect(form.querySelector('input[type="url"]')).toBeTruthy() // the link still works
})
+
+ it('where this browser cannot keep files, Add is there but off, and says why', async () => {
+ const blocked = createMediaStore({ name: 'idb', persistent: true, open: async () => false })
+ _setMediaStore(blocked)
+ customExSheet(null)
+ const form = renderTop()
+ await settle()
+ expect(form.textContent).toContain('This browser cannot store photos or videos here.')
+ const add = [...form.querySelectorAll('button')].find(b => b.textContent.trim() === 'Add')
+ expect(add.disabled).toBe(true)
+ })
})