From ac25b5a7027dc06faf5c10ca783de3f5e0d9d90b Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Mon, 27 Jan 2025 13:56:09 +0100 Subject: [PATCH] Update page.tsx --- frontend/src/app/category-view/page.tsx | 94 ++++++++++++++++--------- 1 file changed, 60 insertions(+), 34 deletions(-) diff --git a/frontend/src/app/category-view/page.tsx b/frontend/src/app/category-view/page.tsx index cad896ff..a6da9419 100644 --- a/frontend/src/app/category-view/page.tsx +++ b/frontend/src/app/category-view/page.tsx @@ -4,15 +4,18 @@ import React, { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { Card, CardContent } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; +import { ChevronLeft, ChevronRight } from "lucide-react"; import { Category } from "@/lib/types"; const defaultLogo = "/default-logo.png"; // Fallback logo path const MAX_DESCRIPTION_LENGTH = 100; // Set max length for description +const MAX_LOGOS = 5; // Max logos to display at once const CategoryView = () => { const [categories, setCategories] = useState([]); const [selectedCategory, setSelectedCategory] = useState(null); + const [logoIndex, setLogoIndex] = useState(0); // Keeps track of logo pagination const router = useRouter(); useEffect(() => { @@ -36,10 +39,12 @@ const CategoryView = () => { const handleCategoryClick = (category: Category) => { setSelectedCategory(category); + setLogoIndex(0); // Reset logo pagination when switching categories }; const handleBackClick = () => { setSelectedCategory(null); + setLogoIndex(0); // Reset logo pagination when going back }; const handleScriptClick = (scriptSlug: string) => { @@ -52,9 +57,8 @@ const CategoryView = () => { : text; }; - const getRandomScripts = (scripts: any[]) => { - if (!scripts || scripts.length <= 5) return scripts; - return scripts.sort(() => 0.5 - Math.random()).slice(0, 5); + const getVisibleLogos = (scripts: any[]) => { + return scripts.slice(logoIndex, logoIndex + MAX_LOGOS); }; return ( @@ -78,29 +82,27 @@ const CategoryView = () => { onClick={() => handleScriptClick(script.slug)} > -
-

{script.name}

-

- Created at: {script.date_created || "No date available"} -

-
-
+
{script.name} -
-
-

- {truncateDescription(script.description || "No description available.")} -

-
- CPU: {script.install_methods[0]?.resources.cpu || "N/A"}vCPU |{" "} - RAM: {script.install_methods[0]?.resources.ram || "N/A"}MB |{" "} - HDD: {script.install_methods[0]?.resources.hdd || "N/A"}GB +
+

{script.name}

+

+ Created at: {script.date_created || "No date available"} +

+

+ {truncateDescription(script.description || "No description available.")} +

+
+ CPU: {script.install_methods[0]?.resources.cpu || "N/A"}vCPU |{" "} + RAM: {script.install_methods[0]?.resources.ram || "N/A"}MB |{" "} + HDD: {script.install_methods[0]?.resources.hdd || "N/A"}GB +
))} @@ -123,21 +125,45 @@ const CategoryView = () => { >

{category.name}

-
- {category.scripts && - getRandomScripts(category.scripts).map((script, index) => ( - {script.name { - e.stopPropagation(); // Prevent card click - handleScriptClick(script.slug); - }} - className="h-8 w-8 object-contain cursor-pointer hover:scale-110 transition-transform" - /> - ))} +
+ +
+ {category.scripts && + getVisibleLogos(category.scripts).map((script, index) => ( + {script.name { + e.stopPropagation(); // Prevent card click + handleScriptClick(script.slug); + }} + className="h-8 w-8 object-contain cursor-pointer hover:scale-110 transition-transform" + /> + ))} +
+

{(category as any).description || "No description available."}