"use client"; import type { Widget } from "@/lib/config/schema"; import { useWidgetSubscription } from "@/lib/ws/client"; import { StatusDot } from "@/components/widgets/StatusDot"; import { SkeletonLines } from "@/components/widgets/Skeleton"; import { WidgetCard } from "@/components/widgets/WidgetCard"; import { MetricBar } from "@/components/widgets/MetricBar"; import { BrandIcon } from "@/components/widgets/BrandIcon"; import { formatBytes, formatUptime } from "@/lib/format"; type DockerWidget = Extract; export function DockerWidget({ widget, widgetId }: { widget: DockerWidget; widgetId: string }) { const result = useWidgetSubscription(widgetId); const data = result?.type === "docker" ? result.data : null; const errorMessage = result?.type === "error" ? result.message : null; const memPercent = data?.memUsageBytes != null && data.memLimitBytes ? (data.memUsageBytes / data.memLimitBytes) * 100 : null; return (
{widget.href ? ( {widget.name} ) : ( {widget.name} )}
{errorMessage && {errorMessage}} {!result && !errorMessage && } {data && ( <> {widget.showStats && data.cpuPercent !== null && memPercent !== null && (
)}
{data.uptimeSeconds !== null && up {formatUptime(data.uptimeSeconds)}} {widget.showStats && data.memUsageBytes !== null && memPercent === null && ( {formatBytes(data.memUsageBytes)} )} {data.restartCount > 0 && {data.restartCount} restarts}
)}
); }