blog-list.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. className="dark:border-knight dark:bg-transparent dark:border-2 bg-[#ece7e7] border-0"
  18. radius="full"
  19. variant="bordered"
  20. >
  21. <RxCross2 />
  22. </Button>
  23. </Link>
  24. <h1 className="text-2xl font-[500]">My Blog</h1>
  25. </div>
  26. <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
  27. {blogPosts.map(({ id, title, imageUrl, createdAt }) => (
  28. <Link key={id} href={`/blog/${id}`}>
  29. <Card className="dark:bg-darkBg dark:border-2 dark:border-knight rounded-[2rem]">
  30. <CardBody className="p-0">
  31. <Image
  32. alt={title}
  33. className="rounded-b-none object-cover h-[200px]"
  34. height={200}
  35. sizes="(max-width: 768px) 100vw, (max-width: 1024px) 50vw, 33vw"
  36. src={imageUrl}
  37. width={400}
  38. />
  39. </CardBody>
  40. <CardFooter className="flex justify-between">
  41. <h3 className="font-[500] text-lg">{title}</h3>
  42. <h3 className="text-sm">{createdAt.toDateString()}</h3>
  43. </CardFooter>
  44. </Card>
  45. </Link>
  46. ))}
  47. </div>
  48. </div>
  49. );
  50. }