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