From df2e11f600834970a66693513a39dff330375d1b Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 3 Jun 2025 15:25:13 +0200 Subject: [PATCH] updates --- src/components/OffsetOrder.tsx | 125 +++++++++++++-------------------- 1 file changed, 49 insertions(+), 76 deletions(-) diff --git a/src/components/OffsetOrder.tsx b/src/components/OffsetOrder.tsx index b53fe37..8c64fce 100644 --- a/src/components/OffsetOrder.tsx +++ b/src/components/OffsetOrder.tsx @@ -1,6 +1,6 @@ import React, { useState, useEffect } from 'react'; import { Check, AlertCircle, ArrowLeft, Loader2, Globe2, TreePine, Waves, Factory, Wind, X } from 'lucide-react'; -import { motion, AnimatePresence } from 'framer-motion'; +import { motion } from 'framer-motion'; import { createOffsetOrder, getPortfolios } from '../api/wrenClient'; import type { CurrencyCode, OffsetOrder as OffsetOrderType, Portfolio, OffsetProject } from '../types'; import { currencies, formatCurrency, getCurrencyByCode } from '../utils/currencies'; @@ -128,26 +128,18 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr // Calculate offset cost using the portfolio price const offsetCost = monetaryAmount || (portfolio ? tons * (portfolio.pricePerTon || 18) : 0); - // Simplified handler for project selection with maximum debugging - const handleProjectClick = (project: OffsetProject) => { - console.log('=== PROJECT CLICK HANDLER FIRED ==='); - console.log('Project name:', project.name); - console.log('Project ID:', project.id); - console.log('Current selectedProject state:', selectedProject?.name || 'null'); - - // Force the state update + // Completely simplified project selection handler + const handleProjectClick = (project: OffsetProject, e: React.MouseEvent) => { + e.preventDefault(); + e.stopPropagation(); + console.log('Opening project details for:', project.name); setSelectedProject(project); - - console.log('State updated to:', project.name); - console.log('=== END PROJECT CLICK HANDLER ==='); }; - // Handler for closing the lightbox - const handleCloseLightbox = (e: React.MouseEvent | React.TouchEvent) => { - if (e) e.preventDefault(); - console.log('=== CLOSING LIGHTBOX ==='); + // Simple lightbox close handler + const handleCloseLightbox = () => { + console.log('Closing lightbox'); setSelectedProject(null); - console.log('selectedProject set to null'); }; return ( @@ -351,16 +343,13 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr animate={{ opacity: 1 }} transition={{ duration: 0.5, delay: 0.3 }} > - {portfolio.projects.map((project, index) => ( + {portfolio.projects.map((project) => (
{ - e.preventDefault(); - e.stopPropagation(); - console.log('Project clicked:', project.name); - handleProjectClick(project); - }} + onClick={(e) => handleProjectClick(project, e)} + role="button" + tabIndex={0} style={{ userSelect: 'none', WebkitUserSelect: 'none', @@ -476,59 +465,44 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr ) : null} - {/* Debug info */} + {/* Simplified Lightbox Modal */} {selectedProject && ( -
- Selected: {selectedProject.name} -
- )} - - {/* Project Lightbox Modal */} - - {selectedProject && ( - handleCloseLightbox(e)} - initial={{ opacity: 0 }} - animate={{ opacity: 1 }} - exit={{ opacity: 0 }} +
+
e.stopPropagation()} > - {/* Modal Content */} -
e.stopPropagation()} + {/* Close Button */} + - - {/* Project Image */} - {selectedProject.imageUrl && ( -
- {selectedProject.name} -
-
-

{selectedProject.name}

-
- - {selectedProject.type || 'Environmental Project'} -
+ + + + {/* Project Image */} + {selectedProject.imageUrl && ( +
+ {selectedProject.name} +
+
+

{selectedProject.name}

+
+ + {selectedProject.type || 'Environmental Project'}
- )} +
+ )} {/* Project Details */}
@@ -584,11 +558,10 @@ export function OffsetOrder({ tons, monetaryAmount, onBack, calculatorType }: Pr

)} -
- - )} - +
+
+ )} ); }