Skip to content

Commit

Permalink
Update index.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
MickLesk committed Jan 23, 2025
1 parent 70ef075 commit 9f29a66
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions frontend/src/app/category-view/index.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
import React, { useState } from 'react';
import { Card, CardContent, CardHeader } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { routes } from '@/routes'; // Assuming your route.ts file is at this location
import { Grid } from '@mui/material'; // Using Material-UI's Grid
"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";

const CategoryView = () => {
const [selectedCategory, setSelectedCategory] = useState(null);
const [categories, setCategories] = useState<Category[]>([]);
const [selectedCategory, setSelectedCategory] = useState<Category | null>(null);

useEffect(() => {
fetchCategories()
.then(setCategories)
.catch((error) => console.error("Error fetching categories:", error));
}, []);

const handleCategoryClick = (category) => {
const handleCategoryClick = (category: Category) => {
setSelectedCategory(category);
};

const handleBackClick = () => {
setSelectedCategory(null);
};

const categories = routes.map((route) => ({
name: route.category,
scripts: route.scripts.map((script) => ({
name: script.name,
date: script.date || 'N/A', // Assuming scripts have a `date` field
})),
}));

return (
<div className="p-4">
{selectedCategory ? (
Expand All @@ -39,7 +41,7 @@ const CategoryView = () => {
<Card>
<CardContent>
<h3 className="text-lg font-medium">{script.name}</h3>
<p className="text-sm text-gray-600">{script.date}</p>
<p className="text-sm text-gray-600">{script.date || "N/A"}</p>
</CardContent>
</Card>
</Grid>
Expand Down Expand Up @@ -67,4 +69,4 @@ const CategoryView = () => {
);
};

export default CategoryView;
export default CategoryView;

0 comments on commit 9f29a66

Please sign in to comment.