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

cloudEnvironmentConnectionPresentation.ts

59 lines1.6 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​
12export function presentSavedCloudEnvironmentConnection(
13 connection: EnvironmentConnectionPresentation,
14): SavedCloudEnvironmentConnectionPresentation {
15 switch (connection.phase) {
16 case "connected":
17 return {
18 buttonLabel: "Connected",
19 statusText: connectionStatusText(connection),
20 tone: "connected",
21 };
22 case "connecting":
23 return {
24 buttonLabel: "Connecting…",
25 statusText: connectionStatusText(connection),
26 tone: "connecting",
27 };
28 case "reconnecting":
29 return {
30 buttonLabel: "Reconnecting…",
31 statusText: connectionStatusText(connection),
32 tone: "connecting",
33 };
34 case "unsupported":
35 return {
36 buttonLabel: "Client not supported",
37 statusText: connectionStatusText(connection),
38 tone: "idle",
39 };
40 case "error":
41 return {
42 buttonLabel: "Connection failed",
43 statusText: connectionStatusText(connection),
44 tone: "error",
45 };
46 case "offline":
47 return {
48 buttonLabel: "Offline",
49 statusText: connectionStatusText(connection),
50 tone: "idle",
51 };
52 case "available":
53 return {
54 buttonLabel: "Not connected",
55 statusText: connectionStatusText(connection),
56 tone: "idle",
57 };
58 }