|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import Link from "next/link"; |
| 4 | +import { Card, CardHeader } from "@heroui/react"; |
| 5 | +import { formatDistanceToNow } from "date-fns"; |
| 6 | +import { Folder, Timer } from "lucide-react"; |
| 7 | +import { useCategoryStore } from "@/stores/categories"; |
| 8 | +import { capitalize } from "@/lib/utils"; |
| 9 | +import type { Category } from "@/types"; |
| 10 | + |
| 11 | +export default function CategoryList() { |
| 12 | + const categories = useCategoryStore((state) => state.categories); |
| 13 | + |
| 14 | + return ( |
| 15 | + <section className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4"> |
| 16 | + {categories.map((category) => ( |
| 17 | + <CategoryCard key={category.id} category={category} /> |
| 18 | + ))} |
| 19 | + </section> |
| 20 | + ); |
| 21 | +} |
| 22 | + |
| 23 | +function CategoryCard({ category }: { category: Category }) { |
| 24 | + return ( |
| 25 | + <article className="group"> |
| 26 | + <Link href={`/resources/categories/${category.slug}`}> |
| 27 | + <Card className="bg-white dark:bg-neutral-950 !outline-none shadow-none rounded-xl border-2 border-neutral-200 dark:border-neutral-800 group-hover:border-neutral-300 dark:group-hover:border-neutral-700"> |
| 28 | + <CardHeader className="flex items-center justify-between"> |
| 29 | + <div className="flex items-center gap-3"> |
| 30 | + <Folder className="w-5 h-5 text-neutral-950 dark:text-white" /> |
| 31 | + <span className="text-sm font-medium text-neutral-950 dark:text-white"> |
| 32 | + {capitalize(category.name)} |
| 33 | + </span> |
| 34 | + </div> |
| 35 | + <div className="flex justify-end items-center gap-2 text-xs text-neutral-500"> |
| 36 | + <Timer size={16} /> |
| 37 | + {formatDistanceToNow(new Date(category.created_at), { |
| 38 | + addSuffix: true, |
| 39 | + })} |
| 40 | + </div> |
| 41 | + </CardHeader> |
| 42 | + </Card> |
| 43 | + </Link> |
| 44 | + </article> |
| 45 | + ); |
| 46 | +} |
0 commit comments