diff --git a/web/src/app/servers/page.tsx b/web/src/app/servers/page.tsx index c703778..6062a33 100644 --- a/web/src/app/servers/page.tsx +++ b/web/src/app/servers/page.tsx @@ -11,7 +11,8 @@ export const metadata: Metadata = { export default function ServersPage() { return ( -

Servers

+ {/* The board shows this as its own heading from sm up; a phone keeps the two boards apart, so it needs one here. */} +

Servers

); diff --git a/web/src/features/servers/ServerActivity.tsx b/web/src/features/servers/ServerActivity.tsx index 61b2468..a2bf409 100644 --- a/web/src/features/servers/ServerActivity.tsx +++ b/web/src/features/servers/ServerActivity.tsx @@ -1,10 +1,10 @@ "use client"; -// Players online across listed servers over the last day, week, month or year. Hovering, tapping or arrow -// keys read a point: players and servers at that time. Every range arrives with the page, so switching is -// instant. +// The top of the Servers board from sm up, as its own card on a phone: players online across listed servers +// over the last day, week, month or year. Hovering, tapping or arrow keys read a point: players and servers +// at that time. Every range arrives with the page, so switching is instant. +import { useSearchParams } from "next/navigation"; import { type ReactNode, useState } from "react"; import type { Schemas } from "@/api/client"; -import { Card } from "@/ui/Card"; import { classNames } from "@/ui/classNames"; import { LineChart } from "@/ui/LineChart"; import { Segmented } from "@/ui/Segmented"; @@ -36,59 +36,84 @@ const date = new Intl.DateTimeFormat("en", { }); export function ServerActivity({ + heading, + servers, activity, }: { + /** Sits in the chart's top row, so the page doesn't spend a line on its own title. */ + heading: string; + /** + * The listed servers, so the headline can count online servers and players from what this viewer actually + * sees below, on whichever of Public or Whitelist is open. Stands in for the chart's own "now" point, which + * comes from the last finished bucket and so can lag behind it by up to the bucket length. + */ + servers?: Schemas["ListedServer"][]; activity: Partial>; }) { const [range, setRange] = useState("day"); const [active, setActive] = useState(null); + const whitelist = useSearchParams().get("view") === "whitelist"; + const shown = servers?.filter((s) => s.online && s.whitelist === whitelist); + const live = shown && { + servers: shown.length, + players: shown.reduce((sum, s) => sum + s.players, 0), + }; const current = activity[range]; const points = current?.points ?? []; // The longer ranges' buckets are averages, so "now" always comes from the day's. - const now = activity.day?.points.at(-1) ?? points.at(-1); + const now = live ?? activity.day?.points.at(-1) ?? points.at(-1); const hovered = active === null ? undefined : points[active]; - if (!current || !now || points.length < 2) return null; + // Hidden on a phone: the page's own heading covers it there, since the chart is its own card. + const title = ( +

{heading}

+ ); + // Without a chart to draw, the board still opens with its title; a phone shows nothing at all. + if (!current || !now || points.length < 2) + return
{title}
; const peak = Math.max(...points.map((point) => point.players)); return ( - -
-

- {hovered ? ( - <> - - {hovered.players === 1 ? "player" : "players"} - {range !== "day" && " on average"} - - - - {hovered.servers === 1 ? "server" : "servers"} - - - - {when(hovered.at, current.bucket_minutes)} - - - ) : ( - <> - 0 ? "text-success" : "text-danger"} - > - online now - - - - {now.servers === 1 ? "server" : "servers"} - - - peak in {rangeLabel(range)} - - )} -

+
+
+
+ {title} +

+ {hovered ? ( + <> + + {hovered.players === 1 ? "player" : "players"} + {range !== "day" && " on average"} + + + + {hovered.servers === 1 ? "server" : "servers"} + + + + {when(hovered.at, current.bucket_minutes)} + + + ) : ( + <> + 0 ? "text-success" : "text-danger"} + > + online now + + + + {now.servers === 1 ? "server" : "servers"} + + + peak in {rangeLabel(range)} + + )} +

+
-
+ {/* Darker than the board, so the trace reads as a screen rather than more flat fill. */} +
{edge(points.at(-1)?.at, range)}
- +
); } diff --git a/web/src/features/servers/ServerList.tsx b/web/src/features/servers/ServerList.tsx index bd03a94..ba269a2 100644 --- a/web/src/features/servers/ServerList.tsx +++ b/web/src/features/servers/ServerList.tsx @@ -1,5 +1,7 @@ // The Servers page: activity over time, then the listed servers running the SourceJump plugin, online ones -// first. Staff with manage_servers also see unlisted servers there, and list or unlist them in place. +// first. Staff with manage_servers also see unlisted servers there, and list or unlist them in place. From sm +// up this is one board; combining the chart and the list into one board read badly on a phone, so it keeps +// them as two boards there. import { api } from "@/api/client"; import { ServerActivity } from "./ServerActivity"; import { ServerRows } from "./ServerRows"; @@ -14,22 +16,30 @@ export async function ServerList() { ), ]); const servers = result?.data?.servers; - if (!servers) { - return

Servers couldn't be loaded. Try again in a moment.

; - } - if (servers.length === 0) return ; return ( -
+
0 + ? { + day: day?.data, + week: week?.data, + month: month?.data, + year: year?.data, + } + : {} + } /> - + {servers ? ( + + ) : ( +

+ Servers couldn't be loaded. Try again in a moment. +

+ )}
); } diff --git a/web/src/features/servers/ServerRow.tsx b/web/src/features/servers/ServerRow.tsx index 390f762..4220bca 100644 --- a/web/src/features/servers/ServerRow.tsx +++ b/web/src/features/servers/ServerRow.tsx @@ -1,5 +1,5 @@ // One server on the Servers page: a card on phones, a compact row wider. Staff rows add badges and tools. -import { Check, ImageOff } from "lucide-react"; +import { Check, ImageOff, Power } from "lucide-react"; import type { ReactNode } from "react"; import type { Schemas } from "@/api/client"; import { formatAgo } from "@/features/runs/time"; @@ -14,14 +14,11 @@ type Server = Schemas["ListedServer"]; export function ServerRow({ server, - unlisted = false, badges, tools, eager = false, }: { server: Server; - /** Shown to staff only: the public list never has unlisted servers. */ - unlisted?: boolean; badges?: ReactNode; /** Staff controls after Join, kept at full strength when the row is dimmed. */ tools?: ReactNode; @@ -32,30 +29,28 @@ export function ServerRow({ // Each part is dimmed on its own, not inside one wrapper, so the staff tools stay at full strength. const dim = classNames( "transition-opacity duration-(--duration-base)", - unlisted ? "opacity-50" : !server.online && "opacity-60", + // Only a server that's down is dimmed; staff marks like Unlisted are badges. + !server.online && "opacity-45", ); const connected = "Runs on this server count on SourceJump"; return ( - - {server.online ? "Online" : "Offline"} - + {!server.online && } + @@ -109,12 +104,7 @@ export function ServerRow({ - + {server.online && ( - Last seen{" "} - + const ago = ( + + ); + const offline = ( + + + Offline + + ); + return stacked ? ( + + {offline} + {/* Two short lines rather than one long one, so the column stays narrow next to the name and badges. */} + + Last seen + {ago} + + + ) : ( + + {offline} + ยท {ago} ); } @@ -233,19 +236,17 @@ function Players({ /** The row's box, shared with the staff-only row of a server listed before it was ever heard from. */ export function ServerRowFrame({ - unlisted = false, className, children, }: { - unlisted?: boolean; className?: string; children: ReactNode; }) { return (
diff --git a/web/src/features/servers/ServerRows.tsx b/web/src/features/servers/ServerRows.tsx index 5221bbe..de9aaf9 100644 --- a/web/src/features/servers/ServerRows.tsx +++ b/web/src/features/servers/ServerRows.tsx @@ -8,7 +8,6 @@ import type { CSSProperties, ReactNode } from "react"; import type { Schemas } from "@/api/client"; import { StaffServerRow } from "@/features/staff/servers/StaffServerRow"; import { useStaffServers } from "@/features/staff/servers/useStaffServers"; -import { Card } from "@/ui/Card"; import { ChoiceBar } from "@/ui/ChoiceBar"; import { classNames } from "@/ui/classNames"; import { LinkTabs } from "@/ui/LinkTabs"; @@ -24,18 +23,18 @@ export function ServerRows({ if (staff) { if (staff.servers.length === 0) { - return ( - - No server has sent a heartbeat or been listed yet. - - ); + return No server has sent a heartbeat or been listed yet.; } // A server listed before it was ever heard from has no mark to read, so it stays under Public. const marked = (server: Schemas["StaffServer"]) => server.server?.whitelist ?? false; - const shown = staff.servers.filter( - (server) => marked(server) === whitelist, - ); + const shown = staff.servers + .filter((server) => marked(server) === whitelist) + .sort( + (a, b) => + Number(!(a.server?.online ?? true)) - + Number(!(b.server?.online ?? true)), + ); return ( - No listed server has been online in the last day. - - ); + return No listed server has been online in the last day.; } - const shown = servers.filter((server) => server.whitelist === whitelist); + const shown = servers + .filter((server) => server.whitelist === whitelist) + .sort((a, b) => Number(!a.online) - Number(!b.online)); return ( +
{(hasWhitelist || whitelist) && ( - - - +
+ + + +
)} {rows.length > 0 ? ( ) : ( - + {whitelist ? "No whitelist server has been online in the last day." : "No public server has been online in the last day."} - + )}
); @@ -125,17 +124,22 @@ function Rows({ pairs: boolean; }) { return ( -
+
+ {/* From sm up each cell draws the line below it; pulled down a pixel so the last row's line sits on the + board's edge. A phone keeps the rows apart as separate cards instead. */}
    {rows.map(({ address, row }, index) => (
  • ); } + +function Note({ children }: { children: ReactNode }) { + return ( +

    + {children} +

    + ); +} diff --git a/web/src/features/staff/servers/StaffServerRow.tsx b/web/src/features/staff/servers/StaffServerRow.tsx index 3a1f964..70c76e9 100644 --- a/web/src/features/staff/servers/StaffServerRow.tsx +++ b/web/src/features/staff/servers/StaffServerRow.tsx @@ -26,7 +26,7 @@ export function StaffServerRow({ if (!server.server || !server.report) { return ( - + {server.address} @@ -41,7 +41,6 @@ export function StaffServerRow({ return ( {!listed && Unlisted}