mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 12:22:14 +03:00
Adiciona dashboard TUI com 7 abas (Overview, Combos, Providers, Keys, Logs, Health, Cost) via Ink, 13 componentes reutilizáveis em tui-components/, menu interativo ao iniciar sem subcomando, e flag --tui no comando dashboard.
26 lines
634 B
JavaScript
26 lines
634 B
JavaScript
import React, { useEffect, useState } from "react";
|
|
import { Text } from "ink";
|
|
|
|
export function HeaderSwr({ fetcher, interval = 5000, render, initial = null }) {
|
|
const [data, setData] = useState(initial);
|
|
|
|
useEffect(() => {
|
|
let cancelled = false;
|
|
async function tick() {
|
|
try {
|
|
const next = await fetcher();
|
|
if (!cancelled) setData(next);
|
|
} catch {}
|
|
}
|
|
tick();
|
|
const id = setInterval(tick, interval);
|
|
return () => {
|
|
cancelled = true;
|
|
clearInterval(id);
|
|
};
|
|
}, [fetcher, interval]);
|
|
|
|
if (!data) return <Text dimColor>Loading…</Text>;
|
|
return render(data);
|
|
}
|