From 1f2e0e8222ffb100c5a4d94e71bc836745ad5f77 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 3 Jun 2025 17:07:59 +0200 Subject: [PATCH] updates --- src/components/OffsetOrder.tsx | 118 +++++++++++++++++++++++---------- 1 file changed, 83 insertions(+), 35 deletions(-) diff --git a/src/components/OffsetOrder.tsx b/src/components/OffsetOrder.tsx index 8c64fce..63f4de0 100644 --- a/src/components/OffsetOrder.tsx +++ b/src/components/OffsetOrder.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useCallback } from 'react'; import { Check, AlertCircle, ArrowLeft, Loader2, Globe2, TreePine, Waves, Factory, Wind, X } from 'lucide-react'; import { motion } from 'framer-motion'; import { createOffsetOrder, getPortfolios } from '../api/wrenClient'; @@ -128,13 +128,21 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr // Calculate offset cost using the portfolio price const offsetCost = monetaryAmount || (portfolio ? tons * (portfolio.pricePerTon || 18) : 0); - // Completely simplified project selection handler - const handleProjectClick = (project: OffsetProject, e: React.MouseEvent) => { - e.preventDefault(); - e.stopPropagation(); + // Robust project click handler with multiple fallbacks + const handleProjectClick = useCallback((project: OffsetProject, e?: React.MouseEvent) => { + if (e) { + e.preventDefault(); + e.stopPropagation(); + } console.log('Opening project details for:', project.name); setSelectedProject(project); - }; + }, []); + + // Additional handler for direct button clicks + const handleProjectButtonClick = useCallback((project: OffsetProject) => { + console.log('Button click - Opening project details for:', project.name); + setSelectedProject(project); + }, []); // Simple lightbox close handler const handleCloseLightbox = () => { @@ -343,56 +351,96 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr animate={{ opacity: 1 }} transition={{ duration: 0.5, delay: 0.3 }} > - {portfolio.projects.map((project) => ( -
handleProjectClick(project, e)} - role="button" - tabIndex={0} - style={{ - userSelect: 'none', - WebkitUserSelect: 'none', - msUserSelect: 'none', - MozUserSelect: 'none' - }} + {portfolio.projects.map((project, index) => ( + -
-
+ {/* Header with title and percentage */} +
+
-

{project.name}

+

{project.name}

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

+ + {/* Description */} +

{project.shortDescription || project.description}

-
-
- Price per ton: - + + {/* Price info */} +
+
+ Price per ton: + ${project.pricePerTon.toFixed(2)}
-
- 👆 Click for details -
-
+ + {/* Click button - Primary call to action */} + + + {/* Fallback click area - covers entire card */} +
{ + e.preventDefault(); + e.stopPropagation(); + handleProjectClick(project, e); + }} + onTouchEnd={(e) => { + e.preventDefault(); + e.stopPropagation(); + handleProjectClick(project); + }} + onKeyDown={(e) => { + if (e.key === 'Enter' || e.key === ' ') { + e.preventDefault(); + handleProjectClick(project); + } + }} + role="button" + tabIndex={0} + aria-label={`View details for ${project.name}`} + /> + ))} )}