blog-list.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 | undefined })[];
  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. {imageUrl && (
  32. <CardBody className="p-0">
  33. <Image
  34. alt={title}
  35. className="w-full rounded-b-none object-cover h-[200px]"
  36. height={200}
  37. sizes="(max-width: 768px) 100vw, (max-width: 1024px) 50vw, 33vw"
  38. src={imageUrl}
  39. width={400}
  40. />
  41. </CardBody>
  42. )}
  43. <CardFooter className="flex justify-between">
  44. <h2 className="font-[500] text-lg">{title}</h2>
  45. {createdAt && (
  46. <time className="text-sm" dateTime={createdAt.toISOString()}>
  47. {createdAt.toDateString()}
  48. </time>
  49. )}
  50. </CardFooter>
  51. </Card>
  52. </Link>
  53. ))}
  54. </div>
  55. </div>
  56. );
  57. }