import { useState, useRef } from "preact/hooks"; import { createClient } from "@connectrpc/connect"; import { createConnectTransport } from "@connectrpc/connect-web"; import { Container, Server, X } from "lucide-preact"; import type { Service } from "../gen/homelab/v1/homelab_pb"; import { HomelabService, ServiceKind, ServiceOp, } from "../gen/homelab/v1/homelab_pb"; const client = createClient( HomelabService, createConnectTransport({ baseUrl: "" }), ); /** Бейдж статуса: systemd — active/failed/выключен (not-found = намеренно disabled, не ошибка), docker — агрегат проекта. */ function badge(s: Service) { if (s.error) return ( ошибка ); if (s.kind === ServiceKind.DOCKER) { if (s.state === "active") return ( работает {s.substate} ); if (s.state === "partial") return ( частично {s.substate} ); return остановлен; } if (s.loadState === "not-found") return выключен; if (s.state === "active") return ( {s.substate || "активен"} ); if (s.state === "failed") return сбой; return остановлен; } /** Кнопки контроля; вынесены, чтобы переиспользовать на карточке и в модалке. */ function Controls({ s, onAct, busy, }: { s: Service; onAct: (op: ServiceOp) => void; busy: boolean; }) { const disabled = s.kind === ServiceKind.SYSTEMD && s.loadState === "not-found"; const btn = (op: ServiceOp, label: string, title?: string) => ( ); return (
{s.containers.join(", ")}
)}
{infoBusy ? "…" : info}