Clean up props and add links based on PR comments
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Amy 2021-08-22 17:17:43 -04:00
parent 80890eef2a
commit 314272fe1e
1 changed files with 44 additions and 34 deletions

View File

@ -1,5 +1,3 @@
import { ParsedUrlQuery } from "querystring";
import { GetStaticProps } from "next"; import { GetStaticProps } from "next";
import { MDXRemote } from "next-mdx-remote"; import { MDXRemote } from "next-mdx-remote";
import React from "react"; import React from "react";
@ -9,6 +7,7 @@ import { DefaultLayout } from "@/components/DefaultLayout";
import { EmailSignup } from "@/components/EmailSignup"; import { EmailSignup } from "@/components/EmailSignup";
import { EventDescriptionCard } from "@/components/EventDescriptionCard"; import { EventDescriptionCard } from "@/components/EventDescriptionCard";
import { Image } from "@/components/Image"; import { Image } from "@/components/Image";
import { Link } from "@/components/Link";
import { NewsCard } from "@/components/NewsCard"; import { NewsCard } from "@/components/NewsCard";
import { SocialLinks } from "@/components/SocialLinks"; import { SocialLinks } from "@/components/SocialLinks";
import { Event, getUpcomingEvents } from "@/lib/events"; import { Event, getUpcomingEvents } from "@/lib/events";
@ -17,8 +16,9 @@ import { News, getRecentNews } from "@/lib/news";
import styles from "./index.module.css"; import styles from "./index.module.css";
interface Props { interface Props {
events: Event[]; numberOfEvents: number; // total number of upcoming events
news: News[]; events: Event[]; // array of 0 - 2 events
news: News;
} }
export default function Home(props: Props) { export default function Home(props: Props) {
@ -48,52 +48,58 @@ export default function Home(props: Props) {
</DefaultLayout> </DefaultLayout>
<div className={styles.cardsBackground}> <div className={styles.cardsBackground}>
<div className={styles.cards}> <div className={styles.cards}>
{/* TODO: add links to past/upcoming events and past news */}
<section className={styles.events}> <section className={styles.events}>
<h1 className={styles.cardsHeading}>Upcoming Events</h1> <h1 className={styles.cardsHeading}>Upcoming Events</h1>
<p className={styles.cardsDescription}>See past events here</p> <p className={styles.cardsDescription}>
See past events{" "}
<Link href="/events/archive">
<a title="Events Archive">here</a>
</Link>
</p>
<hr className={styles.cardsDividingLine} /> <hr className={styles.cardsDividingLine} />
{props.events.length == 0 ? ( {props.numberOfEvents == 0 ? (
<p> <p>
There are no upcoming events right now. Please check back later! There are no upcoming events right now. Please check back later!
</p> </p>
) : null} ) : null}
<div className={styles.eventCards}> <div className={styles.eventCards}>
{props.events.length > 0 {props.events.length > 0
? props.events ? props.events.map((event) => (
.slice(0, 2) <EventDescriptionCard
.map((event) => ( {...event.metadata}
<EventDescriptionCard date={new Date(event.metadata.date)}
{...event.metadata} key={event.metadata.name + event.metadata.date.toString()}
date={new Date(event.metadata.date)} />
key={ ))
event.metadata.name + event.metadata.date.toString()
}
/>
))
: null} : null}
</div> </div>
{props.events.length > 2 ? ( {props.numberOfEvents > 2 ? (
<p>See more upcoming events here</p> <p>
See more upcoming events{" "}
<Link href="/events">
<a title="Events">here</a>
</Link>
</p>
) : null} ) : null}
</section> </section>
<section className={styles.news}> <section className={styles.news}>
<h1 className={styles.cardsHeading}>News</h1> <h1 className={styles.cardsHeading}>News</h1>
<p className={styles.cardsDescription}> <p className={styles.cardsDescription}>
Updates from our execs! <br /> Updates from our execs! <br />
See past news here See past news{" "}
<Link href="/news/archive">
<a title="News Archive">here</a>
</Link>
</p> </p>
<hr className={styles.cardsDividingLine} /> <hr className={styles.cardsDividingLine} />
{props.news.length > 0 ? ( {
<NewsCard <NewsCard
{...props.news[0].metadata} {...props.news.metadata}
date={new Date(props.news[0].metadata.date)} date={new Date(props.news.metadata.date)}
> >
<MDXRemote {...props.news[0].content} /> <MDXRemote {...props.news.content} />
</NewsCard> </NewsCard>
) : ( }
<p>There is no news right now. Please check back later!</p>
)}
</section> </section>
</div> </div>
</div> </div>
@ -109,10 +115,14 @@ Home.Layout = function HomeLayout(props: { children: React.ReactNode }) {
return <div className={styles.page}>{props.children}</div>; return <div className={styles.page}>{props.children}</div>;
}; };
type Params = ParsedUrlQuery; export const getStaticProps: GetStaticProps<Props> = async () => {
const upcomingEvents = await getUpcomingEvents();
export const getStaticProps: GetStaticProps<Props, Params> = async () => { const recentNews = await getRecentNews();
const events = await getUpcomingEvents(); return {
const news = await getRecentNews(); props: {
return { props: { events, news } }; numberOfEvents: upcomingEvents.length,
events: upcomingEvents.slice(0, 2),
news: recentNews[0],
},
};
}; };