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
Custom exercises: the sizes in the editor and in Settings use the language's own decimal mark
Duarte Santosf0eb1c38cab7
diff --git a/frontend/src/components/CustomMediaField.jsx b/frontend/src/components/CustomMediaField.jsxindex 835200c49..d35452831 100644--- a/frontend/src/components/CustomMediaField.jsx+++ b/frontend/src/components/CustomMediaField.jsx@@ -85,8 +85,9 @@ export default function CustomMediaField({ media, url, onChange }) {}// "0:07 · 2.4 MB": the length of a clip or an animation, and the size of the file itself (the- // unit through the packs' own "{0} MB", so it reads Mo, МБ, م.ب where it should).- const sizeLine = m ? [m.dur != null && m.kind !== 'image' ? fmtClip(m.dur) : null, t('{0} MB', Math.max(0.1, Math.round((m.size / MB) * 10) / 10).toFixed(1))].filter(Boolean).join(' · ') : null+ // unit through the packs' own "{0} MB", so it reads Mo, МБ, م.ب where it should, and the+ // number with the language's own decimal mark).+ const sizeLine = m ? [m.dur != null && m.kind !== 'image' ? fmtClip(m.dur) : null, t('{0} MB', fmtMB(Math.max(0.1, m.size / MB), { fixed: true }))].filter(Boolean).join(' · ') : nullconst subtitle = m? <span className="cmf-sub"><Icon name={KIND_ICON[m.kind]} />{sizeLine}</span>: t('Optional — a picture makes it easier to spot in a list.')diff --git a/frontend/src/lib/media-limits.js b/frontend/src/lib/media-limits.jsindex e31bf99cc..9cc15fae2 100644--- a/frontend/src/lib/media-limits.js+++ b/frontend/src/lib/media-limits.js@@ -7,6 +7,8 @@* Every MB is 2^20 bytes on both sides, and the server's values may be fractional.*/+import { dateLocale } from './i18n-core.js'+export const MB = 1024 * 1024export const DEFAULT_LIMITS = Object.freeze({@@ -39,5 +41,8 @@ export function limitsFrom(config) {return out}-/** "2", "0.5", "40" — a cap as the error message says it. */-export const fmtMB = mb => String(Math.round(mb * 10) / 10)+/** "2", "0.5", "40" — a size in MB to one decimal, with the language's own decimal mark ("0,5"+ * in German and French). `fixed` keeps the one decimal on a whole number ("2.0"), for a line+ * that lists sizes. */+export const fmtMB = (mb, { fixed = false } = {}) =>+ (Math.round(mb * 10) / 10).toLocaleString(dateLocale(), { minimumFractionDigits: fixed ? 1 : 0, maximumFractionDigits: 1 })diff --git a/frontend/src/lib/media-limits.test.js b/frontend/src/lib/media-limits.test.jsnew file mode 100644index 000000000..45ebbc543--- /dev/null+++ b/frontend/src/lib/media-limits.test.js@@ -0,0 +1,26 @@+// The sizes the editor and Settings say ("0.2 MB", "12.5 of 200 MB used") are written with the+// language's own decimal mark, like every other number in the app.+import { afterEach, describe, expect, it } from 'vitest'+import { fmtMB } from './media-limits.js'+import { _setLangState } from './i18n-core.js'++afterEach(() => _setLangState('en', null, null, null))++describe('fmtMB', () => {+ it('rounds to one decimal and drops it on a whole number, unless asked to keep it', () => {+ expect(fmtMB(0.5)).toBe('0.5')+ expect(fmtMB(2)).toBe('2')+ expect(fmtMB(2.04)).toBe('2')+ expect(fmtMB(2, { fixed: true })).toBe('2.0')+ })++ it('writes the decimal mark of the language', () => {+ _setLangState('de', {}, null, null)+ expect(fmtMB(0.5)).toBe('0,5')+ expect(fmtMB(2, { fixed: true })).toBe('2,0')+ _setLangState('fr', {}, null, null)+ expect(fmtMB(12.5)).toBe('12,5')+ _setLangState('ar', {}, null, null)+ expect(fmtMB(0.5)).toMatch(/^0.5$/) // Latin digits, as everywhere in the app+ })+})diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsxindex e107e8a79..51b35436c 100644--- a/frontend/src/views/Settings.jsx+++ b/frontend/src/views/Settings.jsx@@ -20,7 +20,7 @@ import { referencedFiles } from '../lib/media-refs.js'import { mediaStore } from '../lib/media-store.js'import { syncMedia, fetchToStore } from '../lib/media-sync.js'import { getMediaStatus, subscribeMediaStatus, pendingRefCount } from '../lib/media-owed.js'-import { limitsFrom, MB } from '../lib/media-limits.js'+import { limitsFrom, fmtMB, MB } from '../lib/media-limits.js'import { setRestAccent } from '../lib/rest-alert.js'import { checkForUpdate, downloadAndInstall } from '../lib/update.js'import { forgetCoach } from '../lib/coach-api.js'@@ -840,7 +840,7 @@ function MediaRow() {const pending = remote ? pendingRefCount(S) : 0const u = status.usageconst usage = remote && u && u.quotaBytes > 0- ? t('{0} of {1} MB used on your server', Math.round((u.bytes || 0) / MB * 10) / 10, Math.round(u.quotaBytes / MB))+ ? t('{0} of {1} MB used on your server', fmtMB((u.bytes || 0) / MB), fmtMB(Math.round(u.quotaBytes / MB))): nullconst sub = remote? [usage, pending ? t('{0} waiting to upload', pending) : null].filter(Boolean).join(' · ') || undefined