@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 66 lines 2.05 KB
Raw
1 import {
2 connectionStatusText,
3 type EnvironmentConnectionPresentation,
4 } from "@t3tools/client-runtime/connection";
5 import { msg } from "gt-react";
6
7 import { m, type MessageResolver } from "~/i18n/messages";
8
9 export interface SavedCloudEnvironmentConnectionPresentation {
10 readonly buttonLabel: string;
11 readonly statusText: string;
12 readonly tone: "connected" | "connecting" | "error" | "idle";
13 }
14
15 /** Components pass `useMessages()` so the label follows a language switch. */
16 export function presentSavedCloudEnvironmentConnection(
17 connection: EnvironmentConnectionPresentation,
18 resolve: MessageResolver = m,
19 ): SavedCloudEnvironmentConnectionPresentation {
20 switch (connection.phase) {
21 case "connected":
22 return {
23 buttonLabel: resolve(msg("Connected")),
24 statusText: connectionStatusText(connection, resolve),
25 tone: "connected",
26 };
27 case "connecting":
28 return {
29 buttonLabel: resolve(msg("Connecting…")),
30 statusText: connectionStatusText(connection, resolve),
31 tone: "connecting",
32 };
33 case "reconnecting":
34 return {
35 buttonLabel: connection.awaitingApproval
36 ? resolve(msg("Waiting for approval…"))
37 : resolve(msg("Reconnecting…")),
38 statusText: connectionStatusText(connection, resolve),
39 tone: "connecting",
40 };
41 case "unsupported":
42 return {
43 buttonLabel: resolve(msg("Client not supported")),
44 statusText: connectionStatusText(connection, resolve),
45 tone: "idle",
46 };
47 case "error":
48 return {
49 buttonLabel: resolve(msg("Connection failed")),
50 statusText: connectionStatusText(connection, resolve),
51 tone: "error",
52 };
53 case "offline":
54 return {
55 buttonLabel: resolve(msg("Offline")),
56 statusText: connectionStatusText(connection, resolve),
57 tone: "idle",
58 };
59 case "available":
60 return {
61 buttonLabel: resolve(msg("Not connected")),
62 statusText: connectionStatusText(connection, resolve),
63 tone: "idle",
64 };
65 }
66 }