2026-10-25 23:54:06 +08:00
import { useState } from "react" ;
import { createPortal } from "react-dom" ;
import { Sidebar } from "@/components/Sidebar" ;
import { PaneWorkbench } from "@/components/workbench/PaneWorkbench" ;
import { ThreadViewport } from "@/components/thread/ThreadViewport" ;
import { ThreadHistoryStatus } from "@/components/thread/ThreadHistoryStatus" ;
import { formatQuotedUserMessage } from "@/lib/user-message-quote" ;
import type { ChatSummary , UIMessage } from "@/lib/types" ;
2026-10-25 19:15:27 +08:00
import { ThreadComposer } from "@/components/thread/ThreadComposer" ;
import { ThreadHeader } from "@/components/thread/ThreadHeader" ;
import { ThemeProvider , useTheme } from "@/hooks/useTheme" ;
2026-11-07 18:08:08 +08:00
import { StarPromptView } from "@/components/StarPromptView" ;
import { Button } from "@/components/ui/button" ;
2026-10-25 19:15:27 +08:00
export function ThemeToggleFixture() {
const { theme , toggle } = useTheme ();
return (
< ThemeProvider theme = { theme }>
2026-11-07 18:08:08 +08:00
{ new URLSearchParams ( location . search ). has ( "star" ) ? < ThemeInvitationFixture toggle = { toggle } /> : new URLSearchParams ( location . search ). has ( "chat" ) ? < ThemeChatFixture theme = { theme } toggle = { toggle } /> : (
2026-10-25 23:54:06 +08:00
< main data - theme - surface className = "thread-workspace relative flex flex-col justify-center gap-8 bg-background px-6" style = {{ height : "100vh" }}>
< div className = "absolute inset-x-0 top-0" >
< ThreadHeader title = "Theme preview" hideTitle theme = { theme } onToggleTheme = { toggle } onToggleSidebar = {() => {}} />
</ div >
< div className = "workbench-body" >
< section data - theme - surface className = "workbench-pane flex flex-col gap-8 bg-background" >
2026-11-13 17:12:18 +08:00
< h1 data - theme - ink className = "text-center text-4xl text-foreground" > Theme preview </ h1 >
2026-10-25 23:54:06 +08:00
< ThreadComposer variant = "hero" onSend = {() => {}} />
</ section >
</ div >
</ main >
)}
2026-10-25 19:15:27 +08:00
</ ThemeProvider >
);
}
2026-10-25 23:54:06 +08:00
2026-11-07 18:08:08 +08:00
function ThemeInvitationFixture ({ toggle } : { toggle : () => void }) {
const [ open , setOpen ] = useState ( false );
return < main className = "flex h-full flex-col items-center justify-center gap-4 bg-background" >
< Button onClick = { toggle }> Toggle theme </ Button >
< Button onClick = {() => setOpen ( true )}> Open invitation </ Button >
< StarPromptView open = { open } saving = { false } error = { false } onOpenChange = { setOpen }
onDismissForever = {() => setOpen ( false )} onStar = {() => {}} />
</ main >;
}
2026-10-25 23:54:06 +08:00
const sessions : ChatSummary [] = [ "Theme chat" , "Another chat" ]. map (( title , index ) => ({
key : `websocket:theme- ${ index } ` , channel : "websocket" , chatId : `theme- ${ index } ` ,
title , preview : "" , createdAt : null , updatedAt : null ,
}));
const messages : UIMessage [] = [
{ id : "user" , role : "user" , content : formatQuotedUserMessage ( "Keep the surface layers in sync." , "Quoted context has its own translucent fill." ), createdAt : 1 },
{ id : "answer" , role : "assistant" , content : "An existing conversation with a portaled composer." , createdAt : 2 },
{ id : "session" , role : "user" , content : "An incoming session message." , createdAt : 3 ,
sessionMessage : { message_id : "incoming" , session : { id : "handle_0123456789abcdef0123456789abcdef" , name : "nori" } } },
];
const noop = () => {};
function ThemeChatFixture ({ theme , toggle } : { theme : "light" | "dark" ; toggle : () => void }) {
const [ activeKey , setActiveKey ] = useState ( sessions [ 0 ]. key );
const composer = < ThreadComposer onSend = { noop } />;
2026-11-06 16:41:12 +08:00
const header = < ThreadHeader title = "Theme chat" hideTitle theme = { theme } onToggleTheme = { toggle } onToggleSidebar = { noop } />;
const panes = [{ key : "theme" , title : "Theme chat" }];
if ( new URLSearchParams ( location . search ). has ( "split" )) panes . push ({ key : "theme-secondary" , title : "Secondary chat" });
2026-10-25 23:54:06 +08:00
return < main data - theme - surface className = "flex bg-background" style = {{ height : "100vh" }}>
< aside className = "hidden w-64 shrink-0 sm:block" >
2026-11-18 15:05:57 +08:00
< Sidebar sessions = { sessions } activeKey = { activeKey } onSelect = { setActiveKey } loading = { false }
2026-10-25 23:54:06 +08:00
onNewChat = { noop } onRequestDelete = { noop } onTogglePin = { noop } onRequestRename = { async () => {}}
onToggleArchive = { noop } onToggleGroup = { noop } onRequestRenameProject = { noop } onNewChatInProject = { noop }
2026-11-18 15:05:57 +08:00
onOpenSettings = { noop } onOpenApps = { noop } onOpenAutomations = { noop }
onOpenSearch = { noop } onToggleArchived = { noop } />
2026-10-25 23:54:06 +08:00
</ aside >
< div className = "min-w-0 flex-1" >
2026-11-06 16:41:12 +08:00
< PaneWorkbench panes = { panes } activePaneKey = "theme" layout = "columns"
2026-10-25 23:54:06 +08:00
showLayoutControl = { false } onActivatePane = { noop } onAddPane = { noop } onLayoutChange = { noop } onPaneOrderChange = { noop }
renderPane = {( _pane , context ) => < div className = "relative flex min-h-0 flex-1 flex-col" >
2026-11-06 16:41:12 +08:00
{ context . active && ( context . headerPortalTarget
? createPortal ( header , context . headerPortalTarget )
: context . headerPortalTarget === undefined ? header : null )}
2026-10-25 23:54:06 +08:00
< ThreadViewport messages = { messages } isStreaming = { false } conversationKey = { activeKey }
2026-11-06 16:41:12 +08:00
navigationFrame = { context . navigationFrame } composer = { context . composerPortalTarget === undefined ? composer : null } />
2026-10-25 23:54:06 +08:00
< ThreadHistoryStatus loading = { false } error = { null } exhausted onRetry = { noop } />
2026-11-06 16:41:12 +08:00
{ context . active && context . composerPortalTarget && createPortal (< div data - active - composer >{ composer }</ div >, context . composerPortalTarget )}
2026-10-25 23:54:06 +08:00
</ div >} />
</ div >
</ main >;
}