Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
2.2 kB ยท 66 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667"use client";
import { useQuery } from "@tanstack/react-query";
import { useTRPC } from "@/lib/trpc/client";
export function useCommandMenuData({ open }: { open: boolean }) { const trpc = useTRPC();
// `enabled: open` keeps the always-mounted palette from fetching on every // dashboard load; data stays cached once fetched. const { data: monitors } = useQuery( trpc.monitor.list.queryOptions(undefined, { enabled: open }), ); const { data: statusPages } = useQuery( trpc.page.list.queryOptions(undefined, { enabled: open }), ); const { data: workspaces } = useQuery( trpc.workspace.list.queryOptions(undefined, { enabled: open }), ); const { data: workspace } = useQuery( trpc.workspace.get.queryOptions(undefined, { enabled: open }), ); // Inputs match the overview/create-sheet queries so create mutations // invalidate this cache entry too. const { data: statusReports } = useQuery( trpc.statusReport.list.queryOptions({}, { enabled: open }), ); const { data: maintenances } = useQuery( trpc.maintenance.list.queryOptions(undefined, { enabled: open }), );
const otherWorkspaces = workspaces?.filter((w) => w.slug !== workspace?.slug) ?? [];
// Unresolved reports first; within each partition keep server order (desc). const sortedStatusReports = statusReports ? [ ...statusReports.filter((r) => r.status !== "resolved"), ...statusReports.filter((r) => r.status === "resolved"), ] : undefined;
// Upcoming/active maintenances first, then past (server order desc). // Orphans without a page are skipped โ no route to navigate to. const now = Date.now(); const withPage = maintenances?.filter((m) => m.pageId !== null); const sortedMaintenances = withPage ? [ ...withPage.filter((m) => m.to.getTime() >= now), ...withPage.filter((m) => m.to.getTime() < now), ] : undefined;
const pageTitleById = new Map(statusPages?.map((p) => [p.id, p.title]) ?? []);
return { monitors, statusPages, statusReports, sortedStatusReports, sortedMaintenances, otherWorkspaces, pageTitleById, };}