2026-11-18 15:13:25 +01:00
|
|
|
import { useEffect, useRef, useState } from "react";
|
2026-11-17 08:59:51 +01:00
|
|
|
import { Button, Card, Group, Select, TextInput } from "@mantine/core";
|
2026-11-16 12:40:03 +01:00
|
|
|
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 {
|
2026-11-17 10:19:58 +01:00
|
|
|
// every POST, PUT, DELETE declares JSON, even without a body: the server refuses it otherwise (its guard)
|
|
|
|
|
const r = await fetch(path, method === "GET" ? { method }
|
|
|
|
|
: { method, headers: { "Content-Type": "application/json" }, body: JSON.stringify(body ?? {}) });
|
2026-11-16 12:40:03 +01:00
|
|
|
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 }) {
|
2026-11-17 08:59:51 +01:00
|
|
|
const [stations, setStations] = useState([]), [s, setS] = useState(selection);
|
|
|
|
|
useEffect(() => { call("/api/stations").then(l => l && setStations(l)); }, []);
|
|
|
|
|
useEffect(() => setS(selection), [selection]); // a new object at each change of the address
|
2026-11-16 12:40:03 +01:00
|
|
|
return (
|
|
|
|
|
<Card shadow="sm" withBorder>
|
|
|
|
|
<Group align="flex-end" gap="md">
|
|
|
|
|
<Select label="Station" placeholder="Choose" data={stations} value={s.station || null} searchable w={200}
|
|
|
|
|
onChange={v => setS({ ...s, station: v || "" })} />
|
|
|
|
|
<TextInput label="From (UTC)" type="date" value={s.start} onChange={e => setS({ ...s, start: e.currentTarget.value })} />
|
|
|
|
|
<TextInput label="To (excluded)" type="date" value={s.end} onChange={e => setS({ ...s, end: e.currentTarget.value })} />
|
|
|
|
|
<Button onClick={() => choose(s)} disabled={!s.station}>Load</Button>
|
|
|
|
|
</Group>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-11-18 15:13:25 +01:00
|
|
|
|
|
|
|
|
// A markdown rendered by the server (report, summary, transcript), at the height of its content once its images are loaded;
|
|
|
|
|
// sandboxed: no script runs in it
|
|
|
|
|
export function Page({ title, src }) {
|
|
|
|
|
const frame = useRef();
|
|
|
|
|
const fit = () => { const b = frame.current?.contentDocument?.body; if (b) frame.current.style.height = `${b.scrollHeight + 20}px`; };
|
|
|
|
|
return <iframe ref={frame} title={title} sandbox="allow-same-origin" onLoad={fit} style={{ border: 0, width: "100%", height: 400 }} src={src} />;
|
|
|
|
|
}
|