import React, {useEffect, useState} from "react"; import styles from "./MapInfoModal.module.css"; import {json, useNavigate} from "react-router-dom"; import edit_icon from "../../assets/edit_icon_black.png"; import PublishForm from "../PublishForm/PublishForm.jsx"; import HttpService from "../../scripts/net/HttpService.js"; import config from "../../scripts/net/netconfig.js"; import {useAppContext} from "../AppContext/AppContext.jsx"; export default function MapInfoModal({isOpen, onClose, map, onDelete, onUpdate, onPublish, published=false}) { const [isEditPopupOpen, setEditPopupOpen] = useState(false); const [editedName, setEditedName] = useState(map?.mapName || ""); const [editedGmapsUrl, setEditedGmapsUrl] = useState(map?.gmaps_url || ""); const [publishFormOpen,setPublishFormOpen] = useState(false) const navigate = useNavigate(); const[loadedFormData,setLoadedFormData] = useState(null) useEffect(() => { console.log("GMAPS: " + JSON.stringify(map)) }, []); const {username} = useAppContext(); if (!isOpen || !map) return null; const handleView = () => { navigate(`/myMaps/${map.mapName}/View`) }; const handleEdit = () => { navigate(`/myMaps/${map.mapName}/Draw`) }; const handleDelete = () => { if (window.confirm(`Are you sure you want to delete the map "${map.mapName}"?`)) { onDelete(map.mapName); onClose(); } }; const openEditPopup = () => { setEditPopupOpen(true); }; const closeEditPopup = () => { setEditPopupOpen(false); }; const handleEditSubmit = async () => { const updatedMap = { ...map, mapName: editedName, gmaps_url: editedGmapsUrl, }; try { //await onUpdate(updatedMap); setEditPopupOpen(false); } catch (error) { console.error("Error updating map:", error); } }; const openPublishModal = async () => { const httpService = new HttpService(true); const respForm = await httpService.get(`${config.my_maps.publish_get}?mapName=${map.mapName}`) setLoadedFormData(respForm); setPublishFormOpen(true) }; const sendPublishRequest = async (formData) => { const httpService = new HttpService(true); formData.mapName = map.mapName; console.log("FORMDATA: "+JSON.stringify(formData)) await httpService.post(`${config.my_maps.publish}?username=${username}`,formData); setPublishFormOpen(false) onPublish() } return (
e.stopPropagation()}> {publishFormOpen && ( setPublishFormOpen(false)}/> )} Map Thumbnail

{map.mapName} Edit

Status: {map.status}

Created At: {new Date(map.created_at).toLocaleString()}

Modified At: {new Date(map.modified_at).toLocaleString()}

Published At: {map.published_at ? new Date(map.published_at).toLocaleString() : "Not published yet"}

Google Maps URL: Open in Google Maps

{!map.is_published && !published && ( )}
{isEditPopupOpen && (
e.stopPropagation()} >

Edit Map Details

setEditedName(e.target.value)} />
setEditedGmapsUrl(e.target.value)} />
)}
); }