An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
fix: Adjust search results display modes
Yoshiki Miura8e32548e3f15
diff --git a/components/artifact/search-artifact-content.tsx b/components/artifact/search-artifact-content.tsxindex 8f939cf4..ad26434f 100644--- a/components/artifact/search-artifact-content.tsx+++ b/components/artifact/search-artifact-content.tsx@@ -26,7 +26,7 @@ export function SearchArtifactContent({ tool }: { tool: ToolInvocation }) {)}<Section title="Sources">- <SearchResults results={searchResults.results} />+ <SearchResults results={searchResults.results} displayMode="list" /></Section></div>)diff --git a/components/search-results.tsx b/components/search-results.tsxindex 9725c3db..1cc08c7e 100644--- a/components/search-results.tsx+++ b/components/search-results.tsx@@ -9,9 +9,13 @@ import { useState } from 'react'export interface SearchResultsProps {results: SearchResultItem[]+ displayMode?: 'grid' | 'list'}-export function SearchResults({ results }: SearchResultsProps) {+export function SearchResults({+ results,+ displayMode = 'grid'+}: SearchResultsProps) {// State to manage whether to display the resultsconst [showAllResults, setShowAllResults] = useState(false)@@ -19,7 +23,8 @@ export function SearchResults({ results }: SearchResultsProps) {setShowAllResults(true)}- const displayedResults = showAllResults ? results : results.slice(0, 3)+ // Logic for grid mode+ const displayedGridResults = showAllResults ? results : results.slice(0, 3)const additionalResultsCount = results.length > 3 ? results.length - 3 : 0const displayUrlName = (url: string) => {const hostname = new URL(url).hostname@@ -27,12 +32,60 @@ export function SearchResults({ results }: SearchResultsProps) {return parts.length > 2 ? parts.slice(1, -1).join('.') : parts[0]}+ // --- List Mode Rendering ---+ if (displayMode === 'list') {+ return (+ <div className="flex flex-col gap-2">+ {results.map((result, index) => (+ <Link+ href={result.url}+ key={index}+ passHref+ target="_blank"+ className="block"+ >+ <Card className="w-full hover:bg-muted/50 transition-colors">+ <CardContent className="p-2 flex items-start space-x-2">+ <Avatar className="h-4 w-4 mt-1 flex-shrink-0">+ <AvatarImage+ src={`https://www.google.com/s2/favicons?domain=${+ new URL(result.url).hostname+ }`}+ alt={new URL(result.url).hostname}+ />+ <AvatarFallback className="text-xs">+ {new URL(result.url).hostname[0]}+ </AvatarFallback>+ </Avatar>+ <div className="flex-grow overflow-hidden space-y-0.5">+ <p className="text-sm font-medium line-clamp-1">+ {result.title || new URL(result.url).pathname}+ </p>+ <p className="text-xs text-muted-foreground line-clamp-2">+ {result.content}+ </p>+ <div className="text-xs text-muted-foreground/80 mt-1 truncate">+ <span className="underline">+ {new URL(result.url).hostname}+ </span>{' '}+ - {index + 1}+ </div>+ </div>+ </CardContent>+ </Card>+ </Link>+ ))}+ </div>+ )+ }++ // --- Grid Mode Rendering (Existing Logic) ---return (- <div className="flex flex-wrap">- {displayedResults.map((result, index) => (+ <div className="flex flex-wrap -m-1">+ {displayedGridResults.map((result, index) => (<div className="w-1/2 md:w-1/4 p-1" key={index}><Link href={result.url} passHref target="_blank">- <Card className="flex-1 h-full">+ <Card className="flex-1 h-full hover:bg-muted/50 transition-colors"><CardContent className="p-2 flex flex-col justify-between h-full"><p className="text-xs line-clamp-2 min-h-[2rem]">{result.title || result.content}diff --git a/components/section.tsx b/components/section.tsxindex dd4e34d3..ed1cc5aa 100644--- a/components/section.tsx+++ b/components/section.tsx@@ -77,7 +77,7 @@ export const Section: React.FC<SectionProps> = ({</h2>)}{title && type === 'badge' && (- <Badge variant="secondary">+ <Badge variant="secondary" className="mb-2">{icon}{title}</Badge>