diff --git a/frontend/src/app/category-view/page.tsx b/frontend/src/app/category-view/page.tsx index 0b5ffa15..95b7388f 100644 --- a/frontend/src/app/category-view/page.tsx +++ b/frontend/src/app/category-view/page.tsx @@ -4,6 +4,7 @@ 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 { Badge } from "@/components/ui/badge"; import { ChevronLeft, ChevronRight } from "lucide-react"; import { Category } from "@/lib/types"; @@ -11,9 +12,24 @@ 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 formattedBadge = (type: string) => { + switch (type) { + case "vm": + return VM; + case "ct": + return ( + LXC + ); + case "misc": + return MISC; + } + return null; +}; + const CategoryView = () => { const [categories, setCategories] = useState([]); const [selectedCategoryIndex, setSelectedCategoryIndex] = useState(null); + const [logoIndices, setLogoIndices] = useState<{ [key: string]: number }>({}); const router = useRouter(); useEffect(() => { @@ -27,6 +43,13 @@ const CategoryView = () => { const data = await response.json(); console.log("Fetched categories:", data); // Debugging setCategories(data); + + // Initialize logo indices + const initialLogoIndices: { [key: string]: number } = {}; + data.forEach((category: any) => { + initialLogoIndices[category.name] = 0; + }); + setLogoIndices(initialLogoIndices); } catch (error) { console.error("Error fetching categories:", error); } @@ -57,6 +80,22 @@ const CategoryView = () => { } }; + const switchLogos = (categoryName: string, direction: "prev" | "next") => { + setLogoIndices((prev) => { + const currentIndex = prev[categoryName] || 0; + const category = categories.find((cat) => cat.name === categoryName); + if (!category || !category.scripts) return prev; + + const totalLogos = category.scripts.length; + const newIndex = + direction === "prev" + ? (currentIndex - MAX_LOGOS + totalLogos) % totalLogos + : (currentIndex + MAX_LOGOS) % totalLogos; + + return { ...prev, [categoryName]: newIndex }; + }); + }; + const truncateDescription = (text: string) => { return text.length > MAX_DESCRIPTION_LENGTH ? `${text.slice(0, MAX_DESCRIPTION_LENGTH)}...` @@ -85,14 +124,6 @@ const CategoryView = () => { ) : null; }; - const renderType = (type: string) => { - return ( - - {type.toUpperCase()} - - ); - }; - return (
{categories.length === 0 && ( @@ -132,7 +163,7 @@ const CategoryView = () => {

{script.name}

- {renderType(script.type || "MISC")} + {formattedBadge(script.type || "misc")}

Created at: {script.date_created || "No date available"} @@ -178,21 +209,37 @@ const CategoryView = () => { >

{category.name}

-
+
+ {category.scripts && - category.scripts.slice(0, 5).map((script, i) => ( - {script.name { - e.stopPropagation(); // Verhindert Klick auf die Kategorie - handleScriptClick(script.slug); - }} - /> - ))} + category.scripts + .slice(logoIndices[category.name] || 0, (logoIndices[category.name] || 0) + MAX_LOGOS) + .map((script, i) => ( + {script.name { + e.stopPropagation(); + handleScriptClick(script.slug); + }} + /> + ))} +

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