From 6b772c59682af298777ec937647aa7aa2f68af21 Mon Sep 17 00:00:00 2001 From: spark Date: Sat, 7 Nov 2026 03:22:05 +0000 Subject: [PATCH] fix(library): open a photo large on double-click The grid was capturing the pointer on the first press, so the second click never reached the photo. The open frame now fills the library pane. --- apps/app/src/library/Grid.test.tsx | 51 ++++++++++++++++++++++++++++++ apps/app/src/library/Grid.tsx | 13 +++++--- apps/app/src/pages/LibraryPage.tsx | 3 +- 3 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 apps/app/src/library/Grid.test.tsx diff --git a/apps/app/src/library/Grid.test.tsx b/apps/app/src/library/Grid.test.tsx new file mode 100644 index 0000000..8b6d10d --- /dev/null +++ b/apps/app/src/library/Grid.test.tsx @@ -0,0 +1,51 @@ +import type { PhotoSummary } from "@photoreport/contracts"; +import { fireEvent, render, screen } from "@testing-library/react"; +import { describe, expect, it, vi } from "vitest"; +import { Grid } from "./Grid.js"; + +function photo(id: string): PhotoSummary { + return { + id, + eventId: "e1", + originalName: `${id}.jpg`, + name: `${id}.jpg`, + sha256: `sha-${id}`, + originalStored: true, + status: "READY", + width: 600, + height: 400, + capturedAt: "2026-09-23T20:00:00Z", + cameraModel: null, + lens: null, + focalLength: null, + aperture: null, + exposureTime: null, + iso: null, + rating: 0, + flag: "NONE", + colorLabel: "NONE", + players: [], + uploader: null, + developSeq: 0, + urls: { thumb: "", preview: "", source: "" }, + }; +} + +describe("grid", () => { + it("opens the photo on a double-click", () => { + const onOpen = vi.fn(); + render( + ""} + onPick={() => {}} + onSelectMany={() => {}} + onOpen={onOpen} + />, + ); + fireEvent.doubleClick(screen.getByRole("button", { name: /a\.jpg/ })); + expect(onOpen).toHaveBeenCalledWith("a"); + }); +}); diff --git a/apps/app/src/library/Grid.tsx b/apps/app/src/library/Grid.tsx index 7aed5c8..a4d05ff 100644 --- a/apps/app/src/library/Grid.tsx +++ b/apps/app/src/library/Grid.tsx @@ -171,6 +171,8 @@ export function Grid(props: { const dy = e.clientY - current.y; if (!current.moved && Math.hypot(dx, dy) < DRAG_PX) return; current.moved = true; + // Capture only once the drag is real. Capturing on the first press steals the second click, so a double-click never opens the photo. + if (!section.hasPointerCapture(e.pointerId)) section.setPointerCapture(e.pointerId); const left = Math.min(current.x, e.clientX); const top = Math.min(current.y, e.clientY); const width = Math.abs(e.clientX - current.x); @@ -197,7 +199,6 @@ export function Grid(props: { base: [...props.selected], moved: false, }; - e.currentTarget.setPointerCapture(e.pointerId); }} onPointerMove={moveBand} onPointerUp={(e) => { @@ -256,6 +257,7 @@ export function Loupe({ total, faces = [], onMenu, + onClose, }: { photo: PhotoSummary; src: string; @@ -264,6 +266,8 @@ export function Loupe({ total: number; faces?: LoupeFace[]; onMenu?: (id: string, e: React.MouseEvent) => void; + /** Double-click returns to the grid. */ + onClose?: () => void; }) { // Desktop app: previews seen once show again without a network; never seen, the thumbnail stands in. const preview = useCachedImage(src, isDesktop()); @@ -288,7 +292,8 @@ export function Loupe({ return (
onClose?.()} onContextMenu={(e) => { if (!onMenu) { e.preventDefault(); @@ -298,13 +303,13 @@ export function Loupe({ onMenu(photo.id, e); }} > - + setFailed(true)} alt={photo.name} draggable={false} - className="pointer-events-none block max-h-[calc(100vh-14rem)] max-w-full object-contain shadow-[0_2px_12px_rgba(0,0,0,0.7)]" + className="pointer-events-none block max-h-full max-w-full object-contain" /> {softCrop && } {faces.map((f) => ( diff --git a/apps/app/src/pages/LibraryPage.tsx b/apps/app/src/pages/LibraryPage.tsx index cb6bd14..de62458 100644 --- a/apps/app/src/pages/LibraryPage.tsx +++ b/apps/app/src/pages/LibraryPage.tsx @@ -777,7 +777,7 @@ export function LibraryPage() { )}
{ if (!e.dataTransfer.types.includes("Files")) return; e.preventDefault(); @@ -884,6 +884,7 @@ export function LibraryPage() { index={visibleIds.indexOf(focus.id)} total={visibleIds.length} faces={loupeFaces} + onClose={() => setLoupe(false)} {...(canCull ? { onMenu: onPhotoMenu } : {})} /> ) : visible.length || suggested.length ? ( -- 2.47.3