'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)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -5,12 +5,16 @@ import { Link, useLocale, useTranslation } from "@/i18n/navigation";
|
||||
import { apiFetch } from "@/app/lib/api-client";
|
||||
import {
|
||||
buildMeetupChatUrl,
|
||||
buildMeetupLivePath,
|
||||
buildMiroTalkJoinUrl,
|
||||
canAccessMeetup,
|
||||
DEFAULT_ONLINE_FEATURES,
|
||||
featureLabels,
|
||||
getLoungeServerLabel,
|
||||
getMiroTalkServerLabel,
|
||||
isLiveMeetup,
|
||||
MIROTALK_PROVIDER_LABEL,
|
||||
viewerDisplayName,
|
||||
type MeetupAccessLevel,
|
||||
type MeetupMode,
|
||||
WEB_CHAT_PROVIDER_LABEL,
|
||||
@@ -41,6 +45,7 @@ interface Meetup {
|
||||
accessLevel: MeetupAccessLevel;
|
||||
meetingProvider: string;
|
||||
mirotalkRoom: string;
|
||||
loungeChannel: string;
|
||||
meetingUrl: string;
|
||||
replayUrl: string;
|
||||
features: string[];
|
||||
@@ -66,6 +71,31 @@ interface ViewerState {
|
||||
type ModeFilter = "all" | MeetupMode;
|
||||
|
||||
const allMeetups: Meetup[] = [
|
||||
{
|
||||
id: "live-june-8",
|
||||
city: "线上",
|
||||
emoji: "🎙️",
|
||||
date: "2026-06-08",
|
||||
time: "19:00",
|
||||
venue: "NomadCNA 线上圆桌",
|
||||
address: "视频会议 + Web 群聊 · 社区账户直通",
|
||||
description: "今晚 19:00 线上圆桌:远程工作节奏、旅居城市选择与社区协作。登录后昵称自动带入视频房,群聊进入活动频道。",
|
||||
rsvpCount: 42,
|
||||
gradientFrom: "#ff4d4f",
|
||||
gradientTo: "#7c3aed",
|
||||
attendees: [{ name: "林晓", photo: avatarForIndex(0) }, { name: "张明", photo: avatarForIndex(4) }, { name: "陈静", photo: avatarForIndex(2) }],
|
||||
isUpcoming: true,
|
||||
mode: "online",
|
||||
accessLevel: "public",
|
||||
meetingProvider: "mirotalk",
|
||||
mirotalkRoom: "nomadcna-20260608-online-roundtable",
|
||||
loungeChannel: "#nomadcna-20260608",
|
||||
meetingUrl: "",
|
||||
replayUrl: "",
|
||||
features: DEFAULT_ONLINE_FEATURES,
|
||||
maxAttendees: 120,
|
||||
organizer: "NomadCNA",
|
||||
},
|
||||
{
|
||||
id: "online-1",
|
||||
city: "线上",
|
||||
@@ -84,6 +114,7 @@ const allMeetups: Meetup[] = [
|
||||
accessLevel: "members",
|
||||
meetingProvider: "mirotalk",
|
||||
mirotalkRoom: "nomadcna-remote-work-open-office",
|
||||
loungeChannel: "#online-events",
|
||||
meetingUrl: "",
|
||||
replayUrl: "",
|
||||
features: DEFAULT_ONLINE_FEATURES,
|
||||
@@ -326,6 +357,7 @@ const copy = {
|
||||
max: "上限",
|
||||
details: "查看详情",
|
||||
joinRoom: "进入视频房",
|
||||
enterLiveRoom: "进入活动间",
|
||||
joinChat: "进入群聊",
|
||||
embedRoom: "在当前页打开",
|
||||
closeEmbed: "收起房间",
|
||||
@@ -355,7 +387,8 @@ const copy = {
|
||||
emptyUpcoming: "暂无即将举办的活动",
|
||||
emptyPrevious: "暂无往期活动记录",
|
||||
authPublicHint: "公开活动可直接打开,登录后会使用你的社区身份进入房间。",
|
||||
chatHint: "群聊默认进入 #nomadcna 与 #online-events。",
|
||||
chatHint: "活动间内嵌 MiroTalk 视频 + The Lounge 群聊,登录后昵称自动带入视频房。",
|
||||
chatChannel: "活动频道",
|
||||
},
|
||||
en: {
|
||||
center: "Events Center",
|
||||
@@ -372,6 +405,7 @@ const copy = {
|
||||
max: "Limit",
|
||||
details: "Details",
|
||||
joinRoom: "Join video room",
|
||||
enterLiveRoom: "Enter live room",
|
||||
joinChat: "Join group chat",
|
||||
embedRoom: "Open inline",
|
||||
closeEmbed: "Hide room",
|
||||
@@ -401,7 +435,8 @@ const copy = {
|
||||
emptyUpcoming: "No upcoming events yet",
|
||||
emptyPrevious: "No past events yet",
|
||||
authPublicHint: "Public events open directly. After login, your community identity is used in the room.",
|
||||
chatHint: "Chat opens with #nomadcna and #online-events by default.",
|
||||
chatHint: "The live room embeds MiroTalk video and The Lounge chat. Your community display name is passed into the video room.",
|
||||
chatChannel: "Event channel",
|
||||
},
|
||||
};
|
||||
|
||||
@@ -451,6 +486,7 @@ function mapMeetup(item: Partial<Meetup> & { id: string; status?: string }): Mee
|
||||
accessLevel: toAccessLevel(item.accessLevel),
|
||||
meetingProvider: item.meetingProvider || (mode === "offline" ? "" : "mirotalk"),
|
||||
mirotalkRoom: item.mirotalkRoom || "",
|
||||
loungeChannel: item.loungeChannel || "",
|
||||
meetingUrl: item.meetingUrl || "",
|
||||
replayUrl: item.replayUrl || "",
|
||||
features: Array.isArray(item.features) ? item.features.map(String) : mode === "offline" ? [] : DEFAULT_ONLINE_FEATURES,
|
||||
@@ -474,25 +510,6 @@ function accessLabel(accessLevel: MeetupAccessLevel, locale: string) {
|
||||
}[accessLevel];
|
||||
}
|
||||
|
||||
function viewerDisplayName(viewer: ViewerState): string {
|
||||
const name = String(viewer.user?.name || "").trim();
|
||||
if (name) return name;
|
||||
const email = String(viewer.user?.email || "").trim();
|
||||
return email ? email.split("@")[0] : "NomadCNA";
|
||||
}
|
||||
|
||||
function isHostViewer(viewer: ViewerState): boolean {
|
||||
const role = String(viewer.user?.role || viewer.user?.["memberRole"] || viewer.user?.["siteRole"] || "").toLowerCase();
|
||||
return ["admin", "owner", "host", "organizer", "moderator"].includes(role);
|
||||
}
|
||||
|
||||
function canAccessMeetup(meetup: Meetup, viewer: ViewerState): boolean {
|
||||
if (meetup.accessLevel === "public") return true;
|
||||
if (meetup.accessLevel === "members") return Boolean(viewer.user);
|
||||
if (meetup.accessLevel === "vip") return Boolean(viewer.vip || viewer.user?.vip);
|
||||
return isHostViewer(viewer);
|
||||
}
|
||||
|
||||
function lockedReason(meetup: Meetup, locale: string) {
|
||||
const c = getCopy(locale);
|
||||
if (meetup.accessLevel === "members") return c.loginRequired;
|
||||
@@ -585,10 +602,11 @@ function MeetupDetailModal({ meetup, locale, viewer, onClose }: { meetup: Meetup
|
||||
const [embedOpen, setEmbedOpen] = useState(false);
|
||||
const canJoin = canAccessMeetup(meetup, viewer);
|
||||
const joinUrl = buildMiroTalkJoinUrl(meetup, viewerDisplayName(viewer));
|
||||
const chatUrl = buildMeetupChatUrl();
|
||||
const chatUrl = buildMeetupChatUrl(meetup);
|
||||
const livePath = buildMeetupLivePath(meetup.id);
|
||||
const mirotalkServer = getMiroTalkServerLabel();
|
||||
const loungeServer = getLoungeServerLabel();
|
||||
const isVideoEvent = meetup.mode !== "offline";
|
||||
const isVideoEvent = isLiveMeetup(meetup);
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-[9999] overflow-y-auto">
|
||||
@@ -645,14 +663,21 @@ function MeetupDetailModal({ meetup, locale, viewer, onClose }: { meetup: Meetup
|
||||
<p className="mt-2 text-xs font-semibold uppercase tracking-wide text-emerald-700 dark:text-emerald-300">{c.chatService}</p>
|
||||
<p className="mt-1 text-sm font-semibold text-gray-900 dark:text-gray-100">{WEB_CHAT_PROVIDER_LABEL}</p>
|
||||
<p className="mt-1 break-all text-xs text-gray-500 dark:text-gray-400">{c.chatServer}: {loungeServer}</p>
|
||||
<p className="mt-1 break-all text-xs text-gray-500 dark:text-gray-400">{c.chatChannel}: {meetup.loungeChannel || `#${meetup.mirotalkRoom || meetup.id}`}</p>
|
||||
</div>
|
||||
{canJoin ? (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Link
|
||||
href={livePath}
|
||||
className="inline-flex min-h-10 cursor-pointer items-center justify-center rounded-lg bg-[#ff4d4f] px-4 py-2 text-sm font-semibold text-white transition hover:bg-[#ff7a45] focus:outline-none focus-visible:ring-2 focus-visible:ring-[#ff4d4f]/40"
|
||||
>
|
||||
{c.enterLiveRoom}
|
||||
</Link>
|
||||
<a
|
||||
href={joinUrl}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="inline-flex min-h-10 cursor-pointer items-center justify-center rounded-lg bg-[#ff4d4f] px-4 py-2 text-sm font-semibold text-white transition hover:bg-[#ff7a45] focus:outline-none focus-visible:ring-2 focus-visible:ring-[#ff4d4f]/40"
|
||||
className="inline-flex min-h-10 cursor-pointer items-center justify-center rounded-lg border border-emerald-200 bg-white px-4 py-2 text-sm font-semibold text-emerald-700 transition hover:bg-emerald-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400 dark:border-emerald-800 dark:bg-gray-900 dark:text-emerald-300 dark:hover:bg-emerald-950/50"
|
||||
>
|
||||
{c.joinRoom}
|
||||
</a>
|
||||
|
||||
Reference in New Issue
Block a user