The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useGT } from "gt-react"; |
| 2 | import { |
| 3 | AuthPreviewOperateScope, |
| 4 | type PreviewAnnotationPayload, |
| 5 | type ScopedThreadRef, |
| 6 | } from "@t3tools/contracts"; |
| 7 | |
| 8 | import type { ComposerImageAttachment } from "~/composerDraftStore"; |
| 9 | import { usePreviewAvailable } from "~/browser/previewRuntime"; |
| 10 | import { useEnvironmentScope } from "~/state/session"; |
| 11 | |
| 12 | import { PreviewPanelShell, type PreviewPanelMode } from "./PreviewPanelShell"; |
| 13 | import { PreviewView } from "./PreviewView"; |
| 14 | |
| 15 | interface Props { |
| 16 | mode: PreviewPanelMode; |
| 17 | threadRef: ScopedThreadRef; |
| 18 | tabId?: string | null; |
| 19 | configuredUrls?: ReadonlyArray<string> | undefined; |
| 20 | visible: boolean; |
| 21 | onSendAnnotation?: ( |
| 22 | annotation: PreviewAnnotationPayload, |
| 23 | image: ComposerImageAttachment | null, |
| 24 | ) => void; |
| 25 | } |
| 26 | |
| 27 | export function PreviewPanel({ |
| 28 | mode, |
| 29 | threadRef, |
| 30 | tabId, |
| 31 | configuredUrls, |
| 32 | visible, |
| 33 | onSendAnnotation, |
| 34 | }: Props) { |
| 35 | const available = usePreviewAvailable(threadRef.environmentId); |
| 36 | const gt = useGT(); |
| 37 | const canOperatePreview = useEnvironmentScope(threadRef.environmentId, AuthPreviewOperateScope); |
| 38 | if (!canOperatePreview || !available) { |
| 39 | return ( |
| 40 | <PreviewPanelShell mode={mode}> |
| 41 | <div className="flex min-h-0 flex-1 flex-col items-center justify-center gap-3 p-8 text-center"> |
| 42 | <p className="max-w-sm text-sm text-muted-foreground"> |
| 43 | {canOperatePreview |
| 44 | ? gt("Preview is only available in the T3 Code desktop app.") |
| 45 | : gt("Pair this client again with preview access to control browser previews.")} |
| 46 | </p> |
| 47 | </div> |
| 48 | </PreviewPanelShell> |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | return ( |
| 53 | <PreviewPanelShell mode={mode}> |
| 54 | <PreviewView |
| 55 | threadRef={threadRef} |
| 56 | {...(tabId !== undefined ? { tabId } : {})} |
| 57 | configuredUrls={configuredUrls} |
| 58 | visible={visible} |
| 59 | {...(onSendAnnotation ? { onSendAnnotation } : {})} |
| 60 | /> |
| 61 | </PreviewPanelShell> |
| 62 | ); |
| 63 | } |