"use client"; import React, { useEffect, useState } from "react"; type Event = { title: string; date: string; location?: string; signupUrl?: string; signups?: boolean | "soon" }; export function CalendarView() { const [events, setEvents] = useState([]); useEffect(() => { (async () => { try { const res = await fetch("/api/content?path=pt/competicoes/future.json"); const json = await res.json(); setEvents(json.events ?? []); } catch {} })(); }, []); // Parse DD/MM/YYYY format const parseDate = (dateStr: string) => { const parts = dateStr.split('/'); if (parts.length === 3) { return new Date(parseInt(parts[2]), parseInt(parts[1]) - 1, parseInt(parts[0])); } return new Date(dateStr); }; // Simple month grid from provided future events const byMonth = events.reduce>((acc, e) => { const month = parseDate(e.date).toLocaleString("pt-PT", { month: "long", year: "numeric" }); acc[month] ??= []; acc[month].push(e); return acc; }, {}); return (

Calendário

{Object.entries(byMonth).map(([m, items]) => (

{m}

    {items.map((e, idx) => (
  • {e.title} — {parseDate(e.date).toLocaleDateString("pt-PT")} {e.location && ({e.location})} {e.signups === true && ( )} {e.signups === false && (
    (Encerradas)
    )} {e.signups === "soon" && (
    (Em breve)
    )}
  • ))}
))}
); }