blog-list.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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="cover"
  33. className="rounded-b-none object-cover h-[200px]"
  34. height={500}
  35. src={imageUrl}
  36. width={500}
  37. />
  38. </CardBody>
  39. <CardFooter className="flex justify-between">
  40. <h3 className="font-[500] text-lg">{title}</h3>
  41. <h3 className="text-sm">{createdAt.toDateString()}</h3>
  42. </CardFooter>
  43. </Card>
  44. </Link>
  45. ))}
  46. </div>
  47. </div>
  48. );
  49. }