AI Chat 1
shadcnstore/ai-chat-1FreeBlock
A chat thread with streaming, code blocks, regenerate and feedback
Install it
npx shadcn@latest add https://shadcnstore.com/r/ai-chat-1.jsonSource
1'use client'23import { useEffect, useRef, useState } from 'react'4import { useReducedMotion } from 'motion/react'5import { ArrowUp, RotateCw, Sparkles, Square, ThumbsDown, ThumbsUp } from 'lucide-react'6import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'7import { Button } from '@/components/ui/button'8import { ScrollArea } from '@/components/ui/scroll-area'9import { Spinner } from '@/components/ui/spinner'10import { Textarea } from '@/components/ui/textarea'11import { chatMessages, streamedReply, suggestions, type ChatMessage } from "@/components/data/ai-chat-1-data"12import { AiChat1MessageBody } from './ai-chat-1-message-body'1314const userAvatar =15 'https://assets.shadcnstore.com/shadcnstore.com/stock/marketing/sarah-johnson.400w.01a6ba.avif'1617/**18 * No AI SDK and no markdown dependency: the thread is plain React over typed blocks, so it19 * drops onto any backend. Replace `AiChat1MessageBody` with your own renderer and `startStream`20 * with your streaming call; every state around them stays as it is.21 */2223export function AiChat1() {24 const [messages, setMessages] = useState<ChatMessage[]>(chatMessages)25 const [streaming, setStreaming] = useState(false)26 const [streamed, setStreamed] = useState('')27 const [feedback, setFeedback] = useState<Record<string, 'up' | 'down'>>({})28 const [draft, setDraft] = useState('')29 const cancelled = useRef(false)30 const reduceMotion = useReducedMotion()3132 const fullReply = streamedReply[0].kind === 'text' ? streamedReply[0].text : ''3334 const startStream = () => {35 cancelled.current = false36 setStreamed('')37 setStreaming(true)38 }3940 useEffect(() => {41 if (!streaming) {42 return43 }4445 const words = fullReply.split(' ')46 let index = 04748 // Reduced motion gets the whole answer at once rather than a typewriter.49 if (reduceMotion) {50 setStreamed(fullReply)51 setStreaming(false)52 setMessages(current => [53 ...current,54 { id: `m-${Date.now()}`, role: 'assistant', blocks: streamedReply },55 ])56 return57 }5859 const timer = window.setInterval(() => {60 if (cancelled.current) {61 window.clearInterval(timer)62 return63 }6465 index += 166 setStreamed(words.slice(0, index).join(' '))6768 if (index >= words.length) {69 window.clearInterval(timer)70 setStreaming(false)71 setMessages(current => [72 ...current,73// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from ShadcnStore
All 228 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| About 1about-1 | ShadcnStore | Blocks | Free | 1 dep · 3 files | |
| About 2about-2 | ShadcnStore | Blocks | Paid | 2 deps · 3 files | |
| AI Chat 2ai-chat-2 | ShadcnStore | Blocks | Paid | 1 dep · 4 files | |
| AI Prompt 1ai-prompt-1 | ShadcnStore | Blocks | Paid | 1 dep · 3 files | |
| App Dashboard 1app-1 | ShadcnStore | Blocks | Free | 1 dep · 4 files | |
| Task Management 2app-2 | ShadcnStore | Blocks | Paid | 2 deps · 4 files | |
| Foundational Application Shellapp-shell-1 | ShadcnStore | Blocks | Free | 1 dep · 4 files | |
| Responsive Icon Rail Shellapp-shell-2 | ShadcnStore | Blocks | Paid | 1 dep · 4 files |
