Files
ProxmoxVE/frontend/src/app/category-view/index.tsx

73 lines
2.3 KiB
TypeScript
Raw Normal View History

2025-01-23 09:33:34 +01:00
"use client";
import React, { useEffect, useState } from "react";
import { Card, CardContent, CardHeader } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { Grid } from "@mui/material";
import { fetchCategories } from "@/lib/data";
import { Category } from "@/lib/types";
2025-01-23 09:27:58 +01:00
const CategoryView = () => {
2025-01-23 09:33:34 +01:00
const [categories, setCategories] = useState<Category[]>([]);
const [selectedCategory, setSelectedCategory] = useState<Category | null>(null);
useEffect(() => {
fetchCategories()
.then(setCategories)
.catch((error) => console.error("Error fetching categories:", error));
}, []);
2025-01-23 09:27:58 +01:00
2025-01-23 09:33:34 +01:00
const handleCategoryClick = (category: Category) => {
2025-01-23 09:27:58 +01:00
setSelectedCategory(category);
};
const handleBackClick = () => {
setSelectedCategory(null);
};
return (
<div className="p-4">
{selectedCategory ? (
<div>
<Button variant="primary" onClick={handleBackClick} className="mb-4">
Back to Categories
</Button>
<h2 className="text-xl font-semibold mb-4">{selectedCategory.name}</h2>
2025-01-23 09:30:00 +01:00
<Grid container spacing={3}>
2025-01-23 09:27:58 +01:00
{selectedCategory.scripts
.sort((a, b) => a.name.localeCompare(b.name))
.map((script) => (
2025-01-23 09:30:00 +01:00
<Grid item xs={12} sm={6} md={4} key={script.name}>
<Card>
<CardContent>
<h3 className="text-lg font-medium">{script.name}</h3>
2025-01-23 09:33:34 +01:00
<p className="text-sm text-gray-600">{script.date || "N/A"}</p>
2025-01-23 09:30:00 +01:00
</CardContent>
</Card>
</Grid>
2025-01-23 09:27:58 +01:00
))}
</Grid>
</div>
) : (
<div>
<h1 className="text-2xl font-bold mb-6">Categories</h1>
2025-01-23 09:30:00 +01:00
<Grid container spacing={3}>
2025-01-23 09:27:58 +01:00
{categories.map((category) => (
2025-01-23 09:30:00 +01:00
<Grid item xs={12} sm={6} md={4} key={category.name}>
<Card
onClick={() => handleCategoryClick(category)}
className="cursor-pointer hover:shadow-lg"
>
<CardHeader title={category.name} className="text-lg font-semibold" />
</Card>
</Grid>
2025-01-23 09:27:58 +01:00
))}
</Grid>
</div>
)}
</div>
);
};
2025-01-23 09:33:34 +01:00
export default CategoryView;