import { useEffect, useState } from "react";//React, import { Box, Flex, Heading, Text, Spinner, SimpleGrid, Badge, Wrap, Tag, Divider, VStack, HStack, Input, Button, Avatar, } from "@chakra-ui/react"; import { MapContainer, TileLayer, Marker, Popup, useMap, } from "react-leaflet"; import L from "leaflet"; import "leaflet/dist/leaflet.css"; import type { ProjectDetailsProps, OrganizationLocation } from "../hooks/types"; import markerIconPng from "leaflet/dist/images/marker-icon.png"; import markerIcon2x from "leaflet/dist/images/marker-icon-2x.png"; import markerShadow from "leaflet/dist/images/marker-shadow.png"; const customIcon = new L.Icon({ iconUrl: markerIconPng, iconRetinaUrl: markerIcon2x, shadowUrl: markerShadow, iconSize: [25, 41], iconAnchor: [12, 41], popupAnchor: [1, -34], }); function ResizeMap({ count }: { count: number }) { const map = useMap(); useEffect(() => { map?.invalidateSize(); }, [count, map]); return null; } export default function ProjectDetails({ project, question, setQuestion, askChatbot, chatHistory = [], messagesEndRef, }: ProjectDetailsProps) { // fetch organization locations const [orgLocations, setOrgLocations] = useState([]); const [loadingOrgs, setLoadingOrgs] = useState(true); useEffect(() => { if (!project) return; setLoadingOrgs(true); fetch(`/api/project/${project.id}/organizations`) .then((r) => r.json()) .then((data) => Array.isArray(data) ? setOrgLocations(data) : console.error(data)) .catch(console.error) .finally(() => setLoadingOrgs(false)); }, [project]); if (!project) { return ( No project selected. ); } // Map center fallback const center: [number, number] = orgLocations.length ? [orgLocations[0].latitude, orgLocations[0].longitude] : [51.505, -0.09]; return ( {/* Left: Details */} {project.title} {project.status} ID {project.id} Acronym {project.acronym} Start Date {project.startDate} End Date {project.endDate} Funding (EC max) €{project.ecMaxContribution.toLocaleString()} Legal Basis {project.legalBasis} Framework Programme {project.frameworkProgramme} Objective {project.objective} {(project.list_euroSciVocTitle ?? []).length > 0 && ( EuroSciVoc Titles {(project.list_euroSciVocTitle ?? []).map((t) => ( {t} ))} )} {(project.list_euroSciVocPath ?? []).length > 0 && ( EuroSciVoc Paths {(project.list_euroSciVocPath ?? []).map((p) => ( {p} ))} )} Participating Organizations {loadingOrgs ? ( ) : ( {orgLocations.map((org, i) => ( {org.name} {org.country} ))} )} {/* Right: Chatbot */} Ask about this project {(chatHistory ?? []).map((msg, i) => ( {msg.role === "assistant" && } {msg.content} {msg.role === "user" && } ))}
setQuestion(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); askChatbot(); } }} /> ); }