Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

cloudEnvironmentConnectionPresentation.ts

58 lines1.7 KB

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";
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 "error":
40 return {
41 buttonLabel: "Connection failed",
42 statusText: connectionStatusText(connection),
43 tone: "error",
44 };
45 case "offline":
46 return {
47 buttonLabel: "Offline",
48 statusText: connectionStatusText(connection),
49 tone: "idle",
50 };
51 case "available":
52 return {
53 buttonLabel: "Not connected",
54 statusText: connectionStatusText(connection),
55 tone: "idle",
56 };
57 }