Skip to content

An AI-powered search engine with a generative UI

Fix undefined query display and add loading animation for search

Yoshiki Miura735a100d0dd2
diff --git a/components/search-section.tsx b/components/search-section.tsx
index 77740cf3..31019264 100644
--- a/components/search-section.tsx
+++ b/components/search-section.tsx
@@ -36,7 +36,7 @@ export function SearchSection({
tool.state === 'input-streaming' || tool.state === 'input-available'
const searchResults: TypeSearchResults | undefined =
tool.state === 'output-available' ? tool.output : undefined
- const query = tool.input?.query
+ const query = tool.input?.query || ''
const includeDomains = tool.input?.include_domains
const includeDomainsString = includeDomains
? ` [${includeDomains.join(', ')}]`
@@ -59,6 +59,7 @@ export function SearchSection({
<ToolArgsSection
tool="search"
number={searchResults ? totalResults : undefined}
+ isLoading={isLoading && isToolLoading}
>{`${query}${includeDomainsString}`}</ToolArgsSection>
</button>
)
diff --git a/components/section.tsx b/components/section.tsx
index 4ca6d183..7810e18d 100644
--- a/components/section.tsx
+++ b/components/section.tsx
@@ -100,11 +100,13 @@ export const Section: React.FC<SectionProps> = ({
export function ToolArgsSection({
children,
tool,
- number
+ number,
+ isLoading
}: {
children: React.ReactNode
tool: string
number?: number
+ isLoading?: boolean
}) {
return (
<Section
@@ -112,7 +114,7 @@ export function ToolArgsSection({
className="py-0 flex items-center justify-between w-full gap-2"
>
<div className="min-w-0 flex-1">
- <ToolBadge tool={tool}>{children}</ToolBadge>
+ <ToolBadge tool={tool} isLoading={isLoading}>{children}</ToolBadge>
</div>
{number && number > 0 && (
<div className="flex-shrink-0">
diff --git a/components/tool-badge.tsx b/components/tool-badge.tsx
index 0d887f38..e0c2df59 100644
--- a/components/tool-badge.tsx
+++ b/components/tool-badge.tsx
@@ -10,12 +10,14 @@ type ToolBadgeProps = {
tool: string
children: React.ReactNode
className?: string
+ isLoading?: boolean
}
export const ToolBadge: React.FC<ToolBadgeProps> = ({
tool,
children,
- className
+ className,
+ isLoading = false
}) => {
const icon: Record<string, React.ReactNode> = {
search: <Search size={14} />,
@@ -24,7 +26,11 @@ export const ToolBadge: React.FC<ToolBadgeProps> = ({
return (
<Badge
- className={cn('inline-flex items-center max-w-full', className)}
+ className={cn(
+ 'inline-flex items-center max-w-full',
+ isLoading && 'animate-pulse',
+ className
+ )}
variant={'secondary'}
>
<span className="flex-shrink-0">{icon[tool]}</span>