import { useEffect, useRef } from "react"; import type { SyntheticSample } from "../samples.ts"; import type { UploadRecord } from "../imageStore.ts"; function SyntheticThumb({ sample }: { sample: SyntheticSample }) { const ref = useRef(null); useEffect(() => { const canvas = ref.current; if (!canvas) return; const raw = sample.generate(); const tmp = document.createElement("canvas"); tmp.width = raw.width; tmp.height = raw.height; tmp .getContext("2d")! .putImageData( new ImageData(new Uint8ClampedArray(raw.rgba), raw.width, raw.height), 0, 0 ); const ctx = canvas.getContext("2d")!; ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.drawImage(tmp, 0, 0, canvas.width, canvas.height); }, [sample]); return ; } interface Props { samples: SyntheticSample[]; uploads: UploadRecord[]; selectedId: string | null; onSelectSample: (sample: SyntheticSample) => void; onSelectUpload: (rec: UploadRecord) => void; onUpload: (file: File) => void; onDeleteUpload: (id: string) => void; disabled?: boolean; } export function SamplePicker({ samples, uploads, selectedId, onSelectSample, onSelectUpload, onUpload, onDeleteUpload, disabled, }: Props) { const fileRef = useRef(null); return (
{samples.map((sample) => ( ))} {uploads.length > 0 &&
} {uploads.map((rec) => (
))} { const f = e.target.files?.[0]; if (f) onUpload(f); e.target.value = ""; }} />
); }