Skip to content

An AI-powered search engine with a generative UI

Add opacity transition to message actions during streaming

Yoshiki Miura749479cdda4e
diff --git a/components/chat.tsx b/components/chat.tsx
index 58f98f19..5baffc4f 100644
--- a/components/chat.tsx
+++ b/components/chat.tsx
@@ -61,7 +61,7 @@ export function Chat({
dependency: messages.length,
isStreaming: () => status === 'streaming',
scrollContainer: scrollContainerRef,
- threshold: 10
+ threshold: 50
})
useEffect(() => {
diff --git a/components/message-actions.tsx b/components/message-actions.tsx
index afce5b46..094d309e 100644
--- a/components/message-actions.tsx
+++ b/components/message-actions.tsx
@@ -1,6 +1,8 @@
'use client'
+import { CHAT_ID } from '@/lib/constants'
import { cn } from '@/lib/utils'
+import { useChat } from '@ai-sdk/react'
import { Copy } from 'lucide-react'
import { toast } from 'sonner'
import { ChatShare } from './chat-share'
@@ -24,13 +26,24 @@ export function MessageActions({
enableShare,
className
}: MessageActionsProps) {
+ const { status } = useChat({
+ id: CHAT_ID
+ })
+ const isLoading = status === 'submitted' || status === 'streaming'
+
async function handleCopy() {
await navigator.clipboard.writeText(message)
toast.success('Message copied to clipboard')
}
return (
- <div className={cn('flex items-center gap-0.5 self-end', className)}>
+ <div
+ className={cn(
+ 'flex items-center gap-0.5 self-end transition-opacity duration-200',
+ isLoading ? 'opacity-0' : 'opacity-100',
+ className
+ )}
+ >
{reload && <RetryButton reload={reload} messageId={messageId} />}
<Button
variant="ghost"