Open History to see the last commit
1import {
2 connectionStatusText,
3 type EnvironmentConnectionPresentation,
4} from "@t3tools/client-runtime/connection";
5
6export interface SavedCloudEnvironmentConnectionPresentation {
7 readonly buttonLabel: string;
8 readonly statusText: string;
9 readonly tone: "connected" | "connecting" | "error" | "idle";
10}
11
12/**
13 * Present the live supervisor state for an environment that is already in the
14 * connection catalog. Catalog membership only means the environment is saved;
15 * it does not mean the connection attempt succeeded.
16 */
17export function presentSavedCloudEnvironmentConnection(
18 connection: EnvironmentConnectionPresentation,
19): SavedCloudEnvironmentConnectionPresentation {
20 switch (connection.phase) {
21 case "connected":
22 return {
23 buttonLabel: "Connected",
24 statusText: connectionStatusText(connection),
25 tone: "connected",
26 };
27 case "connecting":
28 return {
29 buttonLabel: "Connecting…",
30 statusText: connectionStatusText(connection),
31 tone: "connecting",
32 };
33 case "reconnecting":
34 return {
35 buttonLabel: "Reconnecting…",
36 statusText: connectionStatusText(connection),
37 tone: "connecting",
38 };
39 case "unsupported":
40 case "error":
41 return {
42 buttonLabel:
43 connection.phase === "unsupported" ? "Client not supported" : "Connection failed",
44 statusText: connectionStatusText(connection),
45 tone: "error",
46 };
47 case "offline":
48 return {
49 buttonLabel: "Offline",
50 statusText: connectionStatusText(connection),
51 tone: "idle",
52 };
53 case "available":
54 return {
55 buttonLabel: "Not connected",
56 statusText: connectionStatusText(connection),
57 tone: "idle",
58 };
59 }
60}