The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { T } from "gt-react"; |
| 2 | import type { EnvironmentId, ScopedThreadRef } from "@t3tools/contracts"; |
| 3 | import { parseUrl } from "@t3tools/shared/url"; |
| 4 | import { Globe, History, RadioTower } from "lucide-react"; |
| 5 | |
| 6 | import type { BrowserHistoryEntry } from "~/browserHistoryStore"; |
| 7 | import { Empty, EmptyDescription, EmptyMedia, EmptyTitle } from "~/components/ui/empty"; |
| 8 | import { DiscoveryList } from "../ui/discovery-list"; |
| 9 | |
| 10 | import { PreviewLocalServerCard } from "./PreviewLocalServerCard"; |
| 11 | import { PreviewRecentUrlCard } from "./PreviewRecentUrlCard"; |
| 12 | import { useDiscoveredLocalServers } from "./useDiscoveredLocalServers"; |
| 13 | |
| 14 | interface Props { |
| 15 | threadRef: ScopedThreadRef; |
| 16 | environmentId: EnvironmentId; |
| 17 | configuredUrls?: ReadonlyArray<string> | undefined; |
| 18 | recentEntries: ReadonlyArray<BrowserHistoryEntry>; |
| 19 | onRemoveRecent: (url: string) => void; |
| 20 | onOpenUrl: (url: string) => void; |
| 21 | } |
| 22 | |
| 23 | export function PreviewEmptyState({ |
| 24 | threadRef, |
| 25 | environmentId, |
| 26 | configuredUrls, |
| 27 | recentEntries, |
| 28 | onRemoveRecent, |
| 29 | onOpenUrl, |
| 30 | }: Props) { |
| 31 | const servers = useDiscoveredLocalServers({ |
| 32 | environmentId, |
| 33 | configuredUrls, |
| 34 | }); |
| 35 | const recents = recentEntries.filter((entry) => parseUrl(entry.url) !== null).slice(0, 8); |
| 36 | |
| 37 | if (servers.length === 0 && recents.length === 0) { |
| 38 | return ( |
| 39 | <Empty> |
| 40 | <EmptyMedia variant="icon"> |
| 41 | <Globe className="size-4.5 text-muted-foreground" /> |
| 42 | </EmptyMedia> |
| 43 | <EmptyTitle> |
| 44 | <T>No preview yet</T> |
| 45 | </EmptyTitle> |
| 46 | <EmptyDescription> |
| 47 | <T> |
| 48 | Type a URL above, or run a dev script. Local servers this thread starts will show up |
| 49 | here automatically. |
| 50 | </T> |
| 51 | </EmptyDescription> |
| 52 | </Empty> |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | return ( |
| 57 | <div className="scrollbar-gutter-both flex h-full min-h-0 overflow-y-auto px-5 py-8"> |
| 58 | <div className="mx-auto flex w-full max-w-xl flex-col gap-6"> |
| 59 | {recents.length > 0 ? ( |
| 60 | <div className="flex flex-col gap-3"> |
| 61 | <div className="flex items-center gap-2 text-sm text-muted-foreground"> |
| 62 | <History className="size-4 shrink-0" /> |
| 63 | <h2 className="font-medium"> |
| 64 | <T>Recently used</T> |
| 65 | </h2> |
| 66 | </div> |
| 67 | <DiscoveryList> |
| 68 | {recents.map((entry) => ( |
| 69 | <PreviewRecentUrlCard |
| 70 | key={entry.url} |
| 71 | threadRef={threadRef} |
| 72 | entry={entry} |
| 73 | onOpen={() => onOpenUrl(entry.url)} |
| 74 | onRemove={() => onRemoveRecent(entry.url)} |
| 75 | /> |
| 76 | ))} |
| 77 | </DiscoveryList> |
| 78 | </div> |
| 79 | ) : null} |
| 80 | {servers.length > 0 ? ( |
| 81 | <div className="flex flex-col gap-3"> |
| 82 | <div className="flex items-center gap-2 text-sm text-muted-foreground"> |
| 83 | <RadioTower className="size-4 shrink-0" /> |
| 84 | <h2 className="font-medium"> |
| 85 | <T>Local servers</T> |
| 86 | </h2> |
| 87 | </div> |
| 88 | <DiscoveryList> |
| 89 | {servers.map((server) => ( |
| 90 | <PreviewLocalServerCard |
| 91 | key={`${server.host}:${server.port}`} |
| 92 | threadRef={threadRef} |
| 93 | server={server} |
| 94 | onOpen={() => onOpenUrl(server.requestedUrl)} |
| 95 | /> |
| 96 | ))} |
| 97 | </DiscoveryList> |
| 98 | <p className="px-1 text-xs text-muted-foreground"> |
| 99 | <T>Select a live local server to open it in this browser tab.</T> |
| 100 | </p> |
| 101 | </div> |
| 102 | ) : null} |
| 103 | </div> |
| 104 | </div> |
| 105 | ); |
| 106 | } |