diff --git a/frontend/app/(authenticated)/categories/[id]/page.tsx b/frontend/app/(authenticated)/categories/[id]/page.tsx index 9ea0fa8c..7729c748 100644 --- a/frontend/app/(authenticated)/categories/[id]/page.tsx +++ b/frontend/app/(authenticated)/categories/[id]/page.tsx @@ -1,73 +1,77 @@ "use client"; +import { useEffect, useState } from "react"; +import { useQuery } from "@tanstack/react-query"; + import { CategoryDTO, MiniEventDTO } from "@/client"; import ArticleLoading from "@/components/news/article-loading"; import NewsArticle from "@/components/news/news-article"; import { getCategories } from "@/queries/category"; import { getEventsForCategory } from "@/queries/event"; -import { useQuery } from "@tanstack/react-query"; -import { useEffect, useState } from "react"; const Page = ({ params }: { params: { id: string } }) => { - const categoryId = parseInt(params.id); - const [ categoryName, setCategoryName ] = useState(""); - const { data: events, isSuccess: isEventsLoaded } = useQuery(getEventsForCategory(categoryId)); - const { data: categories, isSuccess: isCategoriesLoaded } = useQuery(getCategories()); - - // Very inefficient, but is there a better way to do this? New StoreProvider for CategoryDTO[]? - useEffect(() => { - if (isCategoriesLoaded && categories!.length > 0) { - categories!.forEach((category: CategoryDTO) => { - if (category.id == categoryId) { - setCategoryName(category.name); - } - }); - } - }, [categories, isCategoriesLoaded]); + const categoryId = parseInt(params.id); + const [categoryName, setCategoryName] = useState(""); + const { data: events, isSuccess: isEventsLoaded } = useQuery( + getEventsForCategory(categoryId), + ); + const { data: categories, isSuccess: isCategoriesLoaded } = + useQuery(getCategories()); - const Articles = () => { - if (!isEventsLoaded) { - return ( - <> - - - - - ) + // Very inefficient, but is there a better way to do this? New StoreProvider for CategoryDTO[]? + useEffect(() => { + if (isCategoriesLoaded && categories!.length > 0) { + categories!.forEach((category: CategoryDTO) => { + if (category.id == categoryId) { + setCategoryName(category.name); } + }); + } + }, [categories, isCategoriesLoaded, categoryId]); - const eventData = events!.data; - if (eventData.length == 0) { - return ( -
-

No recent events. Try refreshing the page.

-
- ) - } + const Articles = () => { + if (!isEventsLoaded) { + return ( + <> + + + + + ); + } - return ( - eventData.map((newsEvent: MiniEventDTO, index: number) => ( - - )) - ) + const eventData = events!.data; + if (eventData.length == 0) { + return ( +
+

+ No recent events. Try refreshing the page. +

+
+ ); } - return ( -
-
- - {new Date().toDateString()} - -

- Top events from {categoryName} -

-
+ return eventData.map((newsEvent: MiniEventDTO, index: number) => ( + + )); + }; -
- -
-
- ) + return ( +
+
+ + {new Date().toDateString()} + +

+ Top events from {categoryName} +

+
+ +
+ +
+
+ ); }; export default Page; diff --git a/frontend/components/navigation/sidebar/sidebar-item-with-icon.tsx b/frontend/components/navigation/sidebar/sidebar-item-with-icon.tsx index 114c95fb..043e67d8 100644 --- a/frontend/components/navigation/sidebar/sidebar-item-with-icon.tsx +++ b/frontend/components/navigation/sidebar/sidebar-item-with-icon.tsx @@ -1,5 +1,5 @@ -import { LucideIcon } from "lucide-react"; import { useRouter } from "next/navigation"; +import { LucideIcon } from "lucide-react"; interface SidebarItemWithIconProps { Icon: LucideIcon; @@ -7,13 +7,20 @@ interface SidebarItemWithIconProps { categoryId: number; } -const SidebarItemWithIcon = ({ Icon, label, categoryId }: SidebarItemWithIconProps) => { +const SidebarItemWithIcon = ({ + Icon, + label, + categoryId, +}: SidebarItemWithIconProps) => { const router = useRouter(); const onClickCategory = () => router.push(`/categories/${categoryId}`); return ( -
+
{ - const { data: categories, isSuccess: isCategoriesSuccess } = useQuery(getCategories()); + const { data: categories } = useQuery(getCategories()); return (
@@ -18,17 +16,16 @@ const SidebarOtherTopics = () => { Other topics
- { - categories?.map((category) => { + {categories?.map((category) => { const categoryIcon = getIconFor(category.name); return ( - ) + ); })}
diff --git a/frontend/queries/event.ts b/frontend/queries/event.ts index ecd6266e..03530fcb 100644 --- a/frontend/queries/event.ts +++ b/frontend/queries/event.ts @@ -24,7 +24,7 @@ export const getEventsForCategory = (categoryId: number) => getEventsEventsGet({ withCredentials: true, query: { - category_ids: [ categoryId ] + category_ids: [ categoryId ], }, }).then((data) => data.data), });