diff --git a/frontend/src/index.css b/frontend/src/index.css index a66b8f4..140da1b 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -1160,9 +1160,18 @@ h4.sec{ scroll-snap-align:center;flex:0 0 100%;box-sizing:border-box; background:var(--surface);border-radius:var(--r-xl);padding:22px 18px; display:flex;flex-direction:column;align-items:center;gap:14px; + transition:transform var(--fast),box-shadow var(--fast),opacity var(--fast); } -.ci-card .ci-label{font-size:19px;font-weight:600;letter-spacing:-.014em;text-align:center} +/* header row: edit — title — trash. The two icon buttons are equal fixed widths so the title, + flexed between them, stays optically centered on the card no matter how long it is. */ +.ci-card-hd{display:flex;align-items:center;gap:8px;width:100%} +.ci-card-btn{width:30px;height:30px;font-size:14px;flex:none} +.ci-card .ci-label{flex:1;min-width:0;font-size:19px;font-weight:600;letter-spacing:-.014em;text-align:center;overflow-wrap:anywhere} .ci-card .ci-value{font-size:14px;color:var(--label-2);word-break:break-all;text-align:center;font-variant-numeric:tabular-nums} +/* long-press reorder: the lifted card floats above the rest, which dim slightly to recede. */ +.ci-rail.is-reordering{scroll-snap-type:none} +.ci-rail.is-reordering .ci-card:not(.is-dragging){opacity:.6} +.ci-card.is-dragging{transform:scale(1.03);box-shadow:0 12px 30px -8px rgba(0,0,0,.4);z-index:2} /* The QR itself: lean-qr paints 1 module per pixel, so scale it up with the browser's nearest-neighbour so every module stays a crisp square instead of a blurred blob. White quiet-zone padding is baked in by the renderer; the plate underneath just frames it. */ diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js index 5b0e2ff..92b60cf 100644 --- a/frontend/src/locales/de.js +++ b/frontend/src/locales/de.js @@ -1158,6 +1158,13 @@ export default { 'Membership number or code': 'Mitgliedsnummer oder Code', 'Save card': 'Karte speichern', 'Gym card': 'Studio-Karte', + 'Edit card': 'Karte bearbeiten', + 'Re-scan': 'Neu scannen', + 'Scan it with the camera or import a photo.': 'Scanne sie mit der Kamera oder importiere ein Foto.', + 'Import a photo of your membership card or scan it with the camera. No extra app needed at the gym — just open this screen.': 'Importiere ein Foto deiner Mitgliedskarte oder scanne sie mit der Kamera. Keine zusätzliche App im Studio nötig — öffne einfach diesen Bildschirm.', + 'Long-press a card to reorder': 'Karte gedrückt halten, um sie umzusortieren', + 'Card updated': 'Karte aktualisiert', + 'Scan or import a code first': 'Zuerst einen Code scannen oder importieren', 'Card added': 'Karte hinzugefügt', 'Nothing to save yet': 'Noch nichts zu speichern', "That's not a QR code — only QR cards can be shown here": 'Das ist kein QR-Code — hier lassen sich nur QR-Karten anzeigen', diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.js index 33dd4a7..c2c7686 100644 --- a/frontend/src/store/useStore.js +++ b/frontend/src/store/useStore.js @@ -55,6 +55,10 @@ export const DEF = { // kind of code the gym issued. Just data, so it syncs and backs up like everything else. // [{ id, label, value, fmt }] gymCards: [], + // The card the check-in screen last settled on, so it reopens where you left it (handy when + // you have more than one gym). Holds a gymCards id, or null before any card exists / is chosen; + // a stale id (card since removed) is simply ignored by the view. + lastGymCardId: null, // Whether the check-in feature is on at all (Settings toggle). Off hides the Home // card and the /checkin route; the saved gymCards stay so turning it back on restores them. // Defaults on; an older profile without the key reads as on (`!== false`). diff --git a/frontend/src/views/CheckIn.jsx b/frontend/src/views/CheckIn.jsx index e40d01e..6fb60f3 100644 --- a/frontend/src/views/CheckIn.jsx +++ b/frontend/src/views/CheckIn.jsx @@ -1,4 +1,4 @@ -import { useEffect, useRef, useState } from 'react' +import { useEffect, useLayoutEffect, useRef, useState } from 'react' import { useNavigate } from 'react-router-dom' import { useStore } from '../store/useStore.js' import { useUI } from '../store/useUI.js' @@ -12,25 +12,54 @@ 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 (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. +// Long-press before a card lifts for reordering, and the finger travel that instead counts as a +// horizontal swipe of the rail. Mirrors the routine-editor drag (views/RoutineEdit.jsx) so the +// gesture feels the same across the app. +const CI_LONG_PRESS_MS = 380 +const CI_DRAG_SLOP = 8 + +// 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. +// +// The rail reopens on the card you used last (lastGymCardId) and remembers the one you settle on, +// so a member with two gyms lands on the right code without swiping. Cards are added by scanning +// or importing a photo only — never by typing a code, which is too easy to fat-finger into a +// code that silently fails at the turnstile. An existing card can be edited (rename, re-scan) and +// the whole rail can be reordered with a long-press drag. export default function CheckIn() { const nav = useNavigate() const cards = useStore(s => s.S.gymCards) || [] + const lastId = useStore(s => s.S.lastGymCardId) + const update = useStore(s => s.update) const railRef = useRef(null) const [active, setActive] = useState(0) + const reorder = useRailReorder(railRef, cards) - // Which card the horizontal scroll has settled on — drives the little dots. Reading it off the - // scroll position keeps the rail itself the single control; no separate paging state to sync. + // Open on the last-used card. Done once on mount (and whenever the saved id changes from + // elsewhere) with layout effect so the jump happens before paint — no visible scroll from 0. + // A stale id (its card was removed) falls back to the first card. + useLayoutEffect(() => { + const rail = railRef.current + if (!rail || !cards.length) return + const idx = Math.max(0, cards.findIndex(c => c.id === lastId)) + rail.scrollLeft = idx * rail.clientWidth + setActive(idx) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [lastId, cards.length]) + + // Which card the horizontal scroll has settled on — drives the dots and gets remembered as the + // last-used card. Reading it off the scroll position keeps the rail itself the single control. const onScroll = () => { const rail = railRef.current if (!rail) return const i = Math.round(rail.scrollLeft / rail.clientWidth) + if (i === active) return setActive(i) + const card = cards[i] + if (card && card.id !== lastId) update(s => { s.lastGymCardId = card.id }, false) } return