MCPcopy
hub / github.com/TanStack/ai / ChatPage

Function ChatPage

examples/ts-solid-chat/src/routes/index.tsx:308–401  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

306}
307
308function ChatPage() {
309 const [chunks, setChunks] = createSignal<Array<any>>([])
310
311 const { messages, sendMessage, isLoading, addToolApprovalResponse, stop } =
312 useChat({
313 connection: chatOptions.connection,
314 tools: clientTools,
315 onChunk: (chunk: any) => {
316 setChunks((prev) => [...prev, chunk])
317 },
318 })
319 const [input, setInput] = createSignal('')
320
321 const clearChunks = () => setChunks([])
322
323 return (
324 <div class="flex h-[calc(100vh-72px)] bg-gray-900">
325 {/* Left side - Chat (1/4 width) */}
326 <div class="w-1/2 flex flex-col border-r border-orange-500/20">
327 <div class="p-4 border-b border-orange-500/20">
328 <h1 class="text-2xl font-bold bg-linear-to-r from-orange-500 to-red-600 text-transparent bg-clip-text">
329 TanStack AI on SolidJS
330 </h1>
331 </div>
332
333 <Messages
334 messages={messages()}
335 addToolApprovalResponse={addToolApprovalResponse}
336 />
337
338 <ChatInputArea>
339 <div class="space-y-3">
340 {isLoading() && (
341 <div class="flex items-center justify-center">
342 <button
343 onClick={stop}
344 class="px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-lg text-sm font-medium transition-colors flex items-center gap-2"
345 >
346 <Square class="w-4 h-4 fill-current" />
347 Stop
348 </button>
349 </div>
350 )}
351 <div class="relative">
352 <textarea
353 value={input()}
354 placeholder="Type something"
355 class="w-full rounded-lg border border-orange-500/20 bg-gray-800/50 pl-4 pr-12 py-3 text-sm text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-orange-500/50 focus:border-transparent resize-none overflow-hidden shadow-lg"
356 rows={1}
357 style={{ 'min-height': '44px', 'max-height': '200px' }}
358 disabled={isLoading()}
359 onInput={(e) => {
360 const target = e.target as HTMLTextAreaElement
361 target.style.height = 'auto'
362 target.style.height =
363 Math.min(target.scrollHeight, 200) + 'px'
364 setInput(target.value)
365 }}

Callers

nothing calls this directly

Calls 5

useChatFunction · 0.90
messagesFunction · 0.85
isLoadingFunction · 0.50
sendMessageFunction · 0.50
chunksFunction · 0.50

Tested by

no test coverage detected