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
| 1 | import { |
| 2 | ANOTHER_ADDRESS, |
| 3 | type LinkableMachine, |
| 4 | linkDestination, |
| 5 | } from "@t3tools/client-runtime/link-request"; |
| 6 | import { T, useGT } from "gt-react"; |
| 7 | import { useId } from "react"; |
| 8 | |
| 9 | import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon"; |
| 10 | import { Alert, AlertDescription, AlertTitle } from "../ui/alert"; |
| 11 | import { Badge } from "../ui/badge"; |
| 12 | import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select"; |
| 13 | |
| 14 | const T3_CONNECT_NAME = "T3 Connect"; |
| 15 | |
| 16 | /** |
| 17 | * Shown wherever a link goes to an address this app does not already have for a |
| 18 | * machine, with where that address leads. |
| 19 | */ |
| 20 | export function LinkAddressWarning({ address }: { readonly address: string }) { |
| 21 | return ( |
| 22 | <Alert variant="warning"> |
| 23 | <AlertTitle> |
| 24 | <T>Check this address</T> |
| 25 | </AlertTitle> |
| 26 | <AlertDescription> |
| 27 | <T> |
| 28 | This app cannot confirm it is one of your machines. The pairing code you paste is sent |
| 29 | there. |
| 30 | </T> |
| 31 | <span className="block break-all">{linkDestination(address)}</span> |
| 32 | </AlertDescription> |
| 33 | </Alert> |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | /** Whether a machine is linked already, or how this app knows it when not connected to it. */ |
| 38 | export function LinkMachineBadge({ machine }: { readonly machine: LinkableMachine }) { |
| 39 | const gt = useGT(); |
| 40 | if (machine.linked) { |
| 41 | return ( |
| 42 | <Badge variant="success" size="sm"> |
| 43 | <T>Linked</T> |
| 44 | </Badge> |
| 45 | ); |
| 46 | } |
| 47 | if (machine.connected) return null; |
| 48 | return ( |
| 49 | <Badge variant="outline" size="sm"> |
| 50 | {machine.connectOnly ? T3_CONNECT_NAME : gt("Not connected")} |
| 51 | </Badge> |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | function MachineName({ machine }: { readonly machine: LinkableMachine }) { |
| 56 | return ( |
| 57 | <span className="flex min-w-0 items-center gap-2"> |
| 58 | <EnvironmentMachineIcon kind={machine.machine} className="size-4 shrink-0 opacity-80" /> |
| 59 | <span className="min-w-0 truncate">{machine.label}</span> |
| 60 | </span> |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | /** The user's other machines, including those on their T3 Connect account, then an address. */ |
| 65 | export function LinkMachineSelect({ |
| 66 | machines, |
| 67 | value, |
| 68 | onChange, |
| 69 | disabled, |
| 70 | }: { |
| 71 | readonly machines: ReadonlyArray<LinkableMachine>; |
| 72 | readonly value: string | null; |
| 73 | readonly onChange: (value: string) => void; |
| 74 | readonly disabled: boolean; |
| 75 | }) { |
| 76 | const gt = useGT(); |
| 77 | const labelId = useId(); |
| 78 | return ( |
| 79 | <div className="space-y-1.5"> |
| 80 | <span id={labelId} className="block text-xs font-medium text-foreground"> |
| 81 | <T>Machine</T> |
| 82 | </span> |
| 83 | <Select |
| 84 | value={value} |
| 85 | disabled={disabled} |
| 86 | onValueChange={(next) => { |
| 87 | if (next !== null) onChange(next as string); |
| 88 | }} |
| 89 | > |
| 90 | <SelectTrigger aria-labelledby={labelId}> |
| 91 | <SelectValue> |
| 92 | {(selected: string | null) => { |
| 93 | if (selected === ANOTHER_ADDRESS) return gt("Another address…"); |
| 94 | const machine = machines.find((candidate) => candidate.environmentId === selected); |
| 95 | return machine === undefined ? ( |
| 96 | gt("Choose a machine") |
| 97 | ) : ( |
| 98 | <MachineName machine={machine} /> |
| 99 | ); |
| 100 | }} |
| 101 | </SelectValue> |
| 102 | </SelectTrigger> |
| 103 | <SelectPopup alignItemWithTrigger={false}> |
| 104 | {machines.map((machine) => ( |
| 105 | <SelectItem key={machine.environmentId} value={machine.environmentId} hideIndicator> |
| 106 | <span className="flex min-w-0 items-center justify-between gap-3"> |
| 107 | <MachineName machine={machine} /> |
| 108 | <LinkMachineBadge machine={machine} /> |
| 109 | </span> |
| 110 | </SelectItem> |
| 111 | ))} |
| 112 | <SelectItem value={ANOTHER_ADDRESS} hideIndicator> |
| 113 | <T>Another address…</T> |
| 114 | </SelectItem> |
| 115 | </SelectPopup> |
| 116 | </Select> |
| 117 | </div> |
| 118 | ); |
| 119 | } |