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

main
tsx 70 lines 2.51 KB
Raw
1 import type { DeviceServiceState, EnvironmentId } from "@t3tools/contracts";
2 import { T, useGT } from "gt-react";
3 import { useState } from "react";
4 import { Button } from "~/components/ui/button";
5 import { deviceEnvironment } from "~/state/device";
6 import { useAtomCommand } from "~/state/use-atom-command";
7
8 export function DeviceHostUpdates({
9 state,
10 environmentId,
11 }: {
12 state: DeviceServiceState;
13 environmentId: EnvironmentId;
14 }) {
15 const gt = useGT();
16 const retry = useAtomCommand(deviceEnvironment.list);
17 const [pending, setPending] = useState<string | null>(null);
18 if (state.hostStatus === "disabled") return null;
19 return (
20 <div className="space-y-2">
21 {state.hosts.map((host) => {
22 const status = state.hostStatuses[host.id];
23 if (!status || !["installing", "starting", "failed"].includes(status.status)) return null;
24 const failed = status.status === "failed";
25 return (
26 <div
27 key={host.id}
28 role={failed ? "alert" : "status"}
29 className="flex items-start gap-3 rounded-md border border-border/60 px-3 py-2 text-xs"
30 >
31 <div className="min-w-0 flex-1">
32 <p className="font-medium">{host.label}</p>
33 <p className="whitespace-pre-wrap break-words text-muted-foreground">
34 {status.detail ??
35 (failed
36 ? gt("Device support could not start.")
37 : status.status === "installing"
38 ? gt("Installing device tools…")
39 : gt("Starting device tools…"))}
40 </p>
41 {failed ? (
42 <p className="mt-1 text-muted-foreground">
43 <T>
44 Check the host connection and network access, then retry. Your device settings
45 are saved.
46 </T>
47 </p>
48 ) : null}
49 </div>
50 {failed && state.supportsHostRetry ? (
51 <Button
52 size="compact"
53 variant="outline"
54 disabled={pending !== null}
55 onClick={() => {
56 setPending(host.id);
57 void retry({ environmentId, input: { retryHostId: host.id } }).finally(() =>
58 setPending(null),
59 );
60 }}
61 >
62 {pending === host.id ? gt("Retrying…") : gt("Retry")}
63 </Button>
64 ) : null}
65 </div>
66 );
67 })}
68 </div>
69 );
70 }