Skip to content

An AI-powered search engine with a generative UI

Keep assistant logo visible after generation

Yoshiki Miura07b94249f2d8
diff --git a/components/chat-messages.tsx b/components/chat-messages.tsx
index 44caa4c2..9ced9fac 100644
--- a/components/chat-messages.tsx
+++ b/components/chat-messages.tsx
@@ -89,8 +89,11 @@ export function ChatMessages({
if (!sections.length) return null
- // Check if loading indicator should be shown
- const showLoading = status === 'submitted' || status === 'streaming'
+ // Keep the assistant logo visible for the latest section after generation
+ const latestSection = sections.at(-1)
+ const showAssistantLogo = Boolean(
+ latestSection && (isLoading || latestSection.assistantMessages.length > 0)
+ )
// Helper function to get tool count with caching
const getToolCount = (message?: UIMessage): number => {
@@ -231,10 +234,10 @@ export function ChatMessages({
</div>
)
})}
- {/* Show loading after assistant messages */}
- {showLoading && sectionIndex === sections.length - 1 && (
+ {/* Show assistant logo after assistant messages */}
+ {showAssistantLogo && sectionIndex === sections.length - 1 && (
<div className="flex justify-start py-4">
- <AnimatedLogo className="h-10 w-10" />
+ <AnimatedLogo className="h-10 w-10" animate={isLoading} />
</div>
)}
{sectionIndex === sections.length - 1 && (
diff --git a/components/ui/animated-logo.tsx b/components/ui/animated-logo.tsx
index 4adab615..7219202b 100644
--- a/components/ui/animated-logo.tsx
+++ b/components/ui/animated-logo.tsx
@@ -1,11 +1,50 @@
'use client'
+import { useEffect, useState } from 'react'
+
import { cn } from '@/lib/utils'
export function AnimatedLogo({
+ animate = true,
className,
...props
-}: React.ComponentProps<'svg'>) {
+}: React.ComponentProps<'svg'> & {
+ animate?: boolean
+}) {
+ const [isBlinking, setIsBlinking] = useState(false)
+
+ useEffect(() => {
+ if (animate) {
+ setIsBlinking(false)
+ return
+ }
+
+ let blinkTimeoutId: ReturnType<typeof setTimeout> | undefined
+ let nextBlinkTimeoutId: ReturnType<typeof setTimeout>
+
+ const scheduleBlink = () => {
+ const nextDelay = Math.random() * 5000 + 2000
+
+ nextBlinkTimeoutId = setTimeout(() => {
+ setIsBlinking(true)
+
+ blinkTimeoutId = setTimeout(() => {
+ setIsBlinking(false)
+ scheduleBlink()
+ }, 200)
+ }, nextDelay)
+ }
+
+ scheduleBlink()
+
+ return () => {
+ if (blinkTimeoutId) {
+ clearTimeout(blinkTimeoutId)
+ }
+ clearTimeout(nextBlinkTimeoutId)
+ }
+ }, [animate])
+
return (
<svg
fill="currentColor"
@@ -16,9 +55,28 @@ export function AnimatedLogo({
{...props}
>
<circle cx="128" cy="128" r="128" fill="black"></circle>
- <g className="animate-[lookAround_2s_ease-in-out_infinite] origin-center">
- <circle cx="102" cy="128" r="18" fill="white"></circle>
- <circle cx="154" cy="128" r="18" fill="white"></circle>
+ <g
+ className={cn(
+ 'origin-center',
+ animate && 'animate-[lookAround_2s_ease-in-out_infinite]'
+ )}
+ >
+ <ellipse
+ cx="102"
+ cy="128"
+ rx="18"
+ ry="18"
+ fill="white"
+ className={cn(!animate && isBlinking && 'animate-blink')}
+ ></ellipse>
+ <ellipse
+ cx="154"
+ cy="128"
+ rx="18"
+ ry="18"
+ fill="white"
+ className={cn(!animate && isBlinking && 'animate-blink')}
+ ></ellipse>
</g>
</svg>
)