Files
luminary/src/components/EditedImage.tsx
T
bhursey 0c113e7a91 Land camera-native raw profiles, real ICC soft proofing and 16-bit proxies.
Camera profiles, proofing tables and the half-float sidecar all have to agree
with the pixels the editor actually grades, so they land together with the
preset filter menu that was unusable while thumbnails streamed in.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-11-28 03:59:55 +00:00

71 lines
1.9 KiB
TypeScript

import { memo, useEffect, useRef, useState } from 'react';
import { thumbTransform } from '../lib/edits';
import { useEditedThumb } from '../lib/editThumbs';
import type { PhotoRecord } from '../types';
interface Props {
photo: PhotoRecord;
/** Aspect of the tile the picture fills; the rotation transform needs it. */
boxAspect?: number;
alt?: string;
loading?: 'lazy' | 'eager';
draggable?: boolean;
}
/**
* A thumbnail that follows the photo's edits.
*
* Edited photos get a freshly rendered small JPEG; everything else keeps the
* server/import thumbnail and the CSS orientation transform. Rendering starts
* only when the tile is close to the viewport.
*/
function EditedImage({
photo,
boxAspect = 4 / 3,
alt,
loading = 'lazy',
draggable = false,
}: Props) {
const ref = useRef<HTMLImageElement>(null);
const [nearView, setNearView] = useState(false);
useEffect(() => {
const el = ref.current;
if (!el) return;
if (typeof IntersectionObserver === 'undefined') {
setNearView(true);
return;
}
const observer = new IntersectionObserver(
(entries) => {
if (!entries.some((entry) => entry.isIntersecting)) return;
setNearView(true);
observer.disconnect();
},
{ rootMargin: '400px' },
);
observer.observe(el);
return () => observer.disconnect();
}, []);
const edited = useEditedThumb(photo, nearView);
return (
<img
ref={ref}
src={edited ?? photo.thumbUrl ?? photo.thumb}
alt={alt ?? photo.name}
loading={loading}
draggable={draggable}
// A rendered tile already has the crop, turn and flips baked in.
style={{ transform: edited ? 'none' : thumbTransform(photo, boxAspect) }}
/>
);
}
/**
* Memoised: a selection change on the library re-renders the whole grid, and a
* picture whose photo, size and props did not change has no work to redo.
*/
export default memo(EditedImage);