import { Metadata } from "next"; import Link from "next/link"; import { notFound } from "next/navigation"; import { Navbar } from "@/components/layout/Navbar"; import { Footer } from "@/components/layout/Footer"; import { EventCard } from "@/components/events/EventCard"; import { ApiImage } from "@/components/shared/ApiImage"; import { CampusBadge } from "@/components/shared/CampusFilter"; import { FollowSeriesButton } from "@/components/events/FollowSeriesButton"; import { SeasonPassOffers } from "@/components/series/SeasonPassOffers"; import { Suspense } from "react"; import { apiFetch, apiFetchListForPrerender, ApiError } from "@/lib/api"; import { formatDateTimeRange } from "@/lib/date"; import { ArrowLeft, CalendarX, Layers } from "lucide-react"; import type { Event as FullEvent, SeasonPassView } from "@/types"; export const revalidate = 60; type Event = React.ComponentProps["event"] & { cashupStatus?: string; nextSession?: { startsAt: string } | null }; type PastEvent = { id: string; title: string; startDate: string; endDate: string; campus?: FullEvent["campus"] }; type Series = { id: string; name: string; slug: string; description: string | null; picture: string | null; past: PastEvent[]; passes?: SeasonPassView[] }; async function loadSeries(slug: string): Promise { try { return await apiFetch(`/api/series/by-slug/${encodeURIComponent(slug)}`, { nextOptions: { next: { revalidate } } }); } catch (e) { if (e instanceof ApiError && e.status === 404) return null; throw e; } } export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise { const { slug } = await params; const series = await loadSeries(slug); if (!series) return {}; return { title: series.name, description: series.description || `Every ${series.name} event, past and upcoming.`, alternates: { canonical: `/series/${series.slug}` }, }; } /** A series' page: what it is, the upcoming events in it (any campus), and past ones. */ export default async function SeriesPage({ params }: { params: Promise<{ slug: string }> }) { const { slug } = await params; const series = await loadSeries(slug); if (!series) notFound(); const events = await apiFetchListForPrerender(`/api/events?series=${encodeURIComponent(series.slug)}`, { nextOptions: { next: { revalidate } } }); const now = Date.now(); const upcoming = (events || []) .filter(e => e.cashupStatus !== "closed" && new Date(e.endDate || e.startDate).getTime() > now) .sort((a, b) => new Date(a.nextSession?.startsAt || a.startDate).getTime() - new Date(b.nextSession?.startsAt || b.startDate).getTime()); return (
All events
{series.picture && }

Series

{series.name}

{series.description &&

{series.description}

}

Coming up

{upcoming.length === 0 ? (

Nothing planned yet — follow the series to hear when the next one is out.

) : (
{upcoming.map(event => )}
)} {series.past.length > 0 && ( <>

Past events

    {series.past.map(e => (
  • {e.title} {formatDateTimeRange(e.startDate, e.endDate)}
  • ))}
)}
); }