Show edited renders in thumbnails and paste to a filmstrip selection
The grid and filmstrip only ever showed the import thumbnail, so edits and virtual copies looked untouched. Edited tiles now render client-side with the same shader as the canvas, once each, from the small cached thumbnail. The filmstrip also gains Cmd/Shift multi-select so Paste, Copy and Reset can act on several photos from the toolbar or the right-click menu.
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import { 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.
|
||||
*/
|
||||
export default 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) }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user