diff --git a/apps/studio/src/apps/PhotoApp.tsx b/apps/studio/src/apps/PhotoApp.tsx index 37763504..a2cd7b15 100644 --- a/apps/studio/src/apps/PhotoApp.tsx +++ b/apps/studio/src/apps/PhotoApp.tsx @@ -14,7 +14,7 @@ import type { AppProps } from "./registry"; /** * The Photo app (docs/rewrite/09-shells.md): one photo, large, with its facts. ← and → step through * the list it was opened from (or its collection, else its folder). The preview shows at once; the - * original is loaded on request. + * original replaces it as soon as it has loaded. */ /** One photo; opened without one, the start screen of the project's photos (#426). */ export function PhotoApp(p: AppProps) { @@ -28,11 +28,10 @@ function PhotoView({ win, resource, projectId, setTitle, setRoute }: AppProps) { const [id, setId] = useState(resource?.id ?? ""); useEffect(() => { if (resource?.id) setId(resource.id); }, [resource?.id, win.stateSeq]); const f = map.get(id); - const [full, setFull] = useState(false); + // The preview shows at once; the original replaces it as soon as it has loaded (#426: no Preview / Full size switch). const [loaded, setLoaded] = useState(null); const [name, setName] = useState(f?.name ?? ""); useEffect(() => { setName(f?.name ?? ""); }, [f?.id, f?.name]); - useEffect(() => { setFull(false); }, [id]); const [panels, setPanels] = useDockLayout("photo", { right: { tabs: ["facts"] } }); // The list to step through: the one it was opened from, else its collection, else its folder. @@ -45,12 +44,22 @@ function PhotoView({ win, resource, projectId, setTitle, setRoute }: AppProps) { // The window stands for the photo it shows (one window per file): stepping onto one open elsewhere brings that window up. const step = (d: number) => { const next = list[at + d]; if (next && wm.setResource(win.id, { type: "photo", id: next })) setId(next); }; useEffect(() => { if (f) { setTitle(f.name); setRoute(f.id); } }, [f?.id, f?.name]); - useKeys(bind("photo", { prev: () => step(-1), next: () => step(1), full: () => setFull((v) => !v) })); + useKeys(bind("photo", { prev: () => step(-1), next: () => step(1) })); + const originalUrl = f && f.photo?.stored.original && f.photo.media_type !== "image/heic" ? imageUrl(f.id, "original") : null; + useEffect(() => { + if (!originalUrl || loaded === originalUrl) return; + const img = new Image(); + img.onload = () => setLoaded(originalUrl); + img.src = originalUrl; + return () => { img.onload = null; }; + }, [originalUrl]); if (!files) return
; if (!f || f.type !== "photo" || !f.photo) return
It was deleted, or it is in the recycle bin.
; const p = f.photo; - const src = full && p.stored.original && p.media_type !== "image/heic" ? imageUrl(f.id, "original") : p.stored.preview ? imageUrl(f.id, "preview") : p.stored.thumbnail ? imageUrl(f.id, "thumbnail") : null; + const original = p.stored.original && p.media_type !== "image/heic" ? imageUrl(f.id, "original") : null; + const first = p.stored.preview ? imageUrl(f.id, "preview") : p.stored.thumbnail ? imageUrl(f.id, "thumbnail") : null; + const src = original && loaded === original ? original : first ?? original; const commit = () => { const to = name.trim(); if (!to || to === f.name) { setName(f.name); return; } void store.rename(f, to).catch((e) => { toastError(e); setName(f.name); }); }; return ( = list.length - 1} onClick={() => step(1)} /> setName(e.currentTarget.value)} onBlur={commit} onKeyDown={(e) => { if (e.key === "Enter") e.currentTarget.blur(); if (e.key === "Escape") { setName(f.name); e.currentTarget.blur(); } }} /> -