| 1 | "use client"; |
| 2 | |
| 3 | import { useEffect } from |
| 4 | import Link from "next/link |
| 5 | import { useRouter } |
| 6 | import { useQuery } |
| 7 | import { useTranslations } |
| 8 | import { Server } |
| 9 | import { orpc } |
| 10 | import { authClient } |
| 11 | import Loader from "@/components/loader |
| 12 | |
| 13 | type DbStatus |
| 14 | |
| 15 | type StatusConfig |
| 16 | |
| 17 | const STATUS_CONFIG: Record |
| 18 | installing: { color: " |
| 19 | install_failed: { color: " |
| 20 | suspended: { color: " |
| 21 | restoring_backup: { color: " |
| 22 | running: { color: " |
| 23 | starting: { color: " |
| 24 | stopping: { color: " |
| 25 | offline: { color: " |
| 26 | }; |
| 27 | |
| 28 | function getStatus(dbStatus: |
| 29 | if (dbStatus !== |
| 30 | if (loading) return |
| 31 | return STATUS_CONFIG[powerState |
| 32 | } |
| 33 | |
| 34 | type ServerItem |
| 35 | uuid: string |
| 36 | name: string |
| 37 | status: string |
| 38 | allocation: { |
| 39 | egg: { |
| 40 | }; |
| 41 | |
| 42 | function ServerCard({ server |
| 43 | server: ServerItem |
| 44 | powerState: string |
| 45 | statusLoading: boolean |
| 46 | }) { |
| 47 | const ts = |
| 48 | const tp = |
| 49 | const status = |
| 50 | const label = |
| 51 | |
| 52 | return ( |
| 53 | <Link href={ |
| 54 | <div className="flex flex-col gap-3 rounded-xl border border-border bg-card p-4 transition-colors duration-150 hover:border-foreground/30 |
| 55 | <div className="flex items-start justify-between gap-2 |
| 56 | <div className="flex min-w-0 items-center gap-2.5 |
| 57 | <span |
| 58 | className={`mt-0.5 h-2 w-2 shrink-0 rounded-full ${status |
| 59 | style={{ backgroundColor: |
| 60 | /> |
| 61 | <span className="truncate text-sm font-semibold text-foreground group-hover:text-foreground |
| 62 | {server.name} |
| 63 | </span> |
| 64 | </div> |
| 65 | {server.egg && |
| 66 | <span className="shrink-0 rounded-md border bg-muted px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground |
| 67 | {server.egg.name |
| 68 | </span> |
| 69 | )} |
| 70 | </div> |
| 71 | |
| 72 | <div className="flex items-center justify-between |
| 73 | <span className="text-xs text-muted-foreground |
| 74 | {server.allocation ? |
| 75 | </span> |
| 76 | <span |
| 77 | className="rounded-full px-2 py-0.5 text-[11px] font-medium" |
| 78 | style={{ color: |
| 79 | > |
| 80 | {label} |
| 81 | </span> |
| 82 | </div> |
| 83 | </div> |
| 84 | </Link> |
| 85 | ); |
| 86 | } |
| 87 | |
| 88 | export default function ServersPage |
| 89 | const t = |
| 90 | const router = |
| 91 | const { data: |
| 92 | |
| 93 | useEffect(() => |
| 94 | if (!sessionPending && |
| 95 | }, [sessionPending, |
| 96 | |
| 97 | const { data: |
| 98 | orpc.servers.list |
| 99 | ); |
| 100 | |
| 101 | const { data: |
| 102 | ...orpc.servers. |
| 103 | enabled: !serversPending && |
| 104 | refetchInterval: 30_000, |
| 105 | }); |
| 106 | |
| 107 | if (sessionPending || |
| 108 | |
| 109 | const list = |
| 110 | |
| 111 | return ( |
| 112 | <> |
| 113 | <div className="flex-1 overflow-auto |
| 114 | {serversPending ? ( |
| 115 | <Loader /> |
| 116 | ) : list.length |
| 117 | <div className="flex h-full flex-col items-center justify-center gap-3 |
| 118 | <div className="flex h-12 w-12 items-center justify-center rounded-full bg-muted |
| 119 | <Server className=" |
| 120 | </div> |
| 121 | <div className="text-center |
| 122 | <p className="text-sm font-medium text-foreground |
| 123 | <p className="text-xs text-muted-foreground |
| 124 | </div> |
| 125 | </div> |
| 126 | ) : ( |
| 127 | <div className="grid grid-cols-1 gap-3 p-4 sm:grid-cols-2 lg:grid-cols-3 |
| 128 | {list.map(( |
| 129 | <ServerCard |
| 130 | key={server.uuid |
| 131 | server={server as |
| 132 | powerState={statuses?.[ |
| 133 | statusLoading={statusesPending} |
| 134 | /> |
| 135 | ))} |
| 136 | </div> |
| 137 | )} |
| 138 | </div> |
| 139 | </> |
| 140 | ); |
| 141 | } |