From bd29b986c4c75ff3635181db3862ebeebe583052 Mon Sep 17 00:00:00 2001 From: Aditya Thakral Date: Fri, 27 Aug 2021 20:02:07 -0400 Subject: [PATCH 1/2] Add events archive Closes #117 --- .../ArchivePage.module.css | 0 components/ArchivePage.tsx | 47 +++++++++++++++++ pages/events/archive.tsx | 18 +++++++ pages/news/archive.tsx | 50 ++----------------- 4 files changed, 69 insertions(+), 46 deletions(-) rename pages/news/archive.module.css => components/ArchivePage.module.css (100%) create mode 100644 components/ArchivePage.tsx create mode 100644 pages/events/archive.tsx diff --git a/pages/news/archive.module.css b/components/ArchivePage.module.css similarity index 100% rename from pages/news/archive.module.css rename to components/ArchivePage.module.css diff --git a/components/ArchivePage.tsx b/components/ArchivePage.tsx new file mode 100644 index 00000000..73d5e7e7 --- /dev/null +++ b/components/ArchivePage.tsx @@ -0,0 +1,47 @@ +import React from "react"; + +import { Link } from "@/components/Link"; +import { + ShapesConfig, + GetShapesConfig, + defaultGetShapesConfig, +} from "@/components/ShapesBackground"; + +import styles from "./ArchivePage.module.css"; + +export interface Props { + type: "news" | "events"; + items: { + year: string; + terms: string[]; + }[]; +} + +export function ArchivePage({ items, type }: Props) { + return ( +
+

{capitalize(type)} Archive

+ +
+ ); +} + +ArchivePage.getShapesConfig = ((width, height) => { + return window.innerWidth <= 768 + ? ({} as ShapesConfig) + : defaultGetShapesConfig(width, height); +}) as GetShapesConfig; + +function capitalize(str: string) { + return str.slice(0, 1).toUpperCase() + str.slice(1); +} diff --git a/pages/events/archive.tsx b/pages/events/archive.tsx new file mode 100644 index 00000000..9ae08a0d --- /dev/null +++ b/pages/events/archive.tsx @@ -0,0 +1,18 @@ +import { GetStaticProps } from "next"; + +import { ArchivePage, Props } from "@/components/ArchivePage"; +import { getEventTermsByYear, getEventYears } from "@/lib/events"; + +export default ArchivePage; + +export const getStaticProps: GetStaticProps = async () => { + const years = (await getEventYears()).reverse(); + const yearsWithTerms = await Promise.all( + years.map(async (year) => ({ + year, + terms: (await getEventTermsByYear(year)).reverse(), + })) + ); + + return { props: { items: yearsWithTerms, type: "events" } }; +}; diff --git a/pages/news/archive.tsx b/pages/news/archive.tsx index 9857618a..e7dcf63e 100644 --- a/pages/news/archive.tsx +++ b/pages/news/archive.tsx @@ -1,47 +1,9 @@ -import { getNewsTermsByYear, getNewsYears } from "lib/news"; import { GetStaticProps } from "next"; -import React from "react"; -import { Link } from "@/components/Link"; -import { - ShapesConfig, - GetShapesConfig, - defaultGetShapesConfig, -} from "@/components/ShapesBackground"; +import { ArchivePage, Props } from "@/components/ArchivePage"; +import { getNewsTermsByYear, getNewsYears } from "@/lib/news"; -import styles from "./archive.module.css"; - -interface Props { - items: { - year: string; - terms: string[]; - }[]; -} - -export default function NewsArchive({ items }: Props) { - return ( -
-

News Archive

-
    - {items.map(({ year, terms }) => - terms.map((term) => ( -
  • - - {capitalize(term)} {year} - -
  • - )) - )} -
-
- ); -} - -NewsArchive.getShapesConfig = ((width, height) => { - return window.innerWidth <= 768 - ? ({} as ShapesConfig) - : defaultGetShapesConfig(width, height); -}) as GetShapesConfig; +export default ArchivePage; export const getStaticProps: GetStaticProps = async () => { const years = (await getNewsYears()).reverse(); @@ -52,9 +14,5 @@ export const getStaticProps: GetStaticProps = async () => { })) ); - return { props: { items: yearsWithTerms } }; + return { props: { items: yearsWithTerms, type: "news" } }; }; - -function capitalize(str: string) { - return str.slice(0, 1).toUpperCase() + str.slice(1); -} -- 2.30.2 From 98717fafbc937e5e443ce635f867a2dd4cb6d096 Mon Sep 17 00:00:00 2001 From: Aditya Thakral Date: Sat, 28 Aug 2021 15:41:52 -0400 Subject: [PATCH 2/2] Address PR comments --- components/ArchivePage.module.css | 5 +++++ components/ArchivePage.tsx | 5 +---- pages/events/[year]/[term]/index.tsx | 5 +---- pages/news/[year]/[term].tsx | 5 +---- tsconfig.json | 3 ++- utils.ts | 3 +++ 6 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 utils.ts diff --git a/components/ArchivePage.module.css b/components/ArchivePage.module.css index a05f7b45..88b5b58e 100644 --- a/components/ArchivePage.module.css +++ b/components/ArchivePage.module.css @@ -2,6 +2,11 @@ margin-bottom: calc(40rem / 16); } +.page > h1 { + border-bottom: calc(1rem / 16) solid var(--primary-heading); + padding-bottom: 1rem; +} + .list { list-style: none; padding: 0; diff --git a/components/ArchivePage.tsx b/components/ArchivePage.tsx index 73d5e7e7..bc1e1be7 100644 --- a/components/ArchivePage.tsx +++ b/components/ArchivePage.tsx @@ -6,6 +6,7 @@ import { GetShapesConfig, defaultGetShapesConfig, } from "@/components/ShapesBackground"; +import { capitalize } from "@/utils"; import styles from "./ArchivePage.module.css"; @@ -41,7 +42,3 @@ ArchivePage.getShapesConfig = ((width, height) => { ? ({} as ShapesConfig) : defaultGetShapesConfig(width, height); }) as GetShapesConfig; - -function capitalize(str: string) { - return str.slice(0, 1).toUpperCase() + str.slice(1); -} diff --git a/pages/events/[year]/[term]/index.tsx b/pages/events/[year]/[term]/index.tsx index f8b9f1fd..6387d779 100644 --- a/pages/events/[year]/[term]/index.tsx +++ b/pages/events/[year]/[term]/index.tsx @@ -13,6 +13,7 @@ import { getEventYears, getEventTermsByYear, } from "@/lib/events"; +import { capitalize } from "@/utils"; import styles from "./index.module.css"; @@ -154,7 +155,3 @@ export const getStaticPaths: GetStaticPaths = async () => { fallback: false, }; }; - -function capitalize(str: string) { - return str.slice(0, 1).toUpperCase() + str.slice(1); -} diff --git a/pages/news/[year]/[term].tsx b/pages/news/[year]/[term].tsx index 203165d1..b7f5ce8a 100644 --- a/pages/news/[year]/[term].tsx +++ b/pages/news/[year]/[term].tsx @@ -17,6 +17,7 @@ import { getNewsYears, News, } from "@/lib/news"; +import { capitalize } from "@/utils"; import styles from "./[term].module.css"; @@ -89,7 +90,3 @@ export const getStaticPaths: GetStaticPaths = async () => { fallback: false, }; }; - -function capitalize(str: string) { - return str.slice(0, 1).toUpperCase() + str.slice(1); -} diff --git a/tsconfig.json b/tsconfig.json index d886e684..ea06f1e2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,7 +23,8 @@ "paths": { "@/components/*": ["components/*"], "@/lib/*": ["lib/*"], - "@/hooks/*": ["hooks/*"] + "@/hooks/*": ["hooks/*"], + "@/utils": ["utils"] } }, "include": ["next-env.d.ts", "types.d.ts", "**/*.ts", "**/*.tsx"], diff --git a/utils.ts b/utils.ts new file mode 100644 index 00000000..40ef05aa --- /dev/null +++ b/utils.ts @@ -0,0 +1,3 @@ +export function capitalize(str: string) { + return str.slice(0, 1).toUpperCase() + str.slice(1); +} -- 2.30.2