"use client";
import { useNodes, useUnconfiguredNodes } from "@/lib/useNodes";
import { useCalls, useActiveCalls } from "@/lib/useCalls";
import { useSystems } from "@/lib/useSystems";
import { NodeCard } from "@/components/NodeCard";
import { CallRow } from "@/components/CallRow";
import { NodeConfigModal } from "@/components/NodeConfigModal";
import { useState } from "react";
import type { NodeRecord } from "@/lib/types";
import { useAuth } from "@/components/AuthProvider";
function StatCard({ label, value, accent }: { label: string; value: string | number; accent?: string }) {
return (
);
}
export default function DashboardPage() {
const { nodes, error: nodesError } = useNodes();
const { nodes: pending } = useUnconfiguredNodes();
const { calls, error: callsError } = useCalls(20);
const activeCalls = useActiveCalls();
const { systems, error: systemsError } = useSystems();
const [configNode, setConfigNode] = useState(null);
const { isAdmin } = useAuth();
const systemMap = Object.fromEntries(systems.map((s) => [s.system_id, s]));
const onlineCount = nodes.filter((n) => n.status !== "offline").length;
const fsError = nodesError ?? callsError ?? systemsError;
return (
Dashboard
{fsError && (
Firestore error: {fsError}
)}
{/* Pending config banner */}
{pending.length > 0 && (
{pending.length} new node{pending.length > 1 ? "s" : ""} connected and need{pending.length === 1 ? "s" : ""} configuration.
)}
{/* Stats */}
0 ? "text-orange-400" : undefined} />
{/* Nodes */}
Nodes
{nodes.length === 0 ? (
No nodes registered yet.
) : (
{nodes.map((n) => (
))}
)}
{/* Recent calls */}
Recent Calls
{calls.length === 0 ? (
No calls recorded yet.
) : (
| Time |
Talkgroup |
System |
Node |
Duration |
Audio |
{calls.map((c) => (
))}
)}
{configNode && (
setConfigNode(null)}
/>
)}
);
}