From 91bc9aefc758fcc7c923e413c8562374305510b9 Mon Sep 17 00:00:00 2001 From: spark Date: Mon, 23 Nov 2026 17:47:47 +0000 Subject: [PATCH] Keep a straightened crop on the photograph's aspect and send Lightroom's changes back. Lightroom turns the stored corners around the crop centre, so writing the levelled rectangle made the crop Custom. The file now stores those corners, the original is found by its own hash, and edits already queued go out while the socket stays up. --- AGENTS.md | 11 ++ apps/app/src/App.test.tsx | 6 +- apps/app/src/desktop/fileMarks.ts | 7 + apps/app/src/desktop/lightroomCrop.test.ts | 47 ++++++ apps/app/src/desktop/lightroomCrop.ts | 141 ++++++++++++++++++ apps/app/src/desktop/lightroomSidecar.test.ts | 17 +++ apps/app/src/desktop/lightroomSidecar.ts | 93 ++++++++++-- apps/app/src/desktop/softCrop.ts | 12 +- apps/app/src/desktop/softCropWatch.ts | 16 +- apps/app/src/i18n.ts | 2 + apps/app/src/library/Grid.tsx | 14 +- apps/app/src/library/realtime.ts | 36 ++++- apps/app/src/offline/offline.test.ts | 23 +++ apps/app/src/offline/queue.ts | 37 +++-- apps/app/src/offline/sync.ts | 37 ++++- apps/app/src/pages/DevelopPage.tsx | 24 +-- apps/app/src/pages/LibraryPage.tsx | 4 +- docs/ARCHITECTURE.md | 26 +++- docs/photo-editing-rules.md | 3 + 19 files changed, 503 insertions(+), 53 deletions(-) create mode 100644 apps/app/src/desktop/lightroomCrop.test.ts create mode 100644 apps/app/src/desktop/lightroomCrop.ts diff --git a/AGENTS.md b/AGENTS.md index 93701a2..63a6d62 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -32,6 +32,17 @@ Read `docs/ARCHITECTURE.md` before any task. One task id per branch/PR (`task/BI 13. **Prefer Rust for local heavy work.** Detection, measure, level, develop and anything CPU-bound on the desktop should live in `engine/` (native / WASM), not in ad-hoc TypeScript, when practical. TypeScript orchestrates; Rust does the pixels and the scores. Safer, faster, one implementation with the workers. +14. **Start from the latest `origin/main`.** Paperclip, Claude Code and Cursor fetch and fast-forward this + checkout before editing. Do not leave the work only on an old branch or another folder. A pinned engine + revision is the LightCraft `rev` in the root `Cargo.toml`, not a stale checkout of this repo. +15. **The photograph's aspect is not a dial.** The autopilot and every automatic file write keep the original + aspect (`docs/photo-editing-rules.md`). A straightened crop is written as the corners Lightroom turns back + around the crop centre (`apps/app/src/desktop/lightroomCrop.ts`). Writing the levelled rectangle plus the + angle makes Lightroom show Custom. Do not invent another ratio to satisfy a framing rule. +16. **Lightroom round-trip is the file, not the catalog.** While the desktop app is open it reads crop, pick, + stars and colour back from the work-folder original and sends them to the server. Exposure and the other + develop sliders are written out and are not read back. A change that Lightroom has not written into the + file is invisible. Newsroom fields (caption, title, keywords, creator) go on the first `rdf:Description`. ## Porting from the old projects diff --git a/apps/app/src/App.test.tsx b/apps/app/src/App.test.tsx index 796e981..01555d1 100644 --- a/apps/app/src/App.test.tsx +++ b/apps/app/src/App.test.tsx @@ -5,7 +5,11 @@ import userEvent from "@testing-library/user-event"; import { describe, expect, it, vi } from "vitest"; import { App } from "./App.js"; -vi.mock("./library/realtime.js", () => ({ useLibraryLive: () => "live", onSocketLive: () => () => {} })); +vi.mock("./library/realtime.js", () => ({ + useLibraryLive: () => "live", + onSocketLive: () => () => {}, + isSocketLive: () => false, +})); const ME: Me = { user: { id: "u1", email: "ana@photoreport.pt", name: "Ana", locale: "pt-PT" }, diff --git a/apps/app/src/desktop/fileMarks.ts b/apps/app/src/desktop/fileMarks.ts index e350869..11875d4 100644 --- a/apps/app/src/desktop/fileMarks.ts +++ b/apps/app/src/desktop/fileMarks.ts @@ -3,6 +3,7 @@ import type { ApiClient, EventSummary } from "@photoreport/sdk"; import { useEffect } from "react"; import { useLibraryLive } from "../library/realtime.js"; import { isDesktop } from "../platform.js"; +import { rememberPhotoFrame } from "./lightroomCrop.js"; import { flushFailedPhotoFiles, flushRecentPhotoFiles, settingsFromDevelop, writePhotoCommands, writePhotoFile, type FileIptc, type FileMarkUpdate } from "./lightroomSidecar.js"; const LOCAL = "local:"; @@ -54,6 +55,11 @@ function diskSha(photoId: string, apiSha: string | null | undefined): string | n return null; } +/** The original Lightroom has open. The server hash can be the preview, which is not in the work folder. */ +export function fileShaForPhoto(photoId: string, apiSha: string | null | undefined): string | null { + return diskSha(photoId, apiSha); +} + function shaOf(id: string): string | null { if (id.startsWith(LOCAL)) return id.slice(LOCAL.length); const onDisk = originalSha(id); @@ -226,6 +232,7 @@ export async function catchUpFileMarks(api: ApiClient, orgId: string): Promise { + it("keeps the photograph's aspect after Lightroom levels the straighten", () => { + const stored = toLightroomEdges(shot, angle, width, height); + const shown = fromLightroomEdges(stored, angle, width, height); + const got = sides(shown); + expect(Math.abs(got.w - got.h)).toBeLessThan(0.0001); + expect(stored.left).toBeGreaterThanOrEqual(0); + expect(stored.top).toBeGreaterThanOrEqual(0); + expect(stored.right).toBeLessThanOrEqual(1); + expect(stored.bottom).toBeLessThanOrEqual(1); + const pxW = got.w * width; + const pxH = got.h * height; + expect(pxW / pxH).toBeCloseTo(width / height, 3); + }); + + it("shrinks a crop that would leave the photo once it is turned", () => { + const full = { left: 0.01, top: 0.01, right: 0.99, bottom: 0.99 }; + const stored = toLightroomEdges(full, 2.64, width, height); + expect(stored.left).toBeGreaterThanOrEqual(0); + expect(stored.top).toBeGreaterThanOrEqual(0); + expect(stored.right).toBeLessThanOrEqual(1); + expect(stored.bottom).toBeLessThanOrEqual(1); + const shown = fromLightroomEdges(stored, 2.64, width, height); + const got = sides(shown); + expect(Math.abs(got.w - got.h)).toBeLessThan(0.0001); + expect(got.w).toBeLessThan(0.98); + }); + + it("leaves a level crop untouched", () => { + const rect = { left: 0.1, top: 0.1, right: 0.8, bottom: 0.8 }; + expect(toLightroomEdges(rect, 0, width, height)).toEqual(rect); + expect(fromLightroomEdges(rect, 0, width, height)).toEqual(rect); + }); +}); diff --git a/apps/app/src/desktop/lightroomCrop.ts b/apps/app/src/desktop/lightroomCrop.ts new file mode 100644 index 0000000..f0609fe --- /dev/null +++ b/apps/app/src/desktop/lightroomCrop.ts @@ -0,0 +1,141 @@ +/** + * Lightroom stores a crop as two opposite corners plus an angle. It then turns those corners + * back around the crop centre, and the levelled rectangle is what the crop tool shows. + * The app's crop is already that levelled rectangle (the photograph's own aspect: equal + * width and height in frame fractions). Writing it straight through makes the levelled + * result a different proportion, which the crop tool labels Custom. + */ + +export interface CropEdges { + left: number; + top: number; + right: number; + bottom: number; +} + +export interface PhotoFrame { + width: number; + height: number; +} + +const frames = new Map(); + +/** Pixel size of a local original, so a later read can turn Lightroom's corners back into the levelled crop. */ +export function rememberPhotoFrame(sha256: string, width: number | null | undefined, height: number | null | undefined): void { + if (!sha256) return; + if (typeof width !== "number" || typeof height !== "number") return; + if (!(width > 0) || !(height > 0)) return; + frames.set(sha256, { width, height }); +} + +export function photoFrame(sha256: string): PhotoFrame | null { + return frames.get(sha256) ?? null; +} + +function turn(x: number, y: number, cx: number, cy: number, deg: number): [number, number] { + const th = (deg * Math.PI) / 180; + const dx = x - cx; + const dy = y - cy; + const c = Math.cos(th); + const s = Math.sin(th); + return [dx * c - dy * s + cx, dx * s + dy * c + cy]; +} + +/** Top-left frame fractions as pixels with y growing up, the space the corner rotation is defined in. */ +function pixel(x: number, yTop: number, width: number, height: number): [number, number] { + return [x * width, (1 - yTop) * height]; +} + +function shrunk(rect: CropEdges, scale: number): CropEdges { + const cx = (rect.left + rect.right) / 2; + const cy = (rect.top + rect.bottom) / 2; + const halfW = ((rect.right - rect.left) / 2) * scale; + const halfH = ((rect.bottom - rect.top) / 2) * scale; + return { + left: cx - halfW, + top: cy - halfH, + right: cx + halfW, + bottom: cy + halfH, + }; +} + +function cornersFit(rect: CropEdges, angle: number, width: number, height: number): boolean { + const ul = pixel(rect.left, rect.top, width, height); + const lr = pixel(rect.right, rect.bottom, width, height); + const cx = (ul[0] + lr[0]) / 2; + const cy = (ul[1] + lr[1]) / 2; + const a = -angle; + const pts: Array<[number, number]> = [ + pixel(rect.left, rect.top, width, height), + pixel(rect.right, rect.top, width, height), + pixel(rect.right, rect.bottom, width, height), + pixel(rect.left, rect.bottom, width, height), + ]; + const eps = 0.5; + for (const [x, y] of pts) { + const [rx, ry] = turn(x, y, cx, cy, a); + if (rx < -eps || ry < -eps || rx > width + eps || ry > height + eps) return false; + } + return true; +} + +function storedEdges(rect: CropEdges, angle: number, width: number, height: number): CropEdges { + const ul = pixel(rect.left, rect.top, width, height); + const lr = pixel(rect.right, rect.bottom, width, height); + const cx = (ul[0] + lr[0]) / 2; + const cy = (ul[1] + lr[1]) / 2; + const a = -angle; + const sul = turn(ul[0], ul[1], cx, cy, a); + const slr = turn(lr[0], lr[1], cx, cy, a); + return { + left: sul[0] / width, + top: 1 - sul[1] / height, + right: slr[0] / width, + bottom: 1 - slr[1] / height, + }; +} + +function ordered(rect: CropEdges): boolean { + if (!(rect.left < rect.right && rect.top < rect.bottom)) return false; + if (rect.left < -0.000001 || rect.top < -0.000001) return false; + if (rect.right > 1.000001 || rect.bottom > 1.000001) return false; + return true; +} + +/** + * Corners to write for `crs:Crop*`. `rect` is the levelled crop (what the tool should show). + * A non-zero angle turns those corners about the crop centre, then shrinks until they stay on the photo. + */ +export function toLightroomEdges(rect: CropEdges, angle: number, width: number, height: number): CropEdges { + if (!(width > 0) || !(height > 0)) return rect; + if (!Number.isFinite(angle) || Math.abs(angle) < 0.05) return rect; + let scale = 1; + let fitted = rect; + for (let i = 0; i < 80; i++) { + fitted = shrunk(rect, scale); + const stored = storedEdges(fitted, angle, width, height); + if (cornersFit(fitted, angle, width, height) && ordered(stored)) return stored; + scale -= 0.012; + if (scale < 0.08) break; + } + return storedEdges(fitted, angle, width, height); +} + +/** The levelled crop Lightroom shows for corners it stored. Inverse of `toLightroomEdges` when nothing was shrunk. */ +export function fromLightroomEdges(rect: CropEdges, angle: number, width: number, height: number): CropEdges { + if (!(width > 0) || !(height > 0)) return rect; + if (!Number.isFinite(angle) || Math.abs(angle) < 0.05) return rect; + const ul = pixel(rect.left, rect.top, width, height); + const lr = pixel(rect.right, rect.bottom, width, height); + const cx = (ul[0] + lr[0]) / 2; + const cy = (ul[1] + lr[1]) / 2; + const a = -angle; + const uul = turn(ul[0], ul[1], cx, cy, -a); + const ulr = turn(lr[0], lr[1], cx, cy, -a); + return { + left: uul[0] / width, + top: 1 - uul[1] / height, + right: ulr[0] / width, + bottom: 1 - ulr[1] / height, + }; +} diff --git a/apps/app/src/desktop/lightroomSidecar.test.ts b/apps/app/src/desktop/lightroomSidecar.test.ts index ed653ff..b7d36a0 100644 --- a/apps/app/src/desktop/lightroomSidecar.test.ts +++ b/apps/app/src/desktop/lightroomSidecar.test.ts @@ -9,6 +9,23 @@ describe("Lightroom sidecar", () => { expect(xml).not.toContain("crs:Shadows2012"); }); + it("turns a straightened crop so Lightroom still shows the photograph's aspect", () => { + const xml = lightroomXmp( + JSON.stringify({ + crop: { + geometry: { + angle: -5.9, + rect: { x0: 0.024609, y0: 0.078821, x1: 0.799609, y1: 0.853821 }, + aspect: [6000, 4000], + }, + }, + }), + ); + expect(xml).toContain('crs:CropAngle="-5.90"'); + expect(xml).not.toContain('crs:CropLeft="0.024609"'); + expect(xml).not.toContain('crs:CropTop="0.078821"'); + }); + it("writes a soft crop in the same crs fields Lightroom and Photo Mechanic read", () => { const xml = lightroomXmp(JSON.stringify({ crop: { geometry: { angle: -1.91, rect: { x0: 0, y0: 0.126385, x1: 0.861387, y1: 0.926887 } } } })); expect(xml).toContain('crs:HasCrop="True"'); diff --git a/apps/app/src/desktop/lightroomSidecar.ts b/apps/app/src/desktop/lightroomSidecar.ts index 49b9642..3e1b4c3 100644 --- a/apps/app/src/desktop/lightroomSidecar.ts +++ b/apps/app/src/desktop/lightroomSidecar.ts @@ -1,7 +1,10 @@ import type { DevelopState, EditCommand } from "@photoreport/contracts"; +import { cropFromXmp } from "@photoreport/metadata"; +import { localPhotos } from "../offline/local.js"; import { desktopInvoke, isDesktop } from "../platform.js"; +import { fromLightroomEdges, photoFrame, toLightroomEdges, type PhotoFrame } from "./lightroomCrop.js"; -/** Soft crop written as crs:Crop* (same numbers SoftCropGuide / Photo Mechanic draw). */ +/** Soft crop in the app: the levelled rectangle. The file stores Lightroom's turned corners. */ export interface SoftCrop { left: number; top: number; @@ -201,7 +204,7 @@ function iptcParts(iptc: FileIptc | undefined): { attrs: string[]; children: str } /** Only the sliders that are actually set. Missing ones stay out of the sidecar, so Lightroom is not given a preset. */ -export function lightroomXmp(settings: string, marks?: FileMarks, iptc?: FileIptc): string | null { +export function lightroomXmp(settings: string, marks?: FileMarks, iptc?: FileIptc, frame?: PhotoFrame | null): string | null { let doc: Record; try { const parsed = JSON.parse(settings) as unknown; @@ -243,12 +246,14 @@ export function lightroomXmp(settings: string, marks?: FileMarks, iptc?: FileIpt if (sharpen !== undefined) attrs.push(`crs:Sharpness="${crsNumber(sharpen, 0)}"`); if (nr !== undefined) attrs.push(`crs:ColorNoiseReduction="${crsNumber(nr, 0)}"`); if (crop) { + const size = frameOf(doc) ?? frame ?? null; + const edges = size ? toLightroomEdges(crop, crop.angle, size.width, size.height) : crop; attrs.push( `crs:HasCrop="True"`, - `crs:CropLeft="${crop.left.toFixed(6)}"`, - `crs:CropTop="${crop.top.toFixed(6)}"`, - `crs:CropRight="${crop.right.toFixed(6)}"`, - `crs:CropBottom="${crop.bottom.toFixed(6)}"`, + `crs:CropLeft="${edges.left.toFixed(6)}"`, + `crs:CropTop="${edges.top.toFixed(6)}"`, + `crs:CropRight="${edges.right.toFixed(6)}"`, + `crs:CropBottom="${edges.bottom.toFixed(6)}"`, `crs:CropAngle="${crsNumber(crop.angle, 2)}"`, `crs:CropConstrainToUnitSquare="1"`, `crs:AlreadyApplied="False"`, @@ -278,7 +283,15 @@ export function lightroomXmp(settings: string, marks?: FileMarks, iptc?: FileIpt function foldEdit(doc: Record, command: EditCommand): void { if (command.command === "develop.set") Object.assign(doc, command.params.values); - else if (command.command === "crop.set") doc.crop = { geometry: { rect: command.params.rect, angle: command.params.angle ?? 0 } }; + else if (command.command === "crop.set") { + const geometry: { rect: typeof command.params.rect; angle: number; aspect?: [number, number] } = { + rect: command.params.rect, + angle: command.params.angle ?? 0, + }; + const aspect = command.params.aspect; + if (aspect && aspect[0] > 0 && aspect[1] > 0) geometry.aspect = [aspect[0], aspect[1]]; + doc.crop = { geometry }; + } else if (command.command === "develop.merge") Object.assign(doc, command.params.partial); else if (command.command === "develop.reset") { for (const key of Object.keys(doc)) delete doc[key]; @@ -299,6 +312,56 @@ export function settingsFromDevelop(state: DevelopState): string { return JSON.stringify(doc); } +function frameOf(doc: Record): PhotoFrame | null { + const crop = doc.crop; + if (!crop || typeof crop !== "object") return null; + const geometry = (crop as { geometry?: unknown }).geometry; + if (!geometry || typeof geometry !== "object") return null; + const aspect = (geometry as { aspect?: unknown }).aspect; + if (!Array.isArray(aspect) || aspect.length < 2) return null; + const width = aspect[0]; + const height = aspect[1]; + if (typeof width !== "number" || typeof height !== "number") return null; + if (!(width > 0) || !(height > 0)) return null; + return { width, height }; +} + +function docOf(settings: string): Record | null { + try { + const parsed = JSON.parse(settings) as unknown; + if (!parsed || typeof parsed !== "object") return null; + return parsed as Record; + } catch { + return null; + } +} + +/** Pixel size for this file: the crop's own aspect, then a size learned from the library. */ +export function frameForPhoto(sha256: string, settings: string): PhotoFrame | null { + const doc = docOf(settings); + if (doc) { + const fromCrop = frameOf(doc); + if (fromCrop) return fromCrop; + } + const known = photoFrame(sha256); + if (known) return known; + const local = localPhotos.bySha(sha256); + if (local && local.width && local.height && local.width > 0 && local.height > 0) { + return { width: local.width, height: local.height }; + } + return null; +} + +/** A straighten with no pixel size would be written as a different aspect. Hold the file until the size is known. */ +export function cropWaitsForFrame(settings: string, frame: PhotoFrame | null): boolean { + const doc = docOf(settings); + if (!doc) return false; + const crop = cropOf(doc); + if (!crop || Math.abs(crop.angle) < 0.05) return false; + if (frameOf(doc) || frame) return false; + return true; +} + function cropOf(doc: Record): SoftCrop | null { const crop = doc.crop; if (!crop || typeof crop !== "object") return null; @@ -438,7 +501,13 @@ function invokeWithTimeout(command: string, args: Record): Prom async function flushPhotoFile(sha256: string): Promise { const row = rememberedNow.get(sha256) ?? loadRemembered()[sha256]; if (!row) return; - const xml = lightroomXmp(row.settings, { flag: row.flag, rating: row.rating, colorLabel: row.colorLabel, sent: row.sent }, iptcOf(row.iptc)); + const frame = frameForPhoto(sha256, row.settings); + // Without the pixel size a straighten is written as another aspect. Wait, and retry. + if (cropWaitsForFrame(row.settings, frame)) { + flushFailed.add(sha256); + return; + } + const xml = lightroomXmp(row.settings, { flag: row.flag, rating: row.rating, colorLabel: row.colorLabel, sent: row.sent }, iptcOf(row.iptc), frame); if (!xml) return; // Write the file first. Soft-crop bookkeeping must not block or abort the Lightroom packet. try { @@ -453,7 +522,13 @@ async function flushPhotoFile(sha256: string): Promise { try { const { noteOwnSoftCropWrite } = await import("./softCropWatch.js"); const writtenFlag = row.sent || row.flag === "PICK" ? "PICK" : row.flag === "REJECT" ? "REJECT" : row.flag === "NONE" ? "NONE" : undefined; - noteOwnSoftCropWrite(sha256, softCropFromSettings(row.settings), writtenFlag); + const raw = cropFromXmp(xml); + let noted = softCropFromSettings(row.settings); + if (raw && frame && Math.abs(raw.angle) >= 0.05) { + const back = fromLightroomEdges(raw, raw.angle, frame.width, frame.height); + noted = { left: back.left, top: back.top, right: back.right, bottom: back.bottom, angle: raw.angle }; + } + noteOwnSoftCropWrite(sha256, noted, writtenFlag); } catch { // Watcher is optional; the file already has the marks. } diff --git a/apps/app/src/desktop/softCrop.ts b/apps/app/src/desktop/softCrop.ts index 9e8baa1..b570c11 100644 --- a/apps/app/src/desktop/softCrop.ts +++ b/apps/app/src/desktop/softCrop.ts @@ -1,5 +1,6 @@ import { cropFromXmp, type SoftCrop, xmpPacketFromJpeg } from "@photoreport/metadata"; import { desktopInvoke, isDesktop } from "../platform.js"; +import { fromLightroomEdges, photoFrame } from "./lightroomCrop.js"; const cache = new Map(); const inflight = new Map>(); @@ -39,7 +40,16 @@ export async function softCropFor(sha256: string): Promise { const work = (async () => { try { const xmp = await localXmpText(sha256); - const crop = xmp ? cropFromXmp(xmp) : null; + const raw = xmp ? cropFromXmp(xmp) : null; + if (!raw || Math.abs(raw.angle) < 0.05) { + cache.set(sha256, raw); + return raw; + } + const frame = photoFrame(sha256); + // The file stores turned corners. Without the photo size they are not the crop to draw. + if (!frame) return raw; + const back = fromLightroomEdges(raw, raw.angle, frame.width, frame.height); + const crop = { left: back.left, top: back.top, right: back.right, bottom: back.bottom, angle: raw.angle }; cache.set(sha256, crop); return crop; } catch { diff --git a/apps/app/src/desktop/softCropWatch.ts b/apps/app/src/desktop/softCropWatch.ts index ca53278..37b09f1 100644 --- a/apps/app/src/desktop/softCropWatch.ts +++ b/apps/app/src/desktop/softCropWatch.ts @@ -2,6 +2,7 @@ import { colorClassFromXmp, cropFromXmp, libraryMarksFromXmp, type SoftCrop, typ import type { ColorLabel, PhotoFlag } from "@photoreport/contracts"; import { desktopInvoke, isDesktop } from "../platform.js"; import { offlineQueue } from "../offline/queue.js"; +import { fromLightroomEdges, photoFrame } from "./lightroomCrop.js"; import { forgetSoftCrop, localXmpText } from "./softCrop.js"; /** @@ -159,7 +160,20 @@ export async function reconcileSoftCrops( }); continue; } - const crop = cropFromXmp(xmp); + const rawCrop = cropFromXmp(xmp); + // A straighten is stored as turned corners. Without the photo size those corners are not the crop we show. + if (rawCrop && Math.abs(rawCrop.angle) >= 0.05 && !photoFrame(row.sha256)) { + next.push(row); + continue; + } + let crop = rawCrop; + if (rawCrop && Math.abs(rawCrop.angle) >= 0.05) { + const frame = photoFrame(row.sha256); + if (frame) { + const back = fromLightroomEdges(rawCrop, rawCrop.angle, frame.width, frame.height); + crop = { left: back.left, top: back.top, right: back.right, bottom: back.bottom, angle: rawCrop.angle }; + } + } const color = colorClassFromXmp(xmp); const marks = libraryMarksFromXmp(xmp); let colorApplied = color ? row.color : (row.color ?? ""); diff --git a/apps/app/src/i18n.ts b/apps/app/src/i18n.ts index 21190ad..050f6f7 100644 --- a/apps/app/src/i18n.ts +++ b/apps/app/src/i18n.ts @@ -42,6 +42,8 @@ export const t = { label: "sem ligação", waiting: (n: number) => (n === 1 ? "1 alteração à espera de ligação" : `${n} alterações à espera de ligação`), waitingHelp: "Feito sem ligação ao servidor: fica guardado neste computador e é enviado sozinho quando a ligação voltar.", + pending: (n: number) => (n === 1 ? "1 alteração por enviar" : `${n} alterações por enviar`), + pendingHelp: "A ligação está feita. Estas alterações seguem para o servidor.", queuedDelivery: "Sem ligação: o envio fica à espera e sai sozinho quando a ligação voltar.", editingOffline: "Sem ligação: as edições ficam guardadas neste computador e são enviadas quando a ligação voltar.", }, diff --git a/apps/app/src/library/Grid.tsx b/apps/app/src/library/Grid.tsx index 5d7526b..ac68230 100644 --- a/apps/app/src/library/Grid.tsx +++ b/apps/app/src/library/Grid.tsx @@ -1,6 +1,8 @@ import type { SoftCrop } from "@photoreport/metadata"; import type { ColorLabel, PhotoSummary } from "@photoreport/contracts"; import { memo, useEffect, useRef, useState } from "react"; +import { fileShaForPhoto } from "../desktop/fileMarks.js"; +import { rememberPhotoFrame } from "../desktop/lightroomCrop.js"; import { softCropFor } from "../desktop/softCrop.js"; import { watchSoftCropPhoto } from "../desktop/softCropWatch.js"; import { t } from "../i18n.js"; @@ -41,19 +43,23 @@ const Cell = memo(function Cell({ photo, index, src, orgId, selected, focused, o const [softCrop, setSoftCrop] = useState(null); useEffect(() => setImgFailed(false), [shown]); useEffect(() => { - if (!isDesktop() || !photo.sha256) { + const sha = fileShaForPhoto(photo.id, photo.sha256); + if (!isDesktop() || !sha) { setSoftCrop(null); return; } - if (orgId) watchSoftCropPhoto(orgId, photo.id, photo.sha256); + if (orgId) { + rememberPhotoFrame(sha, photo.width, photo.height); + watchSoftCropPhoto(orgId, photo.id, sha); + } let alive = true; - void softCropFor(photo.sha256).then((crop) => { + void softCropFor(sha).then((crop) => { if (alive) setSoftCrop(crop); }); return () => { alive = false; }; - }, [orgId, photo.id, photo.sha256]); + }, [orgId, photo.id, photo.sha256, photo.width, photo.height]); return (