|
| 1 | +import { motion } from "framer-motion"; |
| 2 | +import { useState } from "react"; |
| 3 | + |
| 4 | +export interface SearchResultProps { |
| 5 | + context: string; |
| 6 | + source: string; |
| 7 | + icon: React.ReactNode; |
| 8 | + score: number; |
| 9 | +} |
| 10 | + |
| 11 | +export function SearchResult({ |
| 12 | + context, |
| 13 | + source, |
| 14 | + icon, |
| 15 | + score, |
| 16 | +}: SearchResultProps) { |
| 17 | + const [isExpanded, setIsExpanded] = useState(false); |
| 18 | + const maxLength = 300; |
| 19 | + |
| 20 | + const toggleReadMore = () => { |
| 21 | + setIsExpanded(!isExpanded); |
| 22 | + }; |
| 23 | + |
| 24 | + const truncatedContext = isExpanded ? context : context.slice(0, maxLength); |
| 25 | + |
| 26 | + return ( |
| 27 | + <motion.div |
| 28 | + initial={{ opacity: 0, y: 20 }} |
| 29 | + animate={{ opacity: 1, y: 0 }} |
| 30 | + transition={{ duration: 0.3 }} |
| 31 | + className="border border-gray-200 dark:border-gray-700 rounded-lg p-4 hover:shadow-md transition-shadow bg-white dark:bg-[#1e1e1e]" |
| 32 | + > |
| 33 | + <p className="text-gray-600 dark:text-gray-300 mb-3"> |
| 34 | + {truncatedContext} |
| 35 | + {context.length > maxLength && ( |
| 36 | + <> |
| 37 | + {!isExpanded && "..."} |
| 38 | + <button |
| 39 | + onClick={toggleReadMore} |
| 40 | + className="text-indigo-600 dark:text-indigo-400 ml-2 hover:underline focus:outline-none" |
| 41 | + > |
| 42 | + {isExpanded ? "Read less" : "Read more"} |
| 43 | + </button> |
| 44 | + </> |
| 45 | + )} |
| 46 | + </p> |
| 47 | + <div className="flex items-center text-sm text-gray-500 dark:text-gray-400"> |
| 48 | + {icon} |
| 49 | + <span className="ml-2">{source}</span> |
| 50 | + </div> |
| 51 | + <div className="mt-2 pt-2 border-t border-gray-200 dark:border-gray-700 flex items-center justify-end bg-gray-50 dark:bg-[#2a2a2a] rounded-b-lg -mx-4 -mb-4 px-4 py-2"> |
| 52 | + <span className="text-xs text-gray-600 dark:text-gray-300"> |
| 53 | + Similarity: {`${score}%`} |
| 54 | + </span> |
| 55 | + </div> |
| 56 | + </motion.div> |
| 57 | + ); |
| 58 | +} |
| 59 | +export function SkeletonSearchResult() { |
| 60 | + return ( |
| 61 | + <motion.div |
| 62 | + initial={{ opacity: 0, y: 20 }} |
| 63 | + animate={{ opacity: 1, y: 0 }} |
| 64 | + transition={{ duration: 0.3 }} |
| 65 | + className="border border-gray-200 dark:border-gray-700 rounded-lg p-4 hover:shadow-md transition-shadow bg-white dark:bg-[#1e1e1e]" |
| 66 | + > |
| 67 | + <div className="h-4 w-full bg-gray-200 dark:bg-gray-700 rounded mb-2"></div> |
| 68 | + <div className="h-4 w-full bg-gray-200 dark:bg-gray-700 rounded mb-2"></div> |
| 69 | + <div className="h-4 w-1/2 bg-gray-200 dark:bg-gray-700 rounded mb-3"></div> |
| 70 | + <div className="flex items-center"> |
| 71 | + <div className="h-5 w-5 bg-gray-200 dark:bg-gray-700 rounded-full mr-2"></div> |
| 72 | + <div className="h-4 w-1/4 bg-gray-200 dark:bg-gray-700 rounded"></div> |
| 73 | + </div> |
| 74 | + </motion.div> |
| 75 | + ); |
| 76 | +} |
| 77 | + |
| 78 | +export const NoResult = () => ( |
| 79 | + <div className="text-center py-8"> |
| 80 | + <p className="text-gray-600 dark:text-gray-400 text-lg">No results found</p> |
| 81 | + <p className="text-gray-500 dark:text-gray-500 text-sm mt-2"> |
| 82 | + Try adjusting your search query |
| 83 | + </p> |
| 84 | + </div> |
| 85 | +); |
0 commit comments