import React, { useState, useEffect } from "react"; import styles from "./LoadMap.module.css"; import HttpService from "../../scripts/net/HttpService"; const MapTemplateSelector = ({ loadHandler }) => { const [templates, setTemplates] = useState([]); const [selectedTemplate, setSelectedTemplate] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { const fetchTemplates = async () => { const httpService = new HttpService("http://localhost:8080/api/protected", true); try { const response = await httpService.get("/maps"); setTemplates(response); setLoading(false); } catch (error) { console.error("Error fetching templates:", error); setLoading(false); } }; fetchTemplates(); }, []); const handleSelect = async (template) => { setSelectedTemplate(template); console.log("Selected template:", template); const httpService = new HttpService("http://localhost:8080/api/protected", true); const response = await httpService.get(`/maps/load?mapName=${template.name}`); console.log("LOAD TEMPLATE: ", response); const data = response.map.mapData.textData; loadHandler(data); }; if (loading) { return
Loading map templates...
; } return (

Templates

{templates.length > 0 ? ( ) : (

No map templates available.

)} {selectedTemplate && (

Loaded Template:

{selectedTemplate.name}

)}
); }; export default MapTemplateSelector;