|
| 1 | +"use client"; |
| 2 | +import { CustomConnectWallet } from "@3rdweb-sdk/react/components/connect-wallet"; |
| 3 | +import { useState } from "react"; |
| 4 | +import { ClientOnly } from "../../components/ClientOnly/ClientOnly"; |
| 5 | +import ExecuteTab from "./components/ExecuteTab"; |
| 6 | +import { ConfigureAPIKeyButton } from "./components/configure-api-key.client"; |
| 7 | +import { useExecuteConfig } from "./hooks/useExecuteConfig"; |
| 8 | + |
| 9 | +export function ChatPage() { |
| 10 | + const [executeMessages, setExecuteMessages] = useState< |
| 11 | + Array<{ text: string; sender: "user" | "chat" | "error" }> |
| 12 | + >([]); |
| 13 | + |
| 14 | + const [executeInputValue, setExecuteInputValue] = useState(""); |
| 15 | + const [executeIsLoading, setExecuteIsLoading] = useState(false); |
| 16 | + const [executeSessionId, setExecuteSessionId] = useState<string | null>(null); |
| 17 | + const [isConfigModalOpen, setIsConfigModalOpen] = useState(false); |
| 18 | + const [executeConfig, setExecuteConfig] = useExecuteConfig(); |
| 19 | + |
| 20 | + const [apiKey, setApiKey] = useState<string | null>(() => { |
| 21 | + try { |
| 22 | + return localStorage.getItem("thirdwebApiKey"); |
| 23 | + } catch { |
| 24 | + return null; |
| 25 | + } |
| 26 | + }); |
| 27 | + |
| 28 | + return ( |
| 29 | + <div className="flex h-screen overflow-hidden bg-background"> |
| 30 | + {/* Left */} |
| 31 | + <aside className="hidden w-[260px] border-r bg-muted/50 md:block"> |
| 32 | + <div className="p-4"> |
| 33 | + <div className="flex flex-col gap-3"> |
| 34 | + <CustomConnectWallet /> |
| 35 | + <ClientOnly ssr={null}> |
| 36 | + <ConfigureAPIKeyButton |
| 37 | + apiKey={apiKey || ""} |
| 38 | + setApiKey={setApiKey} |
| 39 | + /> |
| 40 | + </ClientOnly> |
| 41 | + </div> |
| 42 | + </div> |
| 43 | + </aside> |
| 44 | + |
| 45 | + {/* Right */} |
| 46 | + <ClientOnly ssr={null} className="flex grow flex-col p-6"> |
| 47 | + {!apiKey ? ( |
| 48 | + <div className="flex grow items-center justify-center"> |
| 49 | + <p className="text-gray-400"> |
| 50 | + Please enter your thirdweb API key to continue |
| 51 | + </p> |
| 52 | + </div> |
| 53 | + ) : ( |
| 54 | + <ExecuteTab |
| 55 | + messages={executeMessages} |
| 56 | + setMessages={setExecuteMessages} |
| 57 | + inputValue={executeInputValue} |
| 58 | + setInputValue={setExecuteInputValue} |
| 59 | + isLoading={executeIsLoading} |
| 60 | + setIsLoading={setExecuteIsLoading} |
| 61 | + sessionId={executeSessionId} |
| 62 | + setSessionId={setExecuteSessionId} |
| 63 | + config={executeConfig} |
| 64 | + setConfig={setExecuteConfig} |
| 65 | + isConfigModalOpen={isConfigModalOpen} |
| 66 | + setIsConfigModalOpen={setIsConfigModalOpen} |
| 67 | + /> |
| 68 | + )} |
| 69 | + </ClientOnly> |
| 70 | + </div> |
| 71 | + ); |
| 72 | +} |
0 commit comments