File size: 4,276 Bytes
10c8635 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
import { useEffect, useRef } from 'react';
import { Card } from '@/components/ui/card';
import { Alert, AlertDescription } from '@/components/ui/alert';
import { AlertCircle } from 'lucide-react';
import { Skeleton } from '@/components/ui/skeleton';
import { cn } from '@/lib/utils';
import { motion } from 'framer-motion';
import { SourceList } from '@/components/SourceList';
import { Logo } from '@/components/Logo';
interface SearchResultsProps {
query: string;
results: any;
isLoading: boolean;
error?: Error;
isFollowUp?: boolean;
originalQuery?: string;
}
export function SearchResults({
query,
results,
isLoading,
error,
isFollowUp,
originalQuery
}: SearchResultsProps) {
const contentRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (results && contentRef.current) {
contentRef.current.scrollIntoView({ behavior: 'smooth' });
}
}, [results]);
if (error) {
return (
<Alert variant="destructive" className="animate-in fade-in-50">
<AlertCircle className="h-4 w-4" />
<AlertDescription>
{error.message || 'An error occurred while searching. Please try again.'}
</AlertDescription>
</Alert>
);
}
if (isLoading) {
return (
<div className="space-y-4 animate-in fade-in-50">
<div className="flex justify-center mb-8">
<Logo animate className="w-12 h-12" />
</div>
<Card className="p-6">
<Skeleton className="h-4 w-3/4 mb-4" />
<Skeleton className="h-4 w-full mb-2" />
<Skeleton className="h-4 w-full mb-2" />
<Skeleton className="h-4 w-2/3" />
</Card>
<div className="space-y-2">
<Skeleton className="h-[100px] w-full" />
<Skeleton className="h-[100px] w-full" />
</div>
</div>
);
}
if (!results) return null;
return (
<div ref={contentRef} className="space-y-6 animate-in fade-in-50">
{/* Search Query Display */}
<motion.div
initial={{ opacity: 0, y: -20 }}
animate={{ opacity: 1, y: 0 }}
className="flex flex-col gap-2"
>
{isFollowUp && originalQuery && (
<>
<div className="flex flex-col sm:flex-row sm:items-baseline gap-2 text-xs sm:text-sm text-muted-foreground/70">
<span>Original search:</span>
<span className="font-medium">"{originalQuery}"</span>
</div>
<div className="h-px bg-border w-full" />
</>
)}
<div className="flex flex-col sm:flex-row sm:items-baseline gap-2 text-sm sm:text-base text-muted-foreground">
<span>{isFollowUp ? 'Follow-up question:' : ''}</span>
<h1 className="font-serif text-lg sm:text-3xl text-foreground">"{query}"</h1>
</div>
</motion.div>
{/* Sources Section */}
{results.sources && results.sources.length > 0 && (
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.2 }}
>
<SourceList sources={results.sources} />
</motion.div>
)}
{/* Main Content */}
<Card className="overflow-hidden shadow-md">
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.3, duration: 0.4 }}
className="py-4 px-8"
>
<div
className={cn(
"prose prose-slate max-w-none",
"dark:prose-invert",
"prose-headings:font-bold prose-headings:mb-4",
"prose-h2:text-2xl prose-h2:mt-8 prose-h2:border-b prose-h2:pb-2 prose-h2:border-border",
"prose-h3:text-xl prose-h3:mt-6",
"prose-p:text-base prose-p:leading-7 prose-p:my-4",
"prose-ul:my-6 prose-ul:list-disc prose-ul:pl-6",
"prose-li:my-2 prose-li:marker:text-muted-foreground",
"prose-strong:font-semibold",
"prose-a:text-primary prose-a:no-underline hover:prose-a:text-primary/80",
)}
dangerouslySetInnerHTML={{
__html: results.summary
}}
/>
</motion.div>
</Card>
</div>
);
} |