Add event info page getStaticProps

This commit is contained in:
Amy 2021-08-17 16:44:37 -04:00
parent 2c84e60d06
commit b98d7b9e06
1 changed files with 14 additions and 16 deletions

View File

@ -4,24 +4,21 @@ import { GetStaticPaths, GetStaticProps } from "next";
import { MDXRemote } from "next-mdx-remote";
import React from "react";
import { EventCard } from "../../../../components/EventCard";
import { EventCard } from "@/components/EventCard";
import {
Event,
getEventYears,
getEventTermsByYear,
getEventsByTerm,
getEventBySlug,
} from "../../../../lib/events";
} from "@/lib/events";
export default function EventInfoPage(props: Props) {
return <p>Hello, world!</p>;
}
interface Props {
// event: Event;
event: string;
poster?: string;
registerLink?: string;
event: Event;
}
interface Params extends ParsedUrlQuery {
@ -30,12 +27,12 @@ interface Params extends ParsedUrlQuery {
event: string;
}
export const getStaticProps: GetStaticProps<Props, Params> = async () => {
return {
props: {
event: "test",
},
};
export const getStaticProps: GetStaticProps<Props, Params> = async (
context
) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const { year, term, event } = context.params!;
return { props: { event: await getEventBySlug(year, term, event) } };
};
export const getStaticPaths: GetStaticPaths<Params> = async () => {
@ -51,10 +48,11 @@ export const getStaticPaths: GetStaticPaths<Params> = async () => {
const events = (
await Promise.all(
terms.map(async (term) => {
const eventsInYear = await getEventsByTerm(term.year, term.term);
return eventsInYear.map((event) => {
return { year: term.year, term: term.term, event: event };
});
const eventsInTerm = await getEventsByTerm(term.year, term.term);
return eventsInTerm.map((event) => ({
...term,
event,
}));
})
)
).flat();