From c79bba935b309927361dce4c29d99168e9dbb2ca Mon Sep 17 00:00:00 2001 From: rameen Date: Fri, 18 Sep 2026 14:12:56 +0330 Subject: [PATCH 1/2] Touch on the FDI chart no longer selects a tooth when you scroll. --- .../components/ui/treatment/FdiToothChart.tsx | 155 ++++++++++++++---- 1 file changed, 126 insertions(+), 29 deletions(-) diff --git a/frontend/src/components/ui/treatment/FdiToothChart.tsx b/frontend/src/components/ui/treatment/FdiToothChart.tsx index 2a23e7d..59e5c8b 100644 --- a/frontend/src/components/ui/treatment/FdiToothChart.tsx +++ b/frontend/src/components/ui/treatment/FdiToothChart.tsx @@ -1,6 +1,14 @@ 'use client'; -import { useEffect, useId, useRef, useState, type CSSProperties, type ReactNode } from 'react'; +import { + useEffect, + useId, + useRef, + useState, + type CSSProperties, + type PointerEvent as ReactPointerEvent, + type ReactNode, +} from 'react'; import { useTranslations } from 'next-intl'; import { Info, Plus } from 'lucide-react'; import { Button } from '@/components/ui/shared/Button'; @@ -24,6 +32,8 @@ const TOOTH_NUMBER_GAP = 'mt-1'; const REALISTIC_NUMBER_GAP = '2mm'; /** Tight interproximal gap between tooth columns. */ const TOOTH_GAP = 'gap-x-px'; +/** Max finger movement (px) still counted as a tap; beyond this, treat as scroll. */ +const TOUCH_TAP_SLOP_PX = 10; /** * Centers a mark on the inline-end edge of a tooth column (between this tooth * and the next in flex order). Logical `end` + 0-width flex stays correct in LTR and RTL. @@ -31,6 +41,13 @@ const TOOTH_GAP = 'gap-x-px'; const EDGE_MARK_ANCHOR = 'absolute inset-y-0 end-0 z-10 w-0 flex items-center justify-center'; +type TouchPendingTap = { + pointerId: number; + startX: number; + startY: number; + activate: () => void; +}; + function quadrantMirrored(fdi: FdiToothId): boolean { const q = fdi[0]; return q === '2' || q === '3'; @@ -67,6 +84,7 @@ function ToothNumber({ interactive, disabled, onActivate, + onBeginPointer, }: { fdi: FdiToothId; selected: boolean; @@ -76,6 +94,7 @@ function ToothNumber({ interactive: boolean; disabled: boolean; onActivate: (keys: { shiftKey: boolean; ctrlKey: boolean }) => void; + onBeginPointer: (e: ReactPointerEvent) => void; }) { const className = `text-[10px] tabular-nums text-center leading-none ${colorClass}`; const boxStyle: CSSProperties = { width: `${widthRem}rem`, ...style }; @@ -98,8 +117,7 @@ function ToothNumber({ }} onPointerDown={(e) => { if (e.button !== 0) return; - e.preventDefault(); - onActivate({ shiftKey: e.shiftKey, ctrlKey: e.ctrlKey || e.metaKey }); + onBeginPointer(e); }} onKeyDown={(e) => { if (e.key !== 'Enter' && e.key !== ' ') return; @@ -308,23 +326,69 @@ export function FdiToothChart({ const uid = useId().replace(/:/g, ''); const [hintOpen, setHintOpen] = useState(false); const paintingRef = useRef(false); + const touchPendingRef = useRef(null); const archPeak = 8; const interactive = !readOnly && (Boolean(onToggle) || Boolean(onAssignPointer)); const linkInteractive = interactive && Boolean(onToggleLink); const isDisabled = disabled || readOnly; useEffect(() => { - const endPaint = () => { - paintingRef.current = false; + const slopSq = TOUCH_TAP_SLOP_PX * TOUCH_TAP_SLOP_PX; + const onMove = (e: PointerEvent) => { + const pending = touchPendingRef.current; + if (!pending || e.pointerId !== pending.pointerId) return; + const dx = e.clientX - pending.startX; + const dy = e.clientY - pending.startY; + if (dx * dx + dy * dy > slopSq) { + touchPendingRef.current = null; + } }; - window.addEventListener('pointerup', endPaint); - window.addEventListener('pointercancel', endPaint); + const onUp = (e: PointerEvent) => { + paintingRef.current = false; + const pending = touchPendingRef.current; + if (!pending || e.pointerId !== pending.pointerId) return; + touchPendingRef.current = null; + pending.activate(); + }; + const onCancel = (e: PointerEvent) => { + paintingRef.current = false; + const pending = touchPendingRef.current; + if (pending && e.pointerId === pending.pointerId) { + touchPendingRef.current = null; + } + }; + window.addEventListener('pointermove', onMove); + window.addEventListener('pointerup', onUp); + window.addEventListener('pointercancel', onCancel); return () => { - window.removeEventListener('pointerup', endPaint); - window.removeEventListener('pointercancel', endPaint); + window.removeEventListener('pointermove', onMove); + window.removeEventListener('pointerup', onUp); + window.removeEventListener('pointercancel', onCancel); }; }, []); + /** Mouse/pen: activate immediately. Touch: defer until pointerup if movement stays within slop. */ + const beginToothPointer = ( + e: ReactPointerEvent, + opts: { startPaint: boolean; activate: () => void }, + ) => { + if (e.pointerType === 'touch') { + touchPendingRef.current = { + pointerId: e.pointerId, + startX: e.clientX, + startY: e.clientY, + activate: opts.activate, + }; + return; + } + e.preventDefault(); + e.stopPropagation(); + if (opts.startPaint && !e.shiftKey) { + paintingRef.current = true; + } + opts.activate(); + }; + const toothSizeClass = (fdi: FdiToothId) => toothSize(fdi); const archOffset = (index: number, count: number, upper?: boolean) => { @@ -531,14 +595,11 @@ export function FdiToothChart({ }} onPointerDown={(e) => { if (e.button !== 0) return; - e.preventDefault(); - e.stopPropagation(); - if (onAssignPointer && !e.shiftKey) { - paintingRef.current = true; - } - activateTooth({ - shiftKey: e.shiftKey, - ctrlKey: e.ctrlKey || e.metaKey, + const shiftKey = e.shiftKey; + const ctrlKey = e.ctrlKey || e.metaKey; + beginToothPointer(e, { + startPaint: Boolean(onAssignPointer), + activate: () => activateTooth({ shiftKey, ctrlKey }), }); }} onPointerEnter={() => { @@ -665,6 +726,24 @@ export function FdiToothChart({ } onToggle?.(fdi, { shiftKey: keys.shiftKey }); }} + onBeginPointer={(e) => { + const shiftKey = e.shiftKey; + const ctrlKey = e.ctrlKey || e.metaKey; + beginToothPointer(e, { + startPaint: false, + activate: () => { + if (onAssignPointer) { + onAssignPointer(fdi, { + shiftKey, + ctrlKey, + paint: ctrlKey, + }); + return; + } + onToggle?.(fdi, { shiftKey }); + }, + }); + }} /> ))} @@ -683,19 +762,37 @@ export function FdiToothChart({ style={numberStyle(fdi, selected.has(fdi))} interactive={interactive} disabled={isDisabled} - onActivate={(keys) => { - if (onAssignPointer) { - onAssignPointer(fdi, { - shiftKey: keys.shiftKey, - ctrlKey: keys.ctrlKey, - paint: keys.ctrlKey, + onActivate={(keys) => { + if (onAssignPointer) { + onAssignPointer(fdi, { + shiftKey: keys.shiftKey, + ctrlKey: keys.ctrlKey, + paint: keys.ctrlKey, + }); + return; + } + onToggle?.(fdi, { shiftKey: keys.shiftKey }); + }} + onBeginPointer={(e) => { + const shiftKey = e.shiftKey; + const ctrlKey = e.ctrlKey || e.metaKey; + beginToothPointer(e, { + startPaint: false, + activate: () => { + if (onAssignPointer) { + onAssignPointer(fdi, { + shiftKey, + ctrlKey, + paint: ctrlKey, + }); + return; + } + onToggle?.(fdi, { shiftKey }); + }, }); - return; - } - onToggle?.(fdi, { shiftKey: keys.shiftKey }); - }} - /> - ))} + }} + /> + ))}
Date: Sat, 19 Sep 2026 01:05:14 +0330 Subject: [PATCH 2/2] Make Treatment and lab Cases usable at phone and tablet widths. --- frontend/messages/en.json | 1 + frontend/messages/fa.json | 1 + frontend/messages/nl.json | 1 + .../src/components/ui/lab/CaseCreatePanel.tsx | 3 +- .../src/components/ui/lab/CaseDetailPanel.tsx | 76 ++++++++++--------- .../components/ui/lab/CaseToothChartPanel.tsx | 22 +++--- frontend/src/components/ui/lab/CasesPage.tsx | 24 +++--- .../ui/lab/LabCaseProsthesisGroupsList.tsx | 2 +- .../ui/shared/MobileDetailBackButton.tsx | 18 ++++- .../components/ui/treatment/FdiToothChart.tsx | 6 +- .../ui/treatment/ProsthesisJobPopover.tsx | 14 ++-- .../ui/treatment/TreatmentWorkspace.tsx | 38 +++++++++- 12 files changed, 131 insertions(+), 75 deletions(-) diff --git a/frontend/messages/en.json b/frontend/messages/en.json index fecb28e..d45ec16 100644 --- a/frontend/messages/en.json +++ b/frontend/messages/en.json @@ -725,6 +725,7 @@ "noAppointment": "No appointment", "walkIn": "Walk-in", "newTreatment": "New treatment", + "mobileOpenRail": "Patient / history", "newTreatmentPatientPrompt": "Who is this visit for?", "newTreatmentUseCurrent": "Use {name}", "newTreatmentUseCurrentHint": "Start a new visit for the patient already open on this page.", diff --git a/frontend/messages/fa.json b/frontend/messages/fa.json index 4fa6ab4..976a4fa 100644 --- a/frontend/messages/fa.json +++ b/frontend/messages/fa.json @@ -726,6 +726,7 @@ "noAppointment": "بدون نوبت", "walkIn": "بدون نوبت (مراجع)", "newTreatment": "درمان جدید", + "mobileOpenRail": "بیمار / سابقه", "newTreatmentPatientPrompt": "این ویزیت برای چه کسی است؟", "newTreatmentUseCurrent": "استفاده از {name}", "newTreatmentUseCurrentHint": "ویزیت جدیدی برای بیماری که همین حالا در این صفحه باز است شروع کنید.", diff --git a/frontend/messages/nl.json b/frontend/messages/nl.json index d466274..dd17cb3 100644 --- a/frontend/messages/nl.json +++ b/frontend/messages/nl.json @@ -725,6 +725,7 @@ "noAppointment": "Geen afspraak", "walkIn": "Inloop", "newTreatment": "Nieuwe behandeling", + "mobileOpenRail": "Patiënt / geschiedenis", "newTreatmentPatientPrompt": "Voor wie is dit bezoek?", "newTreatmentUseCurrent": "{name} gebruiken", "newTreatmentUseCurrentHint": "Start een nieuw bezoek voor de patiënt die al op deze pagina openstaat.", diff --git a/frontend/src/components/ui/lab/CaseCreatePanel.tsx b/frontend/src/components/ui/lab/CaseCreatePanel.tsx index 0a6947d..155a2f3 100644 --- a/frontend/src/components/ui/lab/CaseCreatePanel.tsx +++ b/frontend/src/components/ui/lab/CaseCreatePanel.tsx @@ -320,7 +320,7 @@ export function CaseCreatePanel({ const disabled = !canEdit || starting || deleting; return ( -
+

{t('addCaseTitle')}

@@ -478,6 +478,7 @@ export function CaseCreatePanel({ detailClientId={activeLine.clientId} catalog={prosthesisOptions} disabled={disabled} + className="w-full min-w-0" onToggleLink={(a, b) => { if (disabled) return; const currentGroups = diff --git a/frontend/src/components/ui/lab/CaseDetailPanel.tsx b/frontend/src/components/ui/lab/CaseDetailPanel.tsx index cf9b410..13a9ef9 100644 --- a/frontend/src/components/ui/lab/CaseDetailPanel.tsx +++ b/frontend/src/components/ui/lab/CaseDetailPanel.tsx @@ -158,8 +158,8 @@ export function CaseDetailPanel({ } return ( -
-
+
+

@@ -194,9 +194,9 @@ export function CaseDetailPanel({

-
+
{canEditImportant ? ( -
+
{labCase.externalCode.trim()}

) : null} -
+
{showCommentsButton && onCommentsClick ? (
{labCase.shareUrl || (previewAttachment && labCase.attachments.length > 0) ? ( -
+
{previewAttachment && labCase.attachments.length > 0 ? ( - + {t('pageSummary', { page: pagination.page, totalPages: pagination.totalPages, @@ -599,7 +599,7 @@ export function CasesPage() {
diff --git a/frontend/src/components/ui/lab/LabCaseProsthesisGroupsList.tsx b/frontend/src/components/ui/lab/LabCaseProsthesisGroupsList.tsx index a6f46d9..1f5dcd5 100644 --- a/frontend/src/components/ui/lab/LabCaseProsthesisGroupsList.tsx +++ b/frontend/src/components/ui/lab/LabCaseProsthesisGroupsList.tsx @@ -35,7 +35,7 @@ export function LabCaseProsthesisGroupsList({ {groups.map((group) => (
  • void }) { +/** Hide from this breakpoint up (Cases = lg, Treatment = xl). */ +type HideFrom = 'lg' | 'xl'; + +const HIDE_FROM_CLASS: Record = { + lg: 'lg:hidden', + xl: 'xl:hidden', +}; + +export function MobileDetailBackButton({ + onClick, + hideFrom = 'lg', +}: { + onClick: () => void; + hideFrom?: HideFrom; +}) { const t = useTranslations('common'); return ( +
  • {showSearchedPatientLoading ? (

    {t('loading')}

    -- 2.53.0.windows.1