diff --git a/components/details/CO2GalvoDetail.tsx b/components/details/CO2GalvoDetail.tsx index 8be8f18a..ba442242 100644 --- a/components/details/CO2GalvoDetail.tsx +++ b/components/details/CO2GalvoDetail.tsx @@ -10,8 +10,8 @@ type Rec = { setting_title?: string | null; setting_notes?: string | null; - photo?: { id?: string } | string | null; - screen?: { id?: string } | string | null; + photo?: { id?: string } | string | number | null; + screen?: { id?: string } | string | number | null; // ids & readable fields mat?: { id?: string | number; name?: string | null } | null; @@ -54,9 +54,18 @@ function isMine(owner: Rec["owner"], meId: string | null) { return owner.id != null && String(owner.id) === meId; } -function fileUrl(id?: string) { +// --- Image helpers ----------------------------------------------------------- +function resolveFileId(v: Rec["photo"]): string | null { + if (v == null) return null; + if (typeof v === "string" || typeof v === "number") return String(v); + if (typeof v === "object" && v.id) return String(v.id); + // some Directus shapes may nest deeper; add more cases if needed + return null; +} +function assetSrc(id?: string | null) { return id ? `/api/dx/assets/${id}` : ""; } +// ---------------------------------------------------------------------------- export default function CO2GalvoDetail({ id, @@ -171,10 +180,11 @@ export default function CO2GalvoDetail({ const initialValues = useMemo(() => { if (!rec) return null; + const toId = (v: any) => (v == null ? null : typeof v === "object" ? v.id ?? v.submission_id ?? null : v); - const photoId = typeof rec.photo === "string" || typeof rec.photo === "number" ? String(rec.photo) : rec.photo?.id ?? null; - const screenId = typeof rec.screen === "string" || typeof rec.screen === "number" ? String(rec.screen) : rec.screen?.id ?? null; + const photoId = resolveFileId(rec.photo); + const screenId = resolveFileId(rec.screen); const matId = toId(rec.mat); const coatId = toId(rec.mat_coat); @@ -229,14 +239,33 @@ export default function CO2GalvoDetail({ ); } - // VIEW (readable) + // VIEW const ownerDisplay = ownerLabel(rec.owner); const canEdit = showOwnerEdit && isMine(rec.owner, meId); - const photoId = typeof rec.photo === "object" ? rec.photo?.id : (rec.photo as any); - const screenId = typeof rec.screen === "object" ? rec.screen?.id : (rec.screen as any); - const photoSrc = photoId ? fileUrl(String(photoId)) : ""; - const screenSrc = screenId ? fileUrl(String(screenId)) : ""; + const photoSrc = assetSrc(resolveFileId(rec.photo)); + const screenSrc = assetSrc(resolveFileId(rec.screen)); + + // simple lightbox state + const [lightbox, setLightbox] = useState<{ src: string; alt: string } | null>(null); + + function Thumb({ src, alt }: { src: string; alt: string }) { + if (!src) return null; + return ( +
+ +
{alt}
+
+ ); + } return (
@@ -285,18 +314,8 @@ export default function CO2GalvoDetail({
- {photoSrc ? ( -
- Result -
Result
-
- ) : null} - {screenSrc ? ( -
- Settings screenshot -
Settings Screenshot
-
- ) : null} + +
@@ -406,6 +425,23 @@ export default function CO2GalvoDetail({ )} + + {/* Lightbox overlay */} + {lightbox && ( +
setLightbox(null)} + role="dialog" + aria-modal="true" + > + {lightbox.alt} e.stopPropagation()} + /> +
+ )} ); }