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.

Settings: the account id copies on a plain-http LAN address too, where password sign-in is the way in (#219, #118)

Duarte Santosd122171a928b
diff --git a/frontend/src/views/Settings.account-id.test.jsx b/frontend/src/views/Settings.account-id.test.jsx
index 6093ef785..9f7e88253 100644
--- a/frontend/src/views/Settings.account-id.test.jsx
+++ b/frontend/src/views/Settings.account-id.test.jsx
@@ -104,6 +104,19 @@ describe('Settings → Account ID', () => {
expect(idRow(page).textContent).toContain(ID)
})
+ it('plain http without the Clipboard API still copies it, the way a selection copy does', async () => {
+ Object.defineProperty(navigator, 'clipboard', { value: undefined, configurable: true })
+ const execCommand = vi.fn(() => true)
+ Object.defineProperty(document, 'execCommand', { value: execCommand, configurable: true })
+ try {
+ const page = mount(<Settings />)
+ act(() => idRow(page).click())
+ await tick()
+ expect(execCommand).toHaveBeenCalledWith('copy')
+ expect(mocks.toast).toHaveBeenCalledWith('Account ID copied')
+ } finally { delete document.execCommand }
+ })
+
it('a guest has no account and no id', () => {
mocks.user = null
const page = mount(<Settings />)
diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsx
index 053f5527c..5617a816e 100644
--- a/frontend/src/views/Settings.jsx
+++ b/frontend/src/views/Settings.jsx
@@ -4,6 +4,7 @@ import { useStore, DEF, hasData } from '../store/useStore.js'
import { workoutControls } from '../lib/workout-controls.js'
import { convertStateUnit } from '../lib/units.js'
import { speedUnitOf } from '../lib/speed.js'
+import { copyText } from '../lib/clipboard.js'
import { useUI } from '../store/useUI.js'
import { ACCENTS, todayISO, localTZ, weekStartOf, MONDAY, SUNDAY } from '../lib/format.js'
import { effortOf } from '../lib/history.js'
@@ -750,12 +751,13 @@ function EquipmentCard({ S, update }) {
// The account's id, small and one tap to copy (#219). It is what an admin puts in ADMIN_UIDS,
// and the one thing that names an account beyond doubt when someone asks their admin for help:
-// display names are free text and need not be unique. Where the clipboard is out of reach the
-// id is still on screen to read out.
+// display names are free text and need not be unique. copyText also reaches the clipboard on a
+// plain-http LAN address, where the Clipboard API is missing and password sign-in (#118) is the
+// usual way in; where no copy works at all the id is still on screen to read out.
function AccountIdRow({ id }) {
const toast = useUI(s => s.toast)
if (!id) return null
- const copy = () => navigator.clipboard?.writeText(id).then(() => toast(t('Account ID copied')), () => {})
+ const copy = async () => { if (await copyText(id)) toast(t('Account ID copied')) }
return <Row icon="person" iconTint="var(--grey)" title={t('Account ID')} subtitle={<span className="acct-id">{id}</span>} onClick={copy} />
}