import { useEffect, useState } from "react"; import { Button, Card, Group, Select, TextInput } from "@mantine/core"; import { notifications } from "@mantine/notifications"; // A request to the API; a refusal of the server shows as a notification -> the JSON returned, or null export async function call(path, method = "GET", body) { try { const r = await fetch(path, body === undefined ? { method } : { method, headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) }); const json = await r.json().catch(() => ({ error: r.statusText })); if (r.ok) return json; notifications.show({ color: "red", title: "Refused", message: json.error || r.statusText }); } catch (e) { notifications.show({ color: "red", title: "Server unreachable", message: e.message }); } return null; } // The station and the range (UTC, To excluded; empty: the whole period), shared by the pages through the address export function Selector({ selection, choose }) { const [stations, setStations] = useState([]), [s, setS] = useState(selection); useEffect(() => { call("/api/stations").then(l => l && setStations(l)); }, []); useEffect(() => setS(selection), [selection.station, selection.start, selection.end]); return (