The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useAuth } from "@clerk/react"; |
| 2 | import type { EnvironmentId } from "@t3tools/contracts"; |
| 3 | import { Link } from "@tanstack/react-router"; |
| 4 | import { T } from "gt-react"; |
| 5 | import { CheckIcon } from "lucide-react"; |
| 6 | import { type ReactNode, useState } from "react"; |
| 7 | |
| 8 | import { APP_DISPLAY_NAME, DESKTOP_DOWNLOAD_URL } from "~/branding"; |
| 9 | import { hasCloudPublicConfig } from "~/cloud/publicConfig"; |
| 10 | import { isElectron } from "../env"; |
| 11 | import { isLocalEnvironmentDisabled } from "../localEnvironment"; |
| 12 | import { useRelayEnvironmentDiscovery } from "../state/environments"; |
| 13 | import { InstallT3Commands } from "./InstallT3Commands"; |
| 14 | import { retryClerkLoad, useClerkLoadFailed } from "./clerk/clerkLoadFailure"; |
| 15 | import { useT3ConnectAuthPrompt } from "./clerk/useT3ConnectAuthPrompt"; |
| 16 | import { CloudEnvironmentConnectRows } from "./cloud/CloudEnvironmentConnectList"; |
| 17 | import { Button } from "./ui/button"; |
| 18 | import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyTitle } from "./ui/empty"; |
| 19 | import { SidebarInset } from "./ui/sidebar"; |
| 20 | import { WorkspacePageHeader } from "./WorkspacePageHeader"; |
| 21 | |
| 22 | /** Home screen for the hosted app before any computer is added. */ |
| 23 | export function HostedEmptyState() { |
| 24 | const cloudEnabled = hasCloudPublicConfig(); |
| 25 | const localEnvironmentOff = isLocalEnvironmentDisabled(); |
| 26 | |
| 27 | return ( |
| 28 | <SidebarInset className="h-dvh min-h-0 overflow-hidden overscroll-y-none"> |
| 29 | <div className="flex min-h-0 min-w-0 flex-1 flex-col overflow-x-hidden bg-background"> |
| 30 | <WorkspacePageHeader electron={isElectron} className="border-b border-border"> |
| 31 | <div className="flex items-center gap-2"> |
| 32 | <span className="text-sm font-medium text-foreground md:text-muted-foreground/60"> |
| 33 | {APP_DISPLAY_NAME} |
| 34 | </span> |
| 35 | </div> |
| 36 | </WorkspacePageHeader> |
| 37 | |
| 38 | <Empty className="flex-1"> |
| 39 | <EmptyHeader> |
| 40 | <EmptyTitle> |
| 41 | {localEnvironmentOff ? <T>This computer is off</T> : <T>No computer connected</T>} |
| 42 | </EmptyTitle> |
| 43 | <EmptyDescription> |
| 44 | {localEnvironmentOff ? ( |
| 45 | <T>Turn it back on, or connect a different computer.</T> |
| 46 | ) : cloudEnabled ? ( |
| 47 | <T>Your agents run on your computer.</T> |
| 48 | ) : ( |
| 49 | <T>Your agents run on your computer. Start T3 Code there first.</T> |
| 50 | )} |
| 51 | </EmptyDescription> |
| 52 | </EmptyHeader> |
| 53 | <EmptyContent> |
| 54 | {localEnvironmentOff ? ( |
| 55 | <Button render={<Link to="/settings/connections" />} size="sm"> |
| 56 | <T>Open Environments</T> |
| 57 | </Button> |
| 58 | ) : ( |
| 59 | <ol className="w-full space-y-4 text-left"> |
| 60 | {cloudEnabled ? <T3ConnectSteps /> : <PairingSteps />} |
| 61 | </ol> |
| 62 | )} |
| 63 | </EmptyContent> |
| 64 | </Empty> |
| 65 | </div> |
| 66 | </SidebarInset> |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | function T3ConnectSteps() { |
| 71 | const { isLoaded, isSignedIn } = useAuth({ treatPendingAsSignedOut: false }); |
| 72 | const loadFailed = useClerkLoadFailed(); |
| 73 | const { openAuthPrompt } = useT3ConnectAuthPrompt(); |
| 74 | // Adding the first computer unmounts this screen. Wait for all health checks |
| 75 | // so every compatible registration is queued before that happens. |
| 76 | const [autoAddedComputers] = useState(() => new Set<EnvironmentId>()); |
| 77 | const [selectedIds, setSelectedIds] = useState<ReadonlySet<EnvironmentId>>(() => new Set()); |
| 78 | const discovered = [...useRelayEnvironmentDiscovery().environments.values()]; |
| 79 | const discoverySettled = |
| 80 | discovered.length > 0 && discovered.every(({ availability }) => availability !== "checking"); |
| 81 | return ( |
| 82 | <> |
| 83 | <SetupStep number={1}> |
| 84 | {loadFailed ? ( |
| 85 | <Button size="sm" onClick={retryClerkLoad}> |
| 86 | <T>Retry sign-in</T> |
| 87 | </Button> |
| 88 | ) : isSignedIn ? ( |
| 89 | <p className="flex items-center gap-1.5 text-muted-foreground"> |
| 90 | <CheckIcon className="size-4" /> |
| 91 | <T>Signed in</T> |
| 92 | </p> |
| 93 | ) : ( |
| 94 | <Button size="sm" disabled={!isLoaded} onClick={openAuthPrompt}> |
| 95 | <T>Sign in</T> |
| 96 | </Button> |
| 97 | )} |
| 98 | </SetupStep> |
| 99 | <SetupStep number={2}> |
| 100 | <RunOnComputer command="t3 connect" /> |
| 101 | {isSignedIn ? ( |
| 102 | <div className="mt-4 space-y-1.5"> |
| 103 | <CloudEnvironmentConnectRows |
| 104 | primaryEnvironmentId={null} |
| 105 | savedEnvironments={[]} |
| 106 | refreshWhileEmpty |
| 107 | selection={{ |
| 108 | ...(discoverySettled ? { autoSelectedComputers: autoAddedComputers } : {}), |
| 109 | selectedIds, |
| 110 | onChange: (environmentId, selected) => |
| 111 | setSelectedIds((current) => { |
| 112 | const next = new Set(current); |
| 113 | if (selected) next.add(environmentId); |
| 114 | else next.delete(environmentId); |
| 115 | return next; |
| 116 | }), |
| 117 | }} |
| 118 | empty={ |
| 119 | <p className="text-xs text-muted-foreground"> |
| 120 | <T>Waiting for your computer…</T> |
| 121 | </p> |
| 122 | } |
| 123 | /> |
| 124 | </div> |
| 125 | ) : null} |
| 126 | </SetupStep> |
| 127 | </> |
| 128 | ); |
| 129 | } |
| 130 | |
| 131 | function PairingSteps() { |
| 132 | return ( |
| 133 | <> |
| 134 | <SetupStep number={1}> |
| 135 | <RunOnComputer command="t3 pair" /> |
| 136 | </SetupStep> |
| 137 | <SetupStep number={2}> |
| 138 | <Button render={<Link to="/settings/connections" />} size="sm"> |
| 139 | <T>Add pairing link</T> |
| 140 | </Button> |
| 141 | </SetupStep> |
| 142 | </> |
| 143 | ); |
| 144 | } |
| 145 | |
| 146 | function SetupStep({ |
| 147 | number, |
| 148 | children, |
| 149 | }: { |
| 150 | readonly number: number; |
| 151 | readonly children: ReactNode; |
| 152 | }) { |
| 153 | return ( |
| 154 | <li className="flex gap-3"> |
| 155 | <span className="w-2 shrink-0 pt-1 text-muted-foreground">{number}</span> |
| 156 | <div className="min-w-0 flex-1">{children}</div> |
| 157 | </li> |
| 158 | ); |
| 159 | } |
| 160 | |
| 161 | function RunOnComputer({ command }: { readonly command: string }) { |
| 162 | return ( |
| 163 | <> |
| 164 | <p> |
| 165 | <T>Run on your computer:</T> |
| 166 | </p> |
| 167 | <InstallT3Commands command={command} className="mt-2" /> |
| 168 | <a |
| 169 | className="mt-2 inline-block text-xs text-muted-foreground underline underline-offset-2 hover:text-foreground" |
| 170 | href={DESKTOP_DOWNLOAD_URL} |
| 171 | target="_blank" |
| 172 | rel="noreferrer noopener" |
| 173 | > |
| 174 | <T>Or download the desktop app</T> |
| 175 | </a> |
| 176 | </> |
| 177 | ); |
| 178 | } |