"use client"; import { useEffect, useState, useCallback } from "react"; import { usePathname } from "next/navigation"; import Image from "next/image"; import Link from "next/link"; import SessionCoverImage from "./SessionCoverImage"; import AddressLink from "./AddressLink"; import { getSessionsWithDates, MOCK_JOINERS_SESSION1 } from "@/config/home.config"; import { mergeJoiners, getUniqueDbCount } from "@/app/lib/joiners"; import { useXhClickOpener } from "@/app/hooks/useXhClickOpener"; function HeroAvatarItem({ joiner }: { joiner: { name?: string; nickname?: string; avatar?: string; xiaohongshu_url?: string } }) { const nickname = ("name" in joiner ? joiner.name : joiner.nickname) ?? ""; const avatar = joiner.avatar; const xhUrl = joiner.xiaohongshu_url; const showAvatar = avatar && avatar.length > 0; const handleClick = useXhClickOpener(xhUrl); return ( {showAvatar ? ( ) : ( {nickname.slice(0, 1) || "?"} )} ); } export default function HeroSection() { const sessions = getSessionsWithDates(); const mainSession = sessions[0]; const [stats, setStats] = useState<{ count: number; joiners: { nickname: string; avatar?: string; xiaohongshu_url?: string }[] } | null>(null); const pathname = usePathname(); const fetchStats = useCallback(() => { if (!mainSession) return; fetch(`/api/join/stats?_=${Date.now()}`, { cache: "no-store" }) .then((r) => r.json()) .then((d) => d?.stats?.[mainSession.id] && setStats(d.stats[mainSession.id])) .catch(() => {}); }, [mainSession?.id]); useEffect(() => { if (!mainSession || pathname !== "/") return; fetchStats(); const onVisible = () => fetchStats(); const onPageShow = (e: PageTransitionEvent) => { if (e.persisted) fetchStats(); }; document.addEventListener("visibilitychange", onVisible); window.addEventListener("pageshow", onPageShow); return () => { document.removeEventListener("visibilitychange", onVisible); window.removeEventListener("pageshow", onPageShow); }; }, [pathname, mainSession?.id, fetchStats]); return ( 周末2小时 认识更多有趣的人 深圳 · 4–8 人小圈子 公开场地 · 填表申请 · 茶歇 · 不尬聊 立即报名 {mainSession && ( {/* 图片区 - 左侧/上方 */} {mainSession.coverImage ? ( ) : ( ☕ )} {["周末", "4人成行"].map((tag) => ( {tag} ))} {/* 内容区 - 右侧/下方 */} 本周场次 {mainSession.title} 日期 {mainSession.date} 时间 {mainSession.time} 地点 {mergeJoiners(MOCK_JOINERS_SESSION1, stats?.joiners).map((j, i) => ( ))} {3 + getUniqueDbCount(stats?.joiners)} 人已报名 报名 → )} ); }
深圳 · 4–8 人小圈子
公开场地 · 填表申请 · 茶歇 · 不尬聊
本周场次
日期 {mainSession.date}
时间 {mainSession.time}
地点