import { MapContainer, Marker, Rectangle, TileLayer, Tooltip } from "react-leaflet"; import L from "leaflet"; import { useCallback, useState } from "react"; import Modal from 'react-modal'; import "./index.css"; type SetState = React.Dispatch>; type StateInit = [T, SetState]; function Login(params: { modal: StateInit, login: StateInit; }) { const {modal, login} = params; const customStyles = { content: { top: '50%', left: '50%', right: 'auto', bottom: 'auto', marginRight: '-50%', transform: 'translate(-50%, -50%)', }, }; const openModal = () => modal[1](true) const afterOpenModal = () => { } const closeModal = () => modal[1](false) return (<>

Authentification

{ // TODO Check Auth const l = e.get("login") if (l == null) return; closeModal() login[1](l.toString()) }}>

) } function Toolbar(params: { logged_in: [boolean,] }) { } export function App() { const [modalIsOpen, setModalIsOpen]: StateInit = useState(false); const [coords, setCoords]: StateInit<{ x: number; y: number }> = useState({ x: 0, y: 0 }) const [nextLabel, setNextLabel]: StateInit = useState("") const [currentZoom, setCurrentZoom]: StateInit = useState(0) const [markers, setMarkers]: StateInit<{ label: string; x: number; y: number }[]> = useState([ { label: "Spawn", x: 0, y: 0 } ]) const [login, setLogin]: StateInit = useState() let map = useCallback((it: L.Map | null) => { if (it == null) return; it.on('mousemove', (e) => { setCoords({ x: Math.round(e.latlng.lng), y: Math.round(e.latlng.lat) }) }) it.on('zoomend', (_) => setCurrentZoom(it.getZoom())) it.on('click', (e) => setMarkers([...markers, { label: nextLabel, x: Math.round(e.latlng.lng), y: Math.round(e.latlng.lat) }])) }, [coords, markers, nextLabel]) return (<>{ (!modalIsOpen) ? {(currentZoom > -2) ? markers.map((it, i) => ( {it.label} )) : null } : <> } { (login) ? <>

Mouse is at {coords.x}, {-coords.y}

setNextLabel(e.target.value)} value={nextLabel} />

Hello {login}!

: } ) } export default App;