From 13100beb198803b9a7be28923483340d52a77ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20CRAH=C3=89?= Date: Thu, 25 Apr 2024 18:44:50 +0200 Subject: [PATCH] display list of ressources --- .../(front-office)/category/[id]/page.tsx | 89 ++++++++++--------- 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/frontend/src/app/(connected)/(front-office)/category/[id]/page.tsx b/frontend/src/app/(connected)/(front-office)/category/[id]/page.tsx index 1056564..c7ce716 100644 --- a/frontend/src/app/(connected)/(front-office)/category/[id]/page.tsx +++ b/frontend/src/app/(connected)/(front-office)/category/[id]/page.tsx @@ -4,53 +4,56 @@ import { Icon } from '@iconify/react'; import { Category } from "@/types/category"; import { useState, useEffect } from "react"; import axios from 'axios'; +import { useUser } from "@/providers/userProvider"; +import ListOfRessourcesAccordion from "@/components/front-office/ressource-management/listOfRessourcesAccordion"; +import PageSummary from "@/components/pageSummary"; const { Paragraph } = Typography; -export default function CategoryPage({ params }: { params: {id: string} }) { - const [resources, setResources] = useState([]); - const [isLoading, setIsLoading] = useState(false); +export default function CategoryPage({ params }: { params: { id: string } }) { + const [category, setCategory] = useState(); + const [resources, setResources] = useState([]); + const [isLoading, setIsLoading] = useState(false); + const {user} = useUser(); - useEffect(()=>{ - fetchResources(); - }, []) + useEffect(() => { + fetchResources(); + }, []) - const fetchResources = async () => { - try { - setIsLoading(true); - const response = await axios({ - method: 'GET', - baseURL: process.env.NEXT_PUBLIC_BACKEND_API_URL, - url: `/category/${params.id}`, - responseType: 'json', - timeout: 10000, - withCredentials: true, - }); - setResources(response.data.category.ressources); - } catch (error) { - console.error("Error fetching resources:", error); - } finally { - setIsLoading(false); - } - }; + const fetchResources = async () => { + try { + setIsLoading(true); + const response = await axios({ + method: 'GET', + baseURL: process.env.NEXT_PUBLIC_BACKEND_API_URL, + url: `/category/${params.id}`, + responseType: 'json', + timeout: 10000, + withCredentials: true, + }); + console.log(response.data.category.ressources); + setResources(response.data.category.ressources); + setCategory(response.data.category); + } catch (error) { + console.error("Error fetching resources:", error); + } finally { + setIsLoading(false); + } + }; - return ( - <> - - {resources.length > 0 && ( -
- {/*

Ressources liées à {category.title} :

*/} - {isLoading ? ( -

Loading...

- ) : ( -
    - {resources.map((resource, index) => ( -
  • {resource.label}
  • - ))} -
- )} -
- )} - - ); + return ( +
+ + {resources.length > 0 && ( +
+ {/*

Ressources liées à {category.title} :

*/} + {isLoading ? ( +

Loading...

+ ) : ( + + )} +
+ )} +
+ ); } \ No newline at end of file