's'
This commit is contained in:
91
app/[locale]/meetups/[id]/live/page.tsx
Normal file
91
app/[locale]/meetups/[id]/live/page.tsx
Normal file
@@ -0,0 +1,91 @@
|
||||
"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<MeetupRecord | null>(null);
|
||||
const [session, setSession] = useState<MeetupSession | null>(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 (
|
||||
<div className="flex min-h-screen items-center justify-center bg-[#0b1220] text-white/70">
|
||||
{locale === "zh" ? "正在连接活动间…" : "Connecting to live room…"}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (error || !meetup || !session) {
|
||||
return (
|
||||
<div className="flex min-h-screen flex-col items-center justify-center bg-[#0b1220] px-4 text-center text-white">
|
||||
<p className="text-lg font-semibold">{error || (locale === "zh" ? "活动不存在" : "Event not found")}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<EventLiveRoom
|
||||
locale={locale}
|
||||
meetup={meetup}
|
||||
session={session}
|
||||
formattedDate={formatMeetupDate(meetup.date, meetup.time, locale)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user