mirror of
https://github.com/community-scripts/ProxmoxVE
synced 2025-01-30 20:40:15 +00:00
Update page.tsx
This commit is contained in:
parent
9f3a1c8531
commit
a3979001fe
@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { Card, CardContent, CardHeader } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Category } from "@/lib/types";
|
import { Category } from "@/lib/types";
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ const CategoryView = () => {
|
|||||||
const fetchCategories = async () => {
|
const fetchCategories = async () => {
|
||||||
try {
|
try {
|
||||||
const basePath = process.env.NODE_ENV === "production" ? "/ProxmoxVE" : "";
|
const basePath = process.env.NODE_ENV === "production" ? "/ProxmoxVE" : "";
|
||||||
const response = await fetch(`${basePath}/json/categories.json`);
|
const response = await fetch(`${basePath}/api/categories`); // Prüfe den Endpunkt
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Failed to fetch categories");
|
throw new Error("Failed to fetch categories");
|
||||||
}
|
}
|
||||||
@ -40,17 +40,18 @@ const CategoryView = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-4">
|
<div className="p-4">
|
||||||
{categories.length === 0 && (
|
{categories.length === 0 ? (
|
||||||
<p className="text-center text-gray-500">No categories available. Please check the API endpoint.</p>
|
<p className="text-center text-gray-500">
|
||||||
)}
|
No categories available. Please check the API endpoint.
|
||||||
{selectedCategory ? (
|
</p>
|
||||||
|
) : selectedCategory ? (
|
||||||
<div>
|
<div>
|
||||||
<Button variant="default" onClick={handleBackClick} className="mb-4">
|
<Button variant="default" onClick={handleBackClick} className="mb-4">
|
||||||
Back to Categories
|
Back to Categories
|
||||||
</Button>
|
</Button>
|
||||||
<h2 className="text-xl font-semibold mb-4">{selectedCategory.name}</h2>
|
<h2 className="text-xl font-semibold mb-4">{selectedCategory.name}</h2>
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
|
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
|
||||||
{selectedCategory.scripts
|
{(selectedCategory.scripts || [])
|
||||||
.sort((a, b) => a.name.localeCompare(b.name))
|
.sort((a, b) => a.name.localeCompare(b.name))
|
||||||
.map((script) => (
|
.map((script) => (
|
||||||
<Card key={script.name}>
|
<Card key={script.name}>
|
||||||
@ -76,7 +77,7 @@ const CategoryView = () => {
|
|||||||
>
|
>
|
||||||
<CardContent className="flex flex-col items-center">
|
<CardContent className="flex flex-col items-center">
|
||||||
<div className="flex flex-wrap justify-center gap-1 mb-2">
|
<div className="flex flex-wrap justify-center gap-1 mb-2">
|
||||||
{category.scripts && category.scripts.slice(0, 4).map((script, index) => (
|
{(category.scripts || []).slice(0, 4).map((script, index) => (
|
||||||
<img
|
<img
|
||||||
key={index}
|
key={index}
|
||||||
src={script.logo || defaultLogo}
|
src={script.logo || defaultLogo}
|
||||||
@ -87,7 +88,7 @@ const CategoryView = () => {
|
|||||||
</div>
|
</div>
|
||||||
<h3 className="text-lg font-bold mb-1">{category.name}</h3>
|
<h3 className="text-lg font-bold mb-1">{category.name}</h3>
|
||||||
<p className="text-sm text-gray-500 text-center">
|
<p className="text-sm text-gray-500 text-center">
|
||||||
{(category as any).description || "No description available."}
|
{category.description || "No description available."}
|
||||||
</p>
|
</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
Loading…
Reference in New Issue
Block a user