From 5933dd03b86d0f6dcb283576b7a48772d9f27449 Mon Sep 17 00:00:00 2001 From: j285he Date: Fri, 27 Aug 2021 18:37:42 -0400 Subject: [PATCH] Add /events page (#159) Closes #111 Blocked by !158 Co-authored-by: Jared He <66887902+jaredjhe@users.noreply.github.com> Co-authored-by: Aditya Thakral Reviewed-on: https://git.csclub.uwaterloo.ca/www/www-new/pulls/159 Reviewed-by: Aditya Thakral Co-authored-by: j285he Co-committed-by: j285he --- lib/events.ts | 8 +++++++- pages/events/[year]/[term]/index.tsx | 16 +++++++++++----- pages/events/index.tsx | 11 +++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 pages/events/index.tsx diff --git a/lib/events.ts b/lib/events.ts index a909434d..db6f5cb0 100644 --- a/lib/events.ts +++ b/lib/events.ts @@ -104,7 +104,13 @@ export async function getUpcomingEvents(): Promise { }); } -export async function getProps(year: string, term: string): Promise { +export async function getEventsPageProps({ + year, + term, +}: { + year: string; + term: string; +}): Promise { const eventNames = await getEventsByTerm(year, term); const events: Event[] = ( diff --git a/pages/events/[year]/[term]/index.tsx b/pages/events/[year]/[term]/index.tsx index 34a8c8e4..f8b9f1fd 100644 --- a/pages/events/[year]/[term]/index.tsx +++ b/pages/events/[year]/[term]/index.tsx @@ -9,7 +9,7 @@ import { Link } from "@/components/Link"; import { MiniEventCard } from "@/components/MiniEventCard"; import { Event, - getProps, + getEventsPageProps, getEventYears, getEventTermsByYear, } from "@/lib/events"; @@ -61,7 +61,7 @@ export default function Term(props: Props) { key={link.year + link.term} /> ))} - Archives + Archive {hasFutureEvents && ( <> @@ -88,6 +88,14 @@ export default function Term(props: Props) { )} + {!hasFutureEvents && !hasPastEvents && ( + <> +

Events

+ There are no upcoming or past events for the{" "} + {`${capitalize(props.term)} ${props.year}`} term. Please check back + later! + + )}
{props.pastEvents.map(({ content, metadata }) => ( = async ( context ) => { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const { year, term } = context.params!; - - return { props: await getProps(year, term) }; + return { props: await getEventsPageProps(context.params!) }; }; export const getStaticPaths: GetStaticPaths = async () => { diff --git a/pages/events/index.tsx b/pages/events/index.tsx new file mode 100644 index 00000000..5f016465 --- /dev/null +++ b/pages/events/index.tsx @@ -0,0 +1,11 @@ +import { GetStaticProps } from "next"; + +import { getCurrentTerm, getEventsPageProps } from "@/lib/events"; + +import Term, { Props } from "./[year]/[term]/index"; + +export default Term; + +export const getStaticProps: GetStaticProps = async () => { + return { props: await getEventsPageProps(getCurrentTerm()) }; +};