Files
dc-observatio/services/pcp-tgu-ui-service/src/features/constellation/ConstellationTab.tsx
T

76 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* ============================================================
ConstellationTab.tsx — обёртка вкладки «Группировка» с реальными данными.
Грузит состав/геометрию/расписание из API (realData.ts) и монтирует
прототипный ConstellationDashboard уже с готовыми env/domain/sched — поэтому
его mount-once замыкания (RAF/canvas) видят стабильные данные с первого рендера.
============================================================ */
import { useEffect, useState, type ComponentType } from "react";
import ConstellationDashboardImpl from "./ConstellationDashboard.jsx";
import { loadConstellationEnv, type ConstellationConfig } from "./realData";
import "./dashboard.css";
// ConstellationDashboard — JS-модуль прототипа; типизируем точку монтирования.
const ConstellationDashboard = ConstellationDashboardImpl as ComponentType<ConstellationConfig>;
type LoadState =
| { kind: "loading" }
| { kind: "error"; message: string }
| { kind: "ready"; cfg: ConstellationConfig };
export function ConstellationTab() {
const [state, setState] = useState<LoadState>({ kind: "loading" });
useEffect(() => {
let cancelled = false;
setState({ kind: "loading" });
loadConstellationEnv()
.then((cfg) => {
if (!cancelled) setState({ kind: "ready", cfg });
})
.catch((error: unknown) => {
if (!cancelled) {
setState({ kind: "error", message: error instanceof Error ? error.message : "Не удалось загрузить данные группировки." });
}
});
return () => {
cancelled = true;
};
}, []);
if (state.kind === "loading") {
return <ConstellationNotice text="Загрузка состояния группировки…" />;
}
if (state.kind === "error") {
return <ConstellationNotice text={`Ошибка загрузки: ${state.message}`} tone="error" />;
}
if (state.cfg.env.sats.length === 0) {
return <ConstellationNotice text="Нет эксплуатируемых КА с доступной трассой на горизонте планирования." />;
}
return <ConstellationDashboard env={state.cfg.env} domain={state.cfg.domain} sched={state.cfg.sched} />;
}
function ConstellationNotice({ text, tone }: { text: string; tone?: "error" }) {
return (
<div
className="cdash"
style={{
height: "100%",
display: "flex",
alignItems: "center",
justifyContent: "center",
background: "#0a0c0b",
color: tone === "error" ? "#d9685f" : "#95a19d",
fontFamily: "'IBM Plex Mono', monospace",
fontSize: 13,
letterSpacing: ".04em",
padding: 24,
textAlign: "center"
}}
>
{text}
</div>
);
}
export default ConstellationTab;