-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
79 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string>(""); | ||
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<string>(""); | ||
const { data: events, isSuccess: isEventsLoaded } = useQuery( | ||
getEventsForCategory(categoryId), | ||
); | ||
const { data: categories, isSuccess: isCategoriesLoaded } = | ||
useQuery(getCategories()); | ||
|
||
const Articles = () => { | ||
if (!isEventsLoaded) { | ||
return ( | ||
<> | ||
<ArticleLoading /> | ||
<ArticleLoading /> | ||
<ArticleLoading /> | ||
</> | ||
) | ||
// 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 ( | ||
<div className="flex w-full justify-center"> | ||
<p className="text-sm text-offblack">No recent events. Try refreshing the page.</p> | ||
</div> | ||
) | ||
} | ||
const Articles = () => { | ||
if (!isEventsLoaded) { | ||
return ( | ||
<> | ||
<ArticleLoading /> | ||
<ArticleLoading /> | ||
<ArticleLoading /> | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
eventData.map((newsEvent: MiniEventDTO, index: number) => ( | ||
<NewsArticle key={index} newsEvent={newsEvent} /> | ||
)) | ||
) | ||
const eventData = events!.data; | ||
if (eventData.length == 0) { | ||
return ( | ||
<div className="flex w-full justify-center"> | ||
<p className="text-sm text-offblack"> | ||
No recent events. Try refreshing the page. | ||
</p> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col w-full py-8"> | ||
<div className="flex flex-col mb-8 gap-y-2 mx-8 md:mx-16 xl:mx-32"> | ||
<span className="text-sm text-muted-foreground"> | ||
{new Date().toDateString()} | ||
</span> | ||
<h1 className="text-3xl 2xl:text-4xl font-bold"> | ||
Top events from {categoryName} | ||
</h1> | ||
</div> | ||
return eventData.map((newsEvent: MiniEventDTO, index: number) => ( | ||
<NewsArticle key={index} newsEvent={newsEvent} /> | ||
)); | ||
}; | ||
|
||
<div className="flex flex-col w-auto mx-4 md:mx-8 xl:mx-24"> | ||
<Articles /> | ||
</div> | ||
</div> | ||
) | ||
return ( | ||
<div className="flex flex-col w-full py-8"> | ||
<div className="flex flex-col mb-8 gap-y-2 mx-8 md:mx-16 xl:mx-32"> | ||
<span className="text-sm text-muted-foreground"> | ||
{new Date().toDateString()} | ||
</span> | ||
<h1 className="text-3xl 2xl:text-4xl font-bold"> | ||
Top events from {categoryName} | ||
</h1> | ||
</div> | ||
|
||
<div className="flex flex-col w-auto mx-4 md:mx-8 xl:mx-24"> | ||
<Articles /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Page; |
13 changes: 10 additions & 3 deletions
13
frontend/components/navigation/sidebar/sidebar-item-with-icon.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 10 additions & 13 deletions
23
frontend/components/navigation/sidebar/sidebar-other-topics.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters