From e816ea48d2b26447d8fea1fa744c4808809e1917 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 3 Jun 2025 15:09:20 +0200 Subject: [PATCH] updates --- src/components/OffsetOrder.tsx | 399 ++++++++++++++++++--------------- 1 file changed, 223 insertions(+), 176 deletions(-) diff --git a/src/components/OffsetOrder.tsx b/src/components/OffsetOrder.tsx index 32edcbd..e1e0e9f 100644 --- a/src/components/OffsetOrder.tsx +++ b/src/components/OffsetOrder.tsx @@ -40,6 +40,207 @@ const ProjectTypeIcon = ({ project }: ProjectTypeIconProps) => { } }; +// Project card component to improve readability and ensure consistent behavior +const ProjectCard = ({ + project, + index, + onSelect +}: { + project: OffsetProject; + index: number; + onSelect: (project: OffsetProject) => void; +}) => { + // Handler to ensure event propagation is stopped correctly + const handleClick = (e: React.MouseEvent) => { + e.preventDefault(); + e.stopPropagation(); + console.log('Project clicked:', project.name); + onSelect(project); + }; + + return ( + +
+
+ +

{project.name}

+
+ {project.percentage && ( + + {(project.percentage * 100).toFixed(1)}% + + )} +
+ {project.imageUrl && ( +
+ {project.name} +
+ )} +

+ {project.shortDescription || project.description} +

+
+
+ Price per ton: + + ${project.pricePerTon.toFixed(2)} + +
+
+
+ Click for details +
+
+ ); +}; + +// Lightbox modal component +const ProjectLightbox = ({ + project, + onClose +}: { + project: OffsetProject | null; + onClose: () => void; +}) => { + // Close on Escape key + useEffect(() => { + const handleKeyDown = (e: KeyboardEvent) => { + if (e.key === 'Escape') onClose(); + }; + + window.addEventListener('keydown', handleKeyDown); + return () => window.removeEventListener('keydown', handleKeyDown); + }, [onClose]); + + // Prevent body scrolling when modal is open + useEffect(() => { + document.body.style.overflow = 'hidden'; + return () => { + document.body.style.overflow = 'auto'; + }; + }, []); + + if (!project) return null; + + return ( +
+ {/* Backdrop */} +