| 1 | import type { Metadata } from "next"; |
| 2 | import { notFound } |
| 3 | import { LoaderCircle, Search |
| 4 | |
| 5 | import { CodeSearchResults } |
| 6 | import { SearchForm } |
| 7 | import { Alert, AlertDescription |
| 8 | import { |
| 9 | Empty, |
| 10 | EmptyDescription, |
| 11 | EmptyHeader, |
| 12 | EmptyMedia, |
| 13 | EmptyTitle, |
| 14 | } from "@/components/ui/empty"; |
| 15 | import { createServerClient } |
| 16 | |
| 17 | export async function generateMetadata |
| 18 | params, |
| 19 | searchParams, |
| 20 | }: PageProps< |
| 21 | const [{ username, |
| 22 | const query = |
| 23 | const title = |
| 24 | const image = |
| 25 | |
| 26 | return { |
| 27 | title, |
| 28 | openGraph: { title, |
| 29 | twitter: { images: [ |
| 30 | }; |
| 31 | } |
| 32 | |
| 33 | export default async function |
| 34 | params, |
| 35 | searchParams, |
| 36 | }: PageProps< |
| 37 | const [{ username, |
| 38 | const query = |
| 39 | |
| 40 | const searchForm = |
| 41 | <SearchForm |
| 42 | action={`/${username |
| 43 | placeholder="Search this repository" |
| 44 | query={query} |
| 45 | autoFocus={!query} |
| 46 | /> |
| 47 | ); |
| 48 | |
| 49 | if (!query) |
| 50 | return ( |
| 51 | <div className="flex flex-col gap-4 |
| 52 | {searchForm} |
| 53 | <Empty className=" |
| 54 | <EmptyHeader> |
| 55 | <EmptyMedia variant=" |
| 56 | <Search /> |
| 57 | </EmptyMedia> |
| 58 | <EmptyTitle>Search this repository</EmptyTitle |
| 59 | <EmptyDescription> |
| 60 | Type in the search bar above to search the code on the default |
| 61 | branch. |
| 62 | </EmptyDescription> |
| 63 | </EmptyHeader> |
| 64 | </Empty> |
| 65 | </div> |
| 66 | ); |
| 67 | } |
| 68 | |
| 69 | const client = |
| 70 | const { data, |
| 71 | "/api/repositories/{username}/{slug}/search", |
| 72 | { params: { path: |
| 73 | ); |
| 74 | if (response.status |
| 75 | |
| 76 | return ( |
| 77 | <div className="flex flex-col gap-4 |
| 78 | {searchForm} |
| 79 | {data?.indexing && |
| 80 | <Alert> |
| 81 | <LoaderCircle className=" |
| 82 | <AlertDescription> |
| 83 | The latest commits are being indexed. Results may be missing them |
| 84 | for a few seconds. |
| 85 | </AlertDescription> |
| 86 | </Alert> |
| 87 | )} |
| 88 | <CodeSearchResults |
| 89 | files={data?.files |
| 90 | repository={{ owner: |
| 91 | error={error?.message |
| 92 | /> |
| 93 | </div> |
| 94 | ); |
| 95 | } |