|
| 1 | +import Link from "next/link"; |
| 2 | +import Image from "next/image"; |
| 3 | +import { |
| 4 | + Sheet, |
| 5 | + SheetContent, |
| 6 | + SheetDescription, |
| 7 | + SheetHeader, |
| 8 | + SheetTitle, |
| 9 | + SheetTrigger, |
| 10 | +} from "@/components/ui/sheet"; |
| 11 | +import { createSearchIndex, exactTagSearch } from "@/lib/searchUtils"; |
| 12 | +import { fetchAllPages } from "@/lib/notion-utils"; |
| 13 | +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; |
| 14 | +import { Suspense } from "react"; |
| 15 | + |
| 16 | +export default async function HighlightPanel() { |
| 17 | + const notionPages = await fetchAllPages(); |
| 18 | + const searchIndex = createSearchIndex(notionPages); |
| 19 | + const searchResults = exactTagSearch("Highlights", searchIndex); |
| 20 | + |
| 21 | + const contractSummary = (text: string) => |
| 22 | + text.length > 180 ? text.slice(0, 180) + "..." : text; |
| 23 | + |
| 24 | + return ( |
| 25 | + <Sheet> |
| 26 | + <SheetTrigger className="fixed right-[-56px] top-80 z-10 flex h-[45px] w-[140px] -rotate-90 justify-center rounded-t-2xl bg-primary px-4 py-1 text-lg font-semibold text-primary-foreground shadow-md transition-all duration-200 hover:right-[-50px] md:h-[80px] md:hover:right-[-30px]"> |
| 27 | + Highlights |
| 28 | + </SheetTrigger> |
| 29 | + <SheetContent> |
| 30 | + <SheetHeader> |
| 31 | + <SheetTitle className="text-xl font-bold">Highlights</SheetTitle> |
| 32 | + <SheetDescription></SheetDescription> |
| 33 | + </SheetHeader> |
| 34 | + |
| 35 | + <div className="flex flex-col space-y-3"> |
| 36 | + {searchResults.length > 0 ? ( |
| 37 | + searchResults.map((item) => ( |
| 38 | + <Link |
| 39 | + key={item.pageId} |
| 40 | + href={`${item.relativeLink}/${item.slug}`} |
| 41 | + > |
| 42 | + <Card className="cursor-pointer transition-all duration-200 hover:shadow-md"> |
| 43 | + <CardHeader> |
| 44 | + <CardTitle className="text-lg">{item.title}</CardTitle> |
| 45 | + </CardHeader> |
| 46 | + <CardContent className="flex flex-col"> |
| 47 | + {item.imageUrl ? ( |
| 48 | + <Suspense |
| 49 | + fallback={ |
| 50 | + <div className="flex h-full w-full items-center justify-center bg-gray-200"> |
| 51 | + Loading... |
| 52 | + </div> |
| 53 | + } |
| 54 | + > |
| 55 | + <Image |
| 56 | + src={item.imageUrl} |
| 57 | + alt={item.title} |
| 58 | + width={400} |
| 59 | + height={300} |
| 60 | + className="h-full w-full object-cover" |
| 61 | + /> |
| 62 | + </Suspense> |
| 63 | + ) : ( |
| 64 | + <div className="flex h-48 items-center justify-center rounded-md bg-gray-200"> |
| 65 | + No image |
| 66 | + </div> |
| 67 | + )} |
| 68 | + <p className="mt-2 text-sm"> |
| 69 | + {contractSummary(item.summary)} |
| 70 | + </p> |
| 71 | + </CardContent> |
| 72 | + </Card> |
| 73 | + </Link> |
| 74 | + )) |
| 75 | + ) : ( |
| 76 | + <p className="text-center text-gray-500">No highlights found.</p> |
| 77 | + )} |
| 78 | + </div> |
| 79 | + </SheetContent> |
| 80 | + </Sheet> |
| 81 | + ); |
| 82 | +} |
0 commit comments