import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { useState, useMemo } from "react"; import { Category } from "@/lib/types"; import Link from "next/link"; import Image from "next/image"; import { Button } from "./ui/button"; const ITEMS_PER_PAGE = 3; export default function RecentlyUpdatedScripts({ items, }: { items: Category[]; }) { const [page, setPage] = useState(1); const updatedScripts = useMemo(() => { if (!items) return []; const scripts = items.flatMap((category) => category.expand.items || []); const updatedScripts = scripts.map((script) => ({ ...script, updated: new Date(script.updated), })); return updatedScripts.sort( (a, b) => b.updated.getTime() - a.updated.getTime(), ); }, [items]); const goToNextPage = () => { setPage((prevPage) => prevPage + 1); }; const goToPreviousPage = () => { setPage((prevPage) => prevPage - 1); }; const startIndex = (page - 1) * ITEMS_PER_PAGE; const endIndex = page * ITEMS_PER_PAGE; return (
Last updated: {item.updated.toISOString().split("T")[0]}