diff --git a/app/api/events/route.ts b/app/api/events/route.ts index c8bf166..47cbf06 100644 --- a/app/api/events/route.ts +++ b/app/api/events/route.ts @@ -3,7 +3,12 @@ import { NextResponse } from "next/server"; import { prisma } from "@/lib/prisma"; export async function GET() { + const now = new Date(); + const events = await prisma.event.findMany({ + where: { + startAt: { gte: now }, + }, orderBy: { startAt: "asc" }, }); diff --git a/app/events/page.tsx b/app/events/page.tsx index 14cc3ff..8557559 100644 --- a/app/events/page.tsx +++ b/app/events/page.tsx @@ -1,12 +1,61 @@ -import React from "react"; -import PublicLayout from '@/components/layout/PublicLayout'; +"use client"; + +import { useEffect, useState } from "react"; +import PublicLayout from "@/components/layout/PublicLayout"; + +type Event = { + id: string; + title?: string | null; + name?: string | null; + startAt: string; // ISO string coming from JSON + location?: string | null; +}; export default function EventsPage() { + const [events, setEvents] = useState(null); + + useEffect(() => { + async function load() { + const res = await fetch("/api/events"); + if (!res.ok) { + setEvents([]); + return; + } + const data = (await res.json()) as Event[]; + setEvents(data); + } + load(); + }, []); + + const items = events ?? []; + return ( -
-

Events

-

No events yet — this is a placeholder page so the navbar link doesn't 404.

+
+

Events

+

Upcoming events

+ + {events === null ? ( +
Loading…
+ ) : items.length === 0 ? ( +
+ No upcoming events right now. Check back soon. +
+ ) : ( +
    + {items.map((e) => ( +
  • +
    + {e.title ?? e.name ?? "Untitled event"} +
    +
    + {new Date(e.startAt).toLocaleString()} + {e.location ? ` • ${e.location}` : ""} +
    +
  • + ))} +
+ )}
);