An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
Fix undefined query display and add loading animation for search
Yoshiki Miura735a100d0dd2
diff --git a/components/search-section.tsx b/components/search-section.tsxindex 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_domainsconst includeDomainsString = includeDomains? ` [${includeDomains.join(', ')}]`@@ -59,6 +59,7 @@ export function SearchSection({<ToolArgsSectiontool="search"number={searchResults ? totalResults : undefined}+ isLoading={isLoading && isToolLoading}>{`${query}${includeDomainsString}`}</ToolArgsSection></button>)diff --git a/components/section.tsx b/components/section.tsxindex 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.ReactNodetool: stringnumber?: 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.tsxindex 0d887f38..e0c2df59 100644--- a/components/tool-badge.tsx+++ b/components/tool-badge.tsx@@ -10,12 +10,14 @@ type ToolBadgeProps = {tool: stringchildren: React.ReactNodeclassName?: 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>