PR fixes
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Aditya Thakral 2021-08-23 22:13:02 -04:00
parent 24885e5185
commit 2abc7e75c1
2 changed files with 49 additions and 24 deletions

View File

@ -3,6 +3,11 @@
margin-bottom: calc(60rem / 16); margin-bottom: calc(60rem / 16);
} }
.main > h2 {
padding-bottom: 1rem;
border-bottom: 1px solid var(--primary-heading);
}
@media only screen and (max-width: calc(768rem / 16)) { @media only screen and (max-width: calc(768rem / 16)) {
.main { .main {
margin-top: calc(60rem / 16); margin-top: calc(60rem / 16);

View File

@ -14,13 +14,14 @@ import {
Event, Event,
} from "@/lib/events"; } from "@/lib/events";
import styles from "./term.module.css"; import styles from "./index.module.css";
interface Props { interface Props {
term: string; term: string;
year: string; year: string;
pastEvents: Event[]; pastEvents: Event[];
futureEvents: Event[]; futureEvents: Event[];
currentTerm: boolean;
} }
export default function Term(props: Props) { export default function Term(props: Props) {
@ -31,8 +32,7 @@ export default function Term(props: Props) {
<div className={styles.main}> <div className={styles.main}>
{hasFutureEvents && ( {hasFutureEvents && (
<> <>
<h2>Upcoming Events:</h2> <h2>Upcoming Events</h2>
<hr />
<div className={styles.miniEventCards}> <div className={styles.miniEventCards}>
{props.futureEvents.map(({ content, metadata }) => ( {props.futureEvents.map(({ content, metadata }) => (
<EventCard <EventCard
@ -46,24 +46,16 @@ export default function Term(props: Props) {
</div> </div>
</> </>
)} )}
{hasFutureEvents && hasPastEvents && ( {hasPastEvents && props.currentTerm && <h2>Past Events</h2>}
<> {hasPastEvents && !props.currentTerm && (
<h2>Past Events:</h2> <h2>
<hr /> Events Archive:
</> <span className={styles.blue}>
)} {` ${props.term.charAt(0).toUpperCase()}${props.term.slice(1)} ${
{!hasFutureEvents && ( props.year
<> }`}
<h2> </span>
Events Archive: </h2>
<span className={styles.blue}>
{` ${props.term.charAt(0).toUpperCase()}${props.term.slice(1)} ${
props.year
}`}
</span>
</h2>
<hr />
</>
)} )}
<div className={styles.miniEventCards}> <div className={styles.miniEventCards}>
{props.pastEvents.map(({ content, metadata }) => ( {props.pastEvents.map(({ content, metadata }) => (
@ -101,20 +93,23 @@ export const getStaticProps: GetStaticProps<Props, Params> = async (
new Date(a.metadata.date).getTime() - new Date(b.metadata.date).getTime() new Date(a.metadata.date).getTime() - new Date(b.metadata.date).getTime()
); );
const pastEvents = events.filter( const pastEvents = events
(event) => new Date(event.metadata.date).getTime() < Date.now() .filter((event) => new Date(event.metadata.date).getTime() < Date.now())
); .reverse();
const futureEvents = events.filter( const futureEvents = events.filter(
(event) => new Date(event.metadata.date).getTime() >= Date.now() (event) => new Date(event.metadata.date).getTime() >= Date.now()
); );
const current = getCurrentTerm();
return { return {
props: { props: {
term: term, term: term,
year: year, year: year,
pastEvents: pastEvents, pastEvents: pastEvents,
futureEvents: futureEvents, futureEvents: futureEvents,
currentTerm: term === current.term && year === current.year,
}, },
}; };
}; };
@ -137,3 +132,28 @@ export const getStaticPaths: GetStaticPaths<Params> = async () => {
fallback: false, fallback: false,
}; };
}; };
export function getCurrentTerm() {
const date = new Date();
let term = "";
const year = date.getUTCFullYear().toString();
if (
new Date(`${year}-01-01`).getTime() <= date.getTime() &&
date.getTime() <= new Date(`${year}-04-30`).getTime()
) {
term = "winter";
} else if (
new Date(`${year}-05-01`).getTime() <= date.getTime() &&
date.getTime() <= new Date(`${year}-08-31`).getTime()
) {
term = "spring";
} else if (
new Date(`${year}-09-01`).getTime() <= date.getTime() &&
date.getTime() <= new Date(`${year}-12-31`).getTime()
) {
term = "fall";
}
return { term, year };
}