| 1 | import { FileCode2 } from "lucide-react"; |
| 2 | |
| 3 | import { |
| 4 | Empty, |
| 5 | EmptyDescription, |
| 6 | EmptyHeader, |
| 7 | EmptyMedia, |
| 8 | EmptyTitle, |
| 9 | } from "@/components/ui/empty"; |
| 10 | |
| 11 | import { |
| 12 | CodeSearchFile, |
| 13 | type CodeSearchMatch, |
| 14 | type CodeSearchRepository, |
| 15 | } from "./code-search-file"; |
| 16 | import { CodeSearchMore } |
| 17 | |
| 18 | export function CodeSearchResults({ |
| 19 | query, |
| 20 | files, |
| 21 | nextCursor, |
| 22 | repository, |
| 23 | error, |
| 24 | }: { |
| 25 | query: string |
| 26 | files: CodeSearchMatch |
| 27 | nextCursor: string |
| 28 | /** Required when the files carry no repository of their own: a search scoped to one repository. */ |
| 29 | repository?: CodeSearchRepository |
| 30 | error?: string |
| 31 | }) { |
| 32 | // A first page can come back empty with more to follow: public search drops files the database no longer calls public. |
| 33 | if (error || |
| 34 | return ( |
| 35 | <Empty className=" |
| 36 | <EmptyHeader> |
| 37 | <EmptyMedia variant=" |
| 38 | <FileCode2 /> |
| 39 | </EmptyMedia> |
| 40 | <EmptyTitle>{error |
| 41 | <EmptyDescription> |
| 42 | {error ?? |
| 43 | "Try different words, a /regex/, or a file: or lang: filter."} |
| 44 | </EmptyDescription> |
| 45 | </EmptyHeader> |
| 46 | </Empty> |
| 47 | ); |
| 48 | } |
| 49 | |
| 50 | return ( |
| 51 | <div className="flex flex-col gap-4 |
| 52 | {files.map(( |
| 53 | <CodeSearchFile |
| 54 | key={`${file |
| 55 | file={file} |
| 56 | repository={repository} |
| 57 | /> |
| 58 | ))} |
| 59 | {nextCursor !== null |
| 60 | <CodeSearchMore |
| 61 | key={query} |
| 62 | query={query} |
| 63 | repository={repository} |
| 64 | cursor={nextCursor} |
| 65 | /> |
| 66 | )} |
| 67 | </div> |
| 68 | ); |
| 69 | } |