diff --git a/dash/src/app/(nav)/archive/[year]/[key]/page.tsx b/dash/src/app/(nav)/archive/[year]/[key]/page.tsx new file mode 100644 index 00000000..9d41e4eb --- /dev/null +++ b/dash/src/app/(nav)/archive/[year]/[key]/page.tsx @@ -0,0 +1,78 @@ +import { utc } from "moment"; +import Link from "next/link"; + +import type { Meeting } from "@/types/archive.type"; + +import { env } from "@/env"; + +const getArchiveForYear = async (year: string): Promise => { + try { + const nextReq = await fetch(`${env.API_URL}/api/archive/${year}`, { + next: { revalidate: 60 * 60 * 4 }, + }); + const schedule: Meeting[] = await nextReq.json(); + return schedule; + } catch { + return null; + } +}; + +type Prams = Promise<{ + key: string; + year: string; +}>; + +type Props = { + params: Prams; +}; + +export default async function MeetingDetailsPage({ params }: Props) { + const { key, year } = await params; + + const archive = await getArchiveForYear(year); + const meeting = archive?.find((meet) => meet.key.toString() === key); + + if (!meeting) { + return ( +
+
+

No meeting details found for key: {key}

+
+
+ ); + } + + return ( +
+ +
← Back to Year Overview
+ + +
+

{meeting.officialName}

+

{meeting.country.name}

+

{meeting.location}

+

+ {utc(meeting.sessions[0].startDate).local().format("MMMM D, YYYY")} -{" "} + {utc(meeting.sessions[meeting.sessions.length - 1].endDate) + .local() + .format("MMMM D, YYYY")} +

+
+

Sessions

+
    + {meeting.sessions.map((session, index) => ( +
  • +

    {session.name}

    +

    {utc(session.startDate).local().format("MMMM D, YYYY")}

    +

    + {utc(session.startDate).local().format("HH:mm")} -{utc(session.endDate).local().format("HH:mm")} +

    +
  • + ))} +
+
+
+
+ ); +} diff --git a/dash/src/app/(nav)/archive/[year]/page.tsx b/dash/src/app/(nav)/archive/[year]/page.tsx new file mode 100644 index 00000000..6c510325 --- /dev/null +++ b/dash/src/app/(nav)/archive/[year]/page.tsx @@ -0,0 +1,91 @@ +import { notFound } from "next/navigation"; +import { connection } from "next/server"; + +import { env } from "@/env"; + +import Meeting from "../meeting"; +import type { Meeting as MeetingType } from "@/types/archive.type"; +import { Suspense } from "react"; + +const getArchiveForYear = async (year: string) => { + await connection(); + + try { + const nextReq = await fetch(`${env.API_URL}/api/archive/${year}`, { + cache: "no-store", + }); + const schedule: MeetingType[] = await nextReq.json(); + return schedule; + } catch (e) { + console.error("error fetching next round", e); + return null; + } +}; + +export default async function ArchivePage({ params }: { params: Promise<{ year: string }> }) { + const { year } = await params; + + if (year < "2018") notFound(); + + return ( +
+
+

{year} Archive

+

All times are local time

+
+ + }> + + +
+ ); +} + +const Meetings = async ({ year }: { year: string }) => { + const meetings = await getArchiveForYear(year); + + if (!meetings) { + return ( +
+

No archive data found for {year}

+
+ ); + } + + return ( + + ); +}; + +const Loading = () => { + return ( + + ); +}; + +const MeetingLoading = () => { + return ( +
+
+
+ +
+
+
+
+
+ +
+ +
+
+ ); +}; diff --git a/dash/src/app/(nav)/archive/meeting.tsx b/dash/src/app/(nav)/archive/meeting.tsx new file mode 100644 index 00000000..2180c30e --- /dev/null +++ b/dash/src/app/(nav)/archive/meeting.tsx @@ -0,0 +1,35 @@ +import Link from "next/link"; +import { utc } from "moment"; + +import type { Meeting } from "@/types/archive.type"; + +import { getCountryCode } from "@/lib/country"; + +import Flag from "@/components/Flag"; + +type Props = { + meeting: Meeting; + year: string; +}; + +export default function Meeting({ meeting, year }: Props) { + const start = meeting.sessions[0].startDate; + const end = meeting.sessions[meeting.sessions.length - 1].endDate; + + return ( + +
+ +

{meeting.officialName}

+
+ +

+ {meeting.country.name} - {meeting.location} +

+ +

+ {utc(start).local().format("MMMM D, YYYY")} - {utc(end).local().format("MMMM D, YYYY")} +

+ + ); +} diff --git a/dash/src/app/(nav)/archive/page.tsx b/dash/src/app/(nav)/archive/page.tsx new file mode 100644 index 00000000..1264b241 --- /dev/null +++ b/dash/src/app/(nav)/archive/page.tsx @@ -0,0 +1,6 @@ +import { redirect } from "next/navigation"; + +export default function ArchiveRedirectPage() { + const currentYear = new Date().getFullYear(); + redirect(`/archive/${currentYear}`); +} diff --git a/dash/src/app/(nav)/layout.tsx b/dash/src/app/(nav)/layout.tsx index f9eb3732..7ca71c94 100644 --- a/dash/src/app/(nav)/layout.tsx +++ b/dash/src/app/(nav)/layout.tsx @@ -12,6 +12,8 @@ type Props = { }; export default function Layout({ children }: Props) { + const year = new Date().getFullYear(); + return ( <>