blog-list.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use client";
  2. import Link from "next/link";
  3. import { Button, Card, CardBody, CardFooter } from "@heroui/react";
  4. import { RxCross2 } from "react-icons/rx";
  5. import Image from "next/image";
  6. import { Blog } from "@/types/blog";
  7. interface BlogListProps {
  8. blogPosts: (Blog & { imageUrl: string })[];
  9. }
  10. export function BlogList({ blogPosts }: BlogListProps) {
  11. return (
  12. <div className="px-4 pb-10">
  13. <div className="flex flex-col items-center mb-4 gap-2">
  14. <Link href="/" prefetch={true}>
  15. <Button
  16. isIconOnly
  17. aria-label="Back to home"
  18. className="dark:border-knight dark:bg-transparent dark:border-2 bg-[#ece7e7] border-0"
  19. radius="full"
  20. variant="bordered"
  21. >
  22. <RxCross2 />
  23. </Button>
  24. </Link>
  25. <h1 className="text-2xl font-[500]">My Blog</h1>
  26. </div>
  27. <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
  28. {blogPosts.map(({ id, title, imageUrl, createdAt }) => (
  29. <Link key={id} href={`/blog/${id}`}>
  30. <Card className="dark:bg-darkBg dark:border-2 dark:border-knight rounded-[2rem]">
  31. <CardBody className="p-0">
  32. <Image
  33. alt={title}
  34. className="w-full rounded-b-none object-cover h-[200px]"
  35. height={200}
  36. sizes="(max-width: 768px) 100vw, (max-width: 1024px) 50vw, 33vw"
  37. src={imageUrl}
  38. width={400}
  39. />
  40. </CardBody>
  41. <CardFooter className="flex justify-between">
  42. <h2 className="font-[500] text-lg">{title}</h2>
  43. <time className="text-sm" dateTime={createdAt.toISOString()}>
  44. {createdAt.toDateString()}
  45. </time>
  46. </CardFooter>
  47. </Card>
  48. </Link>
  49. ))}
  50. </div>
  51. </div>
  52. );
  53. }