From 3685e279a6f8347ef30275292946386a4e8f6694 Mon Sep 17 00:00:00 2001 From: Sebastian G Date: Mon, 7 Sep 2026 11:21:26 +0200 Subject: [PATCH] removed buggy reorder feature --- frontend/src/index.css | 9 +- frontend/src/lib/pt-br-locale.test.js | 4 +- frontend/src/locales/de.js | 2 + frontend/src/locales/es.js | 2 + frontend/src/locales/fr.js | 2 + frontend/src/locales/hi.js | 2 + frontend/src/locales/hu.js | 2 + frontend/src/locales/it.js | 2 + frontend/src/locales/ko.js | 2 + frontend/src/locales/pl.js | 2 + frontend/src/locales/pt.js | 2 + frontend/src/locales/ru.js | 2 + frontend/src/locales/th.js | 2 + frontend/src/locales/tr.js | 2 + frontend/src/locales/zh.js | 2 + frontend/src/views/CheckIn.jsx | 143 ++++---------------- frontend/src/views/CheckIn.reorder.test.jsx | 8 +- 17 files changed, 60 insertions(+), 130 deletions(-) diff --git a/frontend/src/index.css b/frontend/src/index.css index 140da1b..5168b61 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -1168,10 +1168,11 @@ h4.sec{ .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} +/* reorder row under a card (only shown with >1 card): ◀ position ▶ to nudge the card one slot + along the rail. A plain, reliable control — no drag gesture to fight the horizontal scroll. */ +.ci-reorder{display:flex;align-items:center;justify-content:center;gap:14px;margin-top:2px} +.ci-reorder .ci-pos{font-size:13px;color:var(--label-2);font-variant-numeric:tabular-nums;min-width:44px;text-align:center} +.ci-reorder .iconbtn:disabled{opacity:.3;pointer-events:none} /* 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/lib/pt-br-locale.test.js b/frontend/src/lib/pt-br-locale.test.js index aa131ee..6517939 100644 --- a/frontend/src/lib/pt-br-locale.test.js +++ b/frontend/src/lib/pt-br-locale.test.js @@ -28,10 +28,10 @@ describe('Brazilian Portuguese locale', () => { const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex') expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(631) - expect(inherited).toHaveLength(615) + expect(inherited).toHaveLength(617) // If this fails, review the changed keys and wording before accepting a new hash. From // frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list - expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('8aa678164e6e66010767af67175b1be48139334f54cdd07b75c3f28866a48f57') + expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('6a9e0df18bdd7020d2ad84104a020f2728f68b629933235fae7741b4ec71226d') }) test('does not leak European Portuguese UI terms', () => { diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js index 92b60cf..5e206ae 100644 --- a/frontend/src/locales/de.js +++ b/frontend/src/locales/de.js @@ -1158,6 +1158,8 @@ export default { 'Membership number or code': 'Mitgliedsnummer oder Code', 'Save card': 'Karte speichern', 'Gym card': 'Studio-Karte', + 'Move left': 'Nach links', + 'Move right': 'Nach rechts', '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.', diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js index be1eb37..6b14d47 100644 --- a/frontend/src/locales/es.js +++ b/frontend/src/locales/es.js @@ -1139,6 +1139,8 @@ export default { 'Membership number or code': 'Número de socio o código', 'Save card': 'Guardar tarjeta', 'Gym card': 'Tarjeta del gimnasio', + 'Move left': 'Mover a la izquierda', + 'Move right': 'Mover a la derecha', 'Edit card': 'Editar tarjeta', 'Re-scan': 'Volver a escanear', 'Scan it with the camera or import a photo.': 'Escanéala con la cámara o importa una foto.', diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js index 704d0d1..f3b37a4 100644 --- a/frontend/src/locales/fr.js +++ b/frontend/src/locales/fr.js @@ -1139,6 +1139,8 @@ export default { 'Membership number or code': 'Numéro de membre ou code', 'Save card': 'Enregistrer la carte', 'Gym card': 'Carte de salle', + 'Move left': 'Déplacer à gauche', + 'Move right': 'Déplacer à droite', 'Edit card': 'Modifier la carte', 'Re-scan': 'Rescanner', 'Scan it with the camera or import a photo.': 'Scanne-la avec l’appareil photo ou importe une photo.', diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js index 923066c..936f19a 100644 --- a/frontend/src/locales/hi.js +++ b/frontend/src/locales/hi.js @@ -1139,6 +1139,8 @@ export default { 'Membership number or code': 'मेंबरशिप नंबर या कोड', 'Save card': 'कार्ड सहेजें', 'Gym card': 'जिम कार्ड', + 'Move left': 'बाएँ ले जाएँ', + 'Move right': 'दाएँ ले जाएँ', 'Edit card': 'कार्ड संपादित करें', 'Re-scan': 'फिर से स्कैन करें', 'Scan it with the camera or import a photo.': 'इसे कैमरे से स्कैन करें या फ़ोटो इम्पोर्ट करें।', diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.js index da6702b..4deed29 100644 --- a/frontend/src/locales/hu.js +++ b/frontend/src/locales/hu.js @@ -807,6 +807,8 @@ export default { 'Membership number or code': 'Tagsági szám vagy kód', 'Save card': 'Kártya mentése', 'Gym card': 'Terembérlet', + 'Move left': 'Balra', + 'Move right': 'Jobbra', 'Edit card': 'Kártya szerkesztése', 'Re-scan': 'Újraolvasás', 'Scan it with the camera or import a photo.': 'Olvasd be a kamerával, vagy importálj egy fotót.', diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js index 3a98e9f..64cf97a 100644 --- a/frontend/src/locales/it.js +++ b/frontend/src/locales/it.js @@ -1139,6 +1139,8 @@ export default { 'Membership number or code': 'Numero tessera o codice', 'Save card': 'Salva tessera', 'Gym card': 'Tessera palestra', + 'Move left': 'Sposta a sinistra', + 'Move right': 'Sposta a destra', 'Edit card': 'Modifica tessera', 'Re-scan': 'Scansiona di nuovo', 'Scan it with the camera or import a photo.': 'Scansionala con la fotocamera o importa una foto.', diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js index c411344..2bc5b8f 100644 --- a/frontend/src/locales/ko.js +++ b/frontend/src/locales/ko.js @@ -1139,6 +1139,8 @@ export default { 'Membership number or code': '회원 번호 또는 코드', 'Save card': '카드 저장', 'Gym card': '헬스장 카드', + 'Move left': '왼쪽으로 이동', + 'Move right': '오른쪽으로 이동', 'Edit card': '카드 편집', 'Re-scan': '다시 스캔', 'Scan it with the camera or import a photo.': '카메라로 스캔하거나 사진을 가져오세요.', diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js index 195fed8..c20cfaa 100644 --- a/frontend/src/locales/pl.js +++ b/frontend/src/locales/pl.js @@ -1139,6 +1139,8 @@ export default { 'Membership number or code': 'Numer członkowski lub kod', 'Save card': 'Zapisz kartę', 'Gym card': 'Karta siłowni', + 'Move left': 'Przesuń w lewo', + 'Move right': 'Przesuń w prawo', 'Edit card': 'Edytuj kartę', 'Re-scan': 'Zeskanuj ponownie', 'Scan it with the camera or import a photo.': 'Zeskanuj ją aparatem lub zaimportuj zdjęcie.', diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js index a1eead5..60c8cd1 100644 --- a/frontend/src/locales/pt.js +++ b/frontend/src/locales/pt.js @@ -1139,6 +1139,8 @@ export default { 'Membership number or code': 'Número de sócio ou código', 'Save card': 'Guardar cartão', 'Gym card': 'Cartão do ginásio', + 'Move left': 'Mover para a esquerda', + 'Move right': 'Mover para a direita', 'Edit card': 'Editar cartão', 'Re-scan': 'Digitalizar de novo', 'Scan it with the camera or import a photo.': 'Digitaliza-o com a câmara ou importa uma foto.', diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js index db18d51..cafbfc8 100644 --- a/frontend/src/locales/ru.js +++ b/frontend/src/locales/ru.js @@ -1139,6 +1139,8 @@ export default { 'Membership number or code': 'Номер участника или код', 'Save card': 'Сохранить карту', 'Gym card': 'Карта зала', + 'Move left': 'Влево', + 'Move right': 'Вправо', 'Edit card': 'Изменить карту', 'Re-scan': 'Сканировать заново', 'Scan it with the camera or import a photo.': 'Отсканируйте её камерой или импортируйте фото.', diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.js index a647758..9061748 100644 --- a/frontend/src/locales/th.js +++ b/frontend/src/locales/th.js @@ -815,6 +815,8 @@ export default { 'Membership number or code': 'หมายเลขสมาชิกหรือรหัส', 'Save card': 'บันทึกบัตร', 'Gym card': 'บัตรยิม', + 'Move left': 'ย้ายไปทางซ้าย', + 'Move right': 'ย้ายไปทางขวา', 'Edit card': 'แก้ไขบัตร', 'Re-scan': 'สแกนใหม่', 'Scan it with the camera or import a photo.': 'สแกนด้วยกล้องหรือนำเข้ารูปถ่าย', diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js index b3318ea..d51bbca 100644 --- a/frontend/src/locales/tr.js +++ b/frontend/src/locales/tr.js @@ -1139,6 +1139,8 @@ export default { 'Membership number or code': 'Üyelik numarası veya kodu', 'Save card': 'Kartı kaydet', 'Gym card': 'Salon kartı', + 'Move left': 'Sola taşı', + 'Move right': 'Sağa taşı', 'Edit card': 'Kartı düzenle', 'Re-scan': 'Yeniden tara', 'Scan it with the camera or import a photo.': 'Kamerayla tara ya da bir fotoğraf içe aktar.', diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js index a489dee..053d497 100644 --- a/frontend/src/locales/zh.js +++ b/frontend/src/locales/zh.js @@ -1139,6 +1139,8 @@ export default { 'Membership number or code': '会员号或代码', 'Save card': '保存卡片', 'Gym card': '健身房卡片', + 'Move left': '向左移动', + 'Move right': '向右移动', 'Edit card': '编辑卡片', 'Re-scan': '重新扫描', 'Scan it with the camera or import a photo.': '用相机扫描或导入照片。', diff --git a/frontend/src/views/CheckIn.jsx b/frontend/src/views/CheckIn.jsx index b62f253..546b293 100644 --- a/frontend/src/views/CheckIn.jsx +++ b/frontend/src/views/CheckIn.jsx @@ -1,4 +1,4 @@ -import { useEffect, useLayoutEffect, useRef, useState } from 'react' +import { useLayoutEffect, useRef, useState } from 'react' import { useNavigate } from 'react-router-dom' import { useStore } from '../store/useStore.js' import { useUI } from '../store/useUI.js' @@ -13,16 +13,9 @@ import CameraScan from '../components/CameraScan.jsx' import { Button, TextField } from '../components/ui.jsx' import { confirmSheet } from '../sheets.jsx' -// 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. -export const CI_LONG_PRESS_MS = 380 -export const CI_DRAG_SLOP = 8 - // Move the card at `from` to sit at index `to`, returning a new array (the input is left alone). -// This is the whole of the reorder once the drop target is known — kept as a pure function, apart -// from the pointer maths that computes `to`, so the ordering contract can be tested without a DOM. -// Out-of-range or no-op moves return an unchanged copy rather than throwing. +// Backs the on-card ◀ ▶ reorder buttons. Out-of-range or no-op moves return an unchanged copy +// rather than throwing, so a button at either end is simply inert. export function moveGymCard(cards, from, to) { const next = [...cards] if (from < 0 || from >= next.length) return next @@ -41,8 +34,8 @@ export function moveGymCard(cards, from, to) { // 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. +// code that silently fails at the turnstile. An existing card can be edited (rename, re-scan), and +// with more than one card each carries ◀ ▶ buttons to nudge its position along the rail. export default function CheckIn() { const nav = useNavigate() const cards = useStore(s => s.S.gymCards) || [] @@ -50,7 +43,6 @@ export default function CheckIn() { const update = useStore(s => s.update) const railRef = useRef(null) const [active, setActive] = useState(0) - const reorder = useRailReorder(railRef, cards) // 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. @@ -85,13 +77,14 @@ export default function CheckIn() { -
- {cards.map(card => + {cards.map((card, i) => )} - @@ -103,10 +96,6 @@ export default function CheckIn() { = cards.length ? ' on' : '')} />
} - {cards.length > 1 &&
- {t('Long-press a card to reorder')} -
} - {!cards.length &&
{t('Import a photo of your membership card or scan it with the camera. No extra app needed at the gym — just open this screen.')}
} @@ -115,8 +104,10 @@ export default function CheckIn() { // One saved card: its label centered above the QR, and the raw value underneath (handy when a // reader is fussy and a staff member types it in). The edit button opens the same sheet used to -// add a card, pre-filled; the trash button removes it after a confirm. -function CardFace({ card, dragging }) { +// add a card, pre-filled; the trash button removes it after a confirm. With more than one card, a +// row of ◀ ▶ buttons nudges this card one slot along the rail — a plain, reliable reorder that +// doesn't fight the rail's horizontal scroll the way a drag gesture did. +function CardFace({ card, index, count }) { const update = useStore(s => s.update) const remove = () => confirmSheet({ title: t('Remove this card?'), @@ -128,111 +119,23 @@ function CardFace({ card, dragging }) { if (s.lastGymCardId === card.id) s.lastGymCardId = (s.gymCards[0]?.id) || null }), }) - return
+ const move = to => update(s => { s.gymCards = moveGymCard(s.gymCards, index, to) }) + return
- +
{card.label}
- +
{card.value}
+ {count > 1 &&
+ + {index + 1} / {count} + +
}
} -/* ------------------------------------------------------- long-press reorder -- */ - -// Horizontal drag-to-reorder for the rail. A long-press lifts the card under the finger; moving -// then drops it before whichever card its centre passes. Kept self-contained (not the routine -// editor's vertical hook) because the rail is a scroll-snap track, not a stacked list — the -// gesture maths is horizontal and the scroll container is the element itself. -// -// Returns { dragging, dragId } for styling; the reorder itself is committed to the store on drop. -function useRailReorder(railRef, cards) { - const [state, setState] = useState({ dragging: false, dragId: null }) - const cardsRef = useRef(cards) - cardsRef.current = cards - - useEffect(() => { - const rail = railRef.current - if (!rail) return undefined - let gesture = null - - const clearTimer = () => { if (gesture?.timer) { clearTimeout(gesture.timer); gesture.timer = null } } - - const lift = g => { - g.active = true - setState({ dragging: true, dragId: g.id }) - } - - // Drop before the card whose horizontal centre the pointer has passed, then persist the new - // order. A no-op move (dropped in place) still clears state but writes nothing. - const drop = g => { - const list = cardsRef.current - const from = list.findIndex(c => c.id === g.id) - if (from >= 0) { - const cardEls = [...rail.querySelectorAll('[data-ci-card]')] - const centres = cardEls.map(el => { const r = el.getBoundingClientRect(); return r.left + r.width / 2 }) - const to = centres.reduce((n, cx, i) => n + (i !== from && g.lastX > cx ? 1 : 0), 0) - if (to !== from) useStore.getState().update(s => { s.gymCards = moveGymCard(s.gymCards, from, to) }) - } - setState({ dragging: false, dragId: null }) - } - - const onPointerDown = event => { - if (event.isPrimary === false || (event.pointerType === 'mouse' && event.button !== 0)) return - const target = event.target - if (!target?.closest || target.closest('button,a,input,textarea,select,[data-nodrag]')) return - const cardEl = target.closest('[data-ci-card]') - if (!cardEl || !rail.contains(cardEl)) return - gesture = { id: cardEl.dataset.ciId, pointerId: event.pointerId, startX: event.clientX, lastX: event.clientX, active: false, timer: null } - gesture.timer = window.setTimeout(() => lift(gesture), CI_LONG_PRESS_MS) - } - - const onPointerMove = event => { - if (!gesture || event.pointerId !== gesture.pointerId) return - gesture.lastX = event.clientX - if (!gesture.active) { - // Moved before the long-press fired — it's a swipe of the rail, not a reorder. Bail so the - // native scroll-snap takes over. - if (Math.abs(event.clientX - gesture.startX) > CI_DRAG_SLOP) { clearTimer(); gesture = null } - return - } - event.preventDefault() - } - - const onPointerUp = event => { - if (!gesture || event.pointerId !== gesture.pointerId) return - clearTimer() - if (gesture.active) drop(gesture) - gesture = null - } - - const cancel = () => { if (gesture) { clearTimer(); if (gesture.active) setState({ dragging: false, dragId: null }); gesture = null } } - - // Once a drag is active the rail must not also pan-scroll; a non-passive touchmove is the only - // thing that can stop the browser claiming the gesture as a horizontal pan. - const onTouchMove = event => { if (gesture?.active) event.preventDefault() } - - document.addEventListener('pointerdown', onPointerDown) - document.addEventListener('pointermove', onPointerMove, { passive: false }) - document.addEventListener('pointerup', onPointerUp) - document.addEventListener('pointercancel', cancel) - rail.addEventListener('touchmove', onTouchMove, { passive: false }) - window.addEventListener('blur', cancel) - return () => { - cancel() - document.removeEventListener('pointerdown', onPointerDown) - document.removeEventListener('pointermove', onPointerMove) - document.removeEventListener('pointerup', onPointerUp) - document.removeEventListener('pointercancel', cancel) - rail.removeEventListener('touchmove', onTouchMove) - window.removeEventListener('blur', cancel) - } - }, [railRef]) - - return state -} - /* ------------------------------------------------------------- add/edit sheet -- */ // Opens the add-card sheet. Co-located with the view (not sheets.jsx) because it pulls in the diff --git a/frontend/src/views/CheckIn.reorder.test.jsx b/frontend/src/views/CheckIn.reorder.test.jsx index 6e3d97d..9ce35aa 100644 --- a/frontend/src/views/CheckIn.reorder.test.jsx +++ b/frontend/src/views/CheckIn.reorder.test.jsx @@ -1,10 +1,10 @@ // @vitest-environment happy-dom // @vitest-environment happy-dom -// The rail's reorder maths. The drop handler in CheckIn.jsx turns a pointer position into a target -// index; moveGymCard is the pure part that then rearranges the array. These tests cover that -// contract — a move is a splice, the input is never mutated, and degenerate moves (in place, out of -// range) are safe no-ops — the same shape reorderRoutineUnit is tested to. +// moveGymCard backs the on-card ◀ ▶ reorder buttons: it moves the card at `from` to index `to`, +// returning a new array. These tests cover that contract — a move is a splice, the input is never +// mutated, and degenerate moves (in place, out of range, past the ends) are safe no-ops, so a +// button at either end of the rail is simply inert. // // moveGymCard itself is pure, but importing CheckIn.jsx loads the store (which registers a // visibilitychange listener at module load) and the scanner/sheet modules, so the file runs under