import React, { useEffect, useState } from "react"; import styles from "./MapInfoModal.module.css"; 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"; import { useNavigate } from "react-router-dom"; export default function MapInfoModal({ isOpen, onClose, map, onDelete, onUpdate, onPublish, published = false, }) { const [isEditPopupOpen, setEditPopupOpen] = useState(false); const [editedName, setEditedName] = useState(""); const [editedGmapsUrl, setEditedGmapsUrl] = useState(""); const [editedType, setEditedType] = useState(""); const [publishFormOpen, setPublishFormOpen] = useState(false); const navigate = useNavigate(); const [loadedFormData, setLoadedFormData] = useState(null); const { setLoading } = useAppContext(); const { loading } = useAppContext(); const { username } = useAppContext(); useEffect(() => { if (map) { setEditedName(map.mapName || ""); setEditedGmapsUrl(map.gmaps_url || ""); setEditedType(map.mapType || ""); } }, [map, isEditPopupOpen]); if (!isOpen || !map) return null; const handleView = () => { navigate(`/myMaps/View/${map.mapName}`); }; const handleEdit = () => { navigate(`/myMaps/Draw/${map.mapName}`); }; 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 = { initialName: map.mapName, name: editedName, gmapsUrl: editedGmapsUrl, type: editedType, }; onUpdate(updatedMap); closeEditPopup() }; return (
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