Gym check-in in the browser/PWA too

The feature was gated behind MOBILE because scanning went through the native ML Kit
plugin. iPhone users only have the PWA, so: route, Home card and Settings switch on
every platform; photo import and a live camera sheet decode in the browser with
BarcodeDetector where it exists and jsQR (Apache-2.0, lazy chunk) otherwise. The app
build keeps ML Kit. Round-trip test lean-qr -> jsQR.
This commit is contained in:
Duarte Santos committed 2026-09-04 15:15:31 +02:00
1 parent 0af9f55528
commit aa487d29f4
30 files changed
+315 -47

No files matched your search

+18 -6
View File
@@ -6,13 +6,15 @@ import { uid } from '../lib/format.js'
import { t } from '../lib/i18n.js'
import { canRenderFmt } from '../lib/qr.js'
import { scanCode, importCodeFromImage } from '../lib/scan.js'
import { MOBILE } from '../lib/mobile.js'
import Icon from '../components/Icon.jsx'
import QrCanvas from '../components/QrCanvas.jsx'
import CameraScan from '../components/CameraScan.jsx'
import { Button, TextField } from '../components/ui.jsx'
import { confirmSheet } from '../sheets.jsx'
import { tappable } from '../lib/use-sheet-keyboard.js'
// Gym check-in (mobile-only, reached from the Home "Check in" card). Shows each saved membership
// Gym check-in (reached from the Home "Check in" card; app and PWA alike). Shows each saved membership
// code as a QR the turnstile can read, swiped through horizontally, with a trailing "+" to add
// another. We only ever store the code's value + symbology; the QR is regenerated from it here
// every time (see lib/qr.js), so nothing sensitive is kept as an image.
@@ -83,9 +85,8 @@ function CardFace({ card }) {
/* ------------------------------------------------------------- add-card sheet -- */
// Opens the add-card sheet. Co-located with the view (not sheets.jsx) because the whole feature
// is mobile-only and pulls in the native scanner — keeping it here keeps that out of the shared,
// web-bundled sheets module.
// Opens the add-card sheet. Co-located with the view (not sheets.jsx) because it pulls in the
// scanner paths — keeping it here keeps them out of the shared sheets module.
export function openAddCard() {
useUI.getState().openSheet(close => <AddCard close={close} />)
}
@@ -115,9 +116,20 @@ function AddCard({ close }) {
const commitTyped = () => { if (saveCard({ label, value, fmt: 'qrcode' })) close() }
// Camera scan: hands off to the native scanner, comes back with a value we drop straight into
// the form so the user can still name it before saving.
// Camera scan: in the app, hands off to the native scanner; in a browser, opens our own camera
// sheet on top of this one. Either way the value drops straight into the form so the user can
// still name it before saving.
const doScan = async () => {
if (!MOBILE) {
useUI.getState().openSheet(close => <CameraScan
onCancel={close}
onFound={code => {
close()
if (!canRenderFmt(code.fmt)) { toast(t("That's not a QR code — only QR cards can be shown here")); return }
setValue(code.value)
}} />)
return
}
setBusy(true)
try {
const code = await scanCode()
+3 -5
View File
@@ -10,7 +10,6 @@ import Icon from '../components/Icon.jsx'
import { Button } from '../components/ui.jsx'
import { tappable } from '../lib/use-sheet-keyboard.js'
import { glyphOf } from '../lib/glyphs.js'
import { MOBILE } from '../lib/mobile.js'
// Home = what to do now + a quick glance. Deep charts & history live in Stats.
export default function Home() {
@@ -95,10 +94,9 @@ export default function Home() {
</div>
</div>
{/* Mobile-only: jump to the gym check-in cards (QR membership codes). Shown here as a quick
tap on arrival at the gym; the whole feature folds away in web/demo builds via MOBILE,
and per user via the "Gym check-in" switch in Settings. */}
{MOBILE && S.checkIn !== false && (
{/* Jump to the gym check-in cards (QR membership codes). Shown here as a quick tap on
arrival at the gym; folds away per user via the "Gym check-in" switch in Settings. */}
{S.checkIn !== false && (
<div className="card tappable" style={{ cursor: 'pointer' }} {...tappable(() => nav('/checkin'))}>
<div className="row between">
<div className="row" style={{ gap: 9 }}>
+3 -4
View File
@@ -140,12 +140,11 @@ export default function Settings() {
options={[{ value: MONDAY, label: t('Monday') }, { value: SUNDAY, label: t('Sunday') }]}
value={weekStartOf(S)} onChange={v => update(s => { s.weekStart = v })} />
</Row>
{/* Membership QR codes on Home (views/CheckIn.jsx). Only the app can scan and show them
at a turnstile, so the switch exists only there; off = no Home card, no route. */}
{MOBILE && <Row icon="qr" iconTint="var(--blue)" title={t('Gym check-in')}
{/* Membership QR codes on Home (views/CheckIn.jsx); off = no Home card, no route. */}
<Row icon="qr" iconTint="var(--blue)" title={t('Gym check-in')}
subtitle={t('Show a card on Home with your membership QR codes.')}>
<Switch checked={S.checkIn !== false} onChange={v => update(s => { s.checkIn = v })} />
</Row>}
</Row>
</Section>
{/* ---------- during a workout ---------- */}