"use client"; import { useEffect, useState } from "react"; import { useLocale } from "@/i18n/navigation"; import { useParams } from "next/navigation"; import EventLiveRoom from "@/app/components/meetups/EventLiveRoom"; import { apiFetch } from "@/app/lib/api-client"; import type { MeetupSession } from "@/app/lib/meetups"; interface MeetupRecord { id: string; city: string; emoji: string; venue: string; date: string; time: string; organizer: string; gradientFrom: string; gradientTo: string; mode: string; } const weekdays = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]; function formatMeetupDate(dateStr: string, time: string, locale: string): string { const normalizedDate = dateStr.includes("T") || dateStr.includes(" ") ? dateStr.slice(0, 10) : dateStr; const d = new Date(`${normalizedDate}T${time}`); if (Number.isNaN(d.getTime())) return `${normalizedDate} ${time.slice(0, 5)}`; if (locale !== "zh") { return d.toLocaleString(undefined, { weekday: "long", year: "numeric", month: "long", day: "numeric", hour: "2-digit", minute: "2-digit" }); } const weekday = weekdays[d.getDay()]; return `${weekday}, ${d.getFullYear()}年${d.getMonth() + 1}月${d.getDate()}日, ${time.slice(0, 5)}`; } export default function MeetupLivePage() { const locale = useLocale(); const params = useParams<{ id: string }>(); const meetupId = String(params?.id || ""); const [meetup, setMeetup] = useState(null); const [session, setSession] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(""); useEffect(() => { if (!meetupId) return; let cancelled = false; setLoading(true); apiFetch<{ meetup: MeetupRecord; session: MeetupSession }>(`/api/meetups/${meetupId}/session`) .then((data) => { if (cancelled) return; setMeetup(data.meetup); setSession(data.session); setError(""); }) .catch((err: Error) => { if (!cancelled) setError(err.message || "加载失败"); }) .finally(() => { if (!cancelled) setLoading(false); }); return () => { cancelled = true; }; }, [meetupId]); if (loading) { return (
{locale === "zh" ? "正在连接活动间…" : "Connecting to live room…"}
); } if (error || !meetup || !session) { return (

{error || (locale === "zh" ? "活动不存在" : "Event not found")}

); } return ( ); }