nomadro/src/modules/social/components/HomeClient.tsx
Eric 5271aabc98 Ship social selfie face-check, avatar UX by device, blog/admin, and notify polish.
Add InsightFace/OpenCV challenge upload, PC vs mobile capture branching, and fix avatar persistence into roster/profile pages.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-04 14:38:20 +08:00

655 lines
25 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { useEffect, useMemo, useState, type PointerEvent } from "react";
import Link from "next/link";
import SiteShell from "./SiteShell";
import JoinPayModal from "./JoinPayModal";
import AttractiveRoster from "./AttractiveRoster";
import ConnectionHero, { ConnectionWays } from "./ConnectionHero";
import FxBelt from "./FxBelt";
import SectionSpark from "./SectionSpark";
import CityDirectory from "./CityDirectory";
import SocialBrandLogo from "./SocialBrandLogo";
import SocialAvatar from "./SocialAvatar";
import {
ArrowUpRight,
BookOpen,
Heart,
Radio,
Sparkles,
} from "lucide-react";
import { TEAM_KIND_LABEL, SEED_EBOOKS, SEED_VIDEOS } from "@social/lib/seed";
import { resolveSocialCatalog } from "@social/lib/resolveCatalog";
import { socialPath } from "@social/lib/socialPath";
import { resolveSocialLandingCopy } from "@social/lib/landing";
import { useSocialI18n } from "@social/lib/useSocialI18n";
import { useAudienceRoster } from "@social/lib/useAudienceRoster";
import { useSocialConfig } from "./SocialExperience";
import { socialTx } from "@social/lib/socialTx";
import {
DEFAULT_X_HANDLE,
formatXHandle,
xProfileUrl,
} from "~/components/social-follow";
import { trackFollow } from "~/lib/analytics/track";
const DEFAULT_PROMO =
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4";
const ROLE_EMOJI: Record<string, string> = {
volunteer: "🙋",
parttime: "📝",
fulltime: "💼",
};
export default function HomeClient() {
const config = useSocialConfig();
const { locale, t } = useSocialI18n();
const roster = useAudienceRoster();
const [joinOpen, setJoinOpen] = useState(false);
const [activeSection, setActiveSection] = useState("people");
const promoUrl =
config.copy.socialPromoUrl?.trim() ||
(
config.modules?.social as { promoVideoUrl?: string } | undefined
)?.promoVideoUrl?.trim() ||
DEFAULT_PROMO;
const landingCopy = resolveSocialLandingCopy(config.copy, locale);
const PATH = t.homePath;
const catalog = useMemo(
() => resolveSocialCatalog(config.copy.socialCatalogs),
[config.copy.socialCatalogs],
);
const meetups = catalog.meetups;
const gigs = catalog.gigs;
// 封面必须是美女:女生优先,不够再用在线的人补
const datePreview = (() => {
const women = roster.filter((m) => m.gender === "f");
const rest = roster.filter((m) => m.gender !== "f" && m.online);
return [...women, ...rest].slice(0, 3);
})();
useEffect(() => {
const root = document.querySelector(".social-home");
if (!root) return;
const reveal = new IntersectionObserver(
(entries) =>
entries.forEach((e) => {
if (e.isIntersecting) {
e.target.classList.add("visible");
reveal.unobserve(e.target);
}
}),
{ threshold: 0.06, rootMargin: "0px 0px -24px 0px" },
);
const scan = () => {
root
.querySelectorAll(".reveal:not(.visible)")
.forEach((el) => reveal.observe(el));
};
scan();
root.setAttribute("data-home-motion", "ready");
const t = window.setTimeout(scan, 400);
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) setActiveSection(entry.target.id);
});
},
{ rootMargin: "-25% 0px -55% 0px", threshold: 0 },
);
root
.querySelectorAll("section[id]:not(#hero)")
.forEach((section) => observer.observe(section));
return () => {
window.clearTimeout(t);
reveal.disconnect();
observer.disconnect();
root.removeAttribute("data-home-motion");
};
}, []);
const onPanelPointerMove = (event: PointerEvent<HTMLDivElement>) => {
if (event.pointerType !== "mouse") return;
const panel = (event.target as Element).closest<HTMLElement>(
".social-panel",
);
if (!panel) return;
const rect = panel.getBoundingClientRect();
panel.style.setProperty("--spot-x", `${event.clientX - rect.left}px`);
panel.style.setProperty("--spot-y", `${event.clientY - rect.top}px`);
};
return (
<div
className="home-flow social-flow social-fx social-home"
onPointerMove={onPanelPointerMove}
>
<div className="social-fx-orbs" aria-hidden>
<i className="social-fx-orb o1" />
<i className="social-fx-orb o2" />
<i className="social-fx-orb o3" />
</div>
<SiteShell home onJoin={() => setJoinOpen(true)}>
<div className="connection-scroll-progress" aria-hidden="true" />
<main id="social-main">
<ConnectionHero
onJoin={() => setJoinOpen(true)}
promoUrl={promoUrl}
copy={landingCopy}
/>
<ConnectionWays copy={landingCopy} />
<nav className="social-path" aria-label={socialTx("本页导航")}>
<div className="container">
<div className="social-path-track reveal">
{PATH.map((p) => {
const external = "external" in p && p.external;
const href = external ? socialPath(p.href) : p.href;
if (external) {
return (
<Link
key={p.href}
href={href}
className="social-path-link"
>
<span className="social-path-emoji" aria-hidden>
{p.emoji}
</span>
{p.label}
</Link>
);
}
return (
<a
key={p.href}
href={href}
className="social-path-link"
aria-current={
activeSection === p.href.slice(1)
? "location"
: undefined
}
>
<span className="social-path-emoji" aria-hidden>
{p.emoji}
</span>
{p.label}
</a>
);
})}
</div>
</div>
</nav>
<AttractiveRoster onJoin={() => setJoinOpen(true)} />
<section
className="section section-compact social-section-alt"
id="date"
aria-label={socialTx("认识一下")}
>
<div className="container">
<div className="social-date-hero reveal is-alive">
<div className="social-date-hero-copy">
<span className="section-tag">
<span>{socialTx("认识一下")}</span>
<span>{socialTx("左右滑")}</span>
</span>
<h2>
<span className="social-title-emoji" aria-hidden>
💕
</span>
{socialTx("一张一张认识新朋友")}
</h2>
<p>
{socialTx(
"像翻相册一样:不感兴趣就划走,想认识就留下。记在你这边,之后再决定要不要打招呼。",
)}
</p>
<ul className="social-date-hero-steps">
<li>
<em>←</em> {socialTx("划走")}
</li>
<li>
<em>→</em> {socialTx("想认识")}
</li>
<li>
<em>♥</em> {socialTx("稍后打招呼")}
</li>
</ul>
<div className="social-date-stage-acts">
<Link
className="btn btn-primary"
href={socialPath("/date")}
>
{socialTx("开始认识")}
<ArrowUpRight size={16} />
</Link>
<Link
className="btn btn-ghost"
href={socialPath("/people")}
>
{socialTx("先浏览大家")}
</Link>
</div>
</div>
<Link
href={socialPath("/date")}
className="social-date-hero-deck"
aria-label={socialTx("开始认识")}
>
{datePreview.map((m, i) => (
<div
key={m.id}
className={`social-date-hero-card social-date-hero-card-${i}`}
style={{
["--i" as string]: i,
backgroundImage: `linear-gradient(180deg, transparent 35%, #0a0a0ef2 88%), url(${m.avatar})`,
}}
>
{m.online ? (
<span className="social-date-hero-online">{socialTx("在线")}</span>
) : null}
<div className="social-date-hero-meta">
<strong>
{m.name}
<small>{m.title}</small>
</strong>
<em>{m.city.split("·")[0].trim()}</em>
<p>{m.lookingFor}</p>
<div className="social-date-card-tags">
{m.tags.slice(0, 2).map((t) => (
<span key={t}>{t}</span>
))}
</div>
</div>
</div>
))}
<span className="social-date-hero-cta">
<Heart size={14} /> {socialTx("点这里开始滑")}
</span>
</Link>
</div>
</div>
</section>
<FxBelt />
<section
className="section section-compact social-section-alt"
id="meetup"
aria-label={socialTx("开视频聊聊")}
>
<div className="container">
<div className="section-header reveal">
<SectionSpark label="meetup" />
<span className="section-tag">
<span>{socialTx("聊天群组")}</span>
<span>{socialTx("语音 · 视频")}</span>
</span>
<h2>
<span className="social-title-emoji" aria-hidden>
📡
</span>
{landingCopy.socialOnlineTitle}
</h2>
<p>
{socialTx(
"先进聊天群组热热身,再开语音或视频见面。「想参加」会先记在你这边。",
)}
</p>
</div>
<div className="social-panel-grid social-panel-grid-2">
{meetups.map((m, i) => (
<article
key={m.id}
className={`social-panel social-panel-fx reveal${i === 0 ? " is-accent" : ""}`}
style={{ ["--stagger" as string]: `${i * 80}ms` }}
>
<div
className="connection-meetup-art is-live"
aria-hidden="true"
>
<span className="connection-meetup-number">
0{i + 1}
</span>
<div className="connection-audio-bars">
{Array.from({ length: 14 }, (_, n) => (
<i
key={n}
style={{
height: `${12 + ((n * 17 + i * 13) % 48)}px`,
animationDelay: `${n * -0.15}s`,
}}
/>
))}
</div>
<div className="social-video-grid">
{roster.slice(i, i + 4).map((p) => (
<span key={p.id} className="social-video-tile">
<SocialAvatar src={p.avatar} size={36} lazy />
</span>
))}
</div>
<Radio size={22} strokeWidth={1.3} />
</div>
<div className="social-panel-meta">
<span>
{m.city === "Online" ? "群组 · 语音视频" : m.city}
</span>
<time>
{m.date} · {m.time}
</time>
</div>
<div className="social-meetup-faces" aria-hidden>
{roster.slice(i + 1, i + 5).map((p) => (
<SocialAvatar key={p.id} src={p.avatar} size={24} lazy />
))}
<em>+{6 + i} 想参加</em>
</div>
<h3>{m.title}</h3>
<p>{socialTx("群里打个招呼 → 开麦 / 开视频 → 认识新朋友")}</p>
<Link
className="btn btn-primary btn-sm"
href={socialPath(`/meetup/${m.id}`)}
>
{socialTx("进入聊聊")}
<ArrowUpRight size={14} />
</Link>
</article>
))}
</div>
<div className="social-section-actions reveal">
<Link href={socialPath("/meetup")} className="btn btn-ghost">
{socialTx("看看全部")}
</Link>
<Link href={socialPath("/chat")} className="btn btn-ghost">
{socialTx("文字群聊")}
</Link>
<button
type="button"
className="btn btn-ghost"
onClick={() => setJoinOpen(true)}
>
{t.joinCommunity}
</button>
</div>
</div>
</section>
<FxBelt />
<section
className="section section-compact"
id="cities"
aria-label={socialTx("同城见一面")}
>
<div className="container">
<div className="section-header reveal">
<SectionSpark label="cities" />
<span className="section-tag">
<span>{socialTx("挑一座城")}</span>
<span>{socialTx("再出来见面")}</span>
</span>
<h2>
<span className="social-title-emoji" aria-hidden>
🌆
</span>
{landingCopy.socialOfflineTitle}
</h2>
<p>
{socialTx(
"认识了、聊过之后,出来见一面会更自然。先挑一座城市,再找适合见面的咖啡馆。",
)}
</p>
</div>
<div className="social-map-teaser reveal">
<div className="social-map-teaser-copy">
<strong>地图摘要</strong>
<p>热门城市聚合 · 不暴露精确位置</p>
<div className="social-map-teaser-chips">
{["清迈", "巴厘岛", "大理", "里斯本", "成都"].map((name) => (
<span key={name}>{name}</span>
))}
</div>
</div>
<Link href={socialPath("/map")} className="btn btn-primary">
打开地图
<ArrowUpRight size={15} aria-hidden />
</Link>
</div>
<CityDirectory compact limit={8} />
<div className="social-section-actions reveal">
<Link href={socialPath("/places")} className="btn btn-primary">
逛城市
</Link>
<Link
href={socialPath("/places?tab=cafes")}
className="btn btn-ghost"
>
咖啡馆见面
</Link>
<Link href={socialPath("/people")} className="btn btn-ghost">
{socialTx("找同城的人")}
</Link>
</div>
</div>
</section>
<FxBelt />
<section
className="section section-compact social-section-alt"
id="team"
aria-label={socialTx("一起做点事")}
>
<div className="container">
<div className="section-header reveal">
<SectionSpark label="team" />
<span className="section-tag">
<span>{socialTx("找搭子")}</span>
<span>{socialTx("共创")}</span>
</span>
<h2>
<span className="social-title-emoji" aria-hidden>
🚀
</span>
{landingCopy.socialTeamTitle}
</h2>
<p>
{socialTx(
"有人在找帮手;也有人一起写小册、拍视频做共创。点卡片看看详情,合适再表达兴趣。",
)}
</p>
</div>
<div className="social-together-tabs reveal" role="tablist">
<Link
href={socialPath("/team")}
className="is-on"
role="tab"
aria-selected="true"
>
{socialTx("找搭子")}
</Link>
<Link href={socialPath("/ebook")} role="tab" aria-selected="false">
{socialTx("共创")}
</Link>
</div>
<div className="social-panel-grid social-panel-grid-3">
{gigs.slice(0, 3).map((g, i) => (
<Link
key={g.id}
href={socialPath(`/team#${g.id}`)}
className="social-panel social-panel-fx connection-team reveal is-clickable"
style={{ ["--stagger" as string]: `${i * 60}ms` }}
>
<div className="social-panel-ico" aria-hidden>
{ROLE_EMOJI[g.kind || "parttime"] || "📝"}
</div>
<div className="social-panel-meta">
<span>{TEAM_KIND_LABEL[g.kind || "parttime"]}</span>
<span>{g.remote ? "线上也能做" : "可以见面做"}</span>
</div>
<h3>{g.title}</h3>
<p>{g.pay}</p>
<div className="social-panel-foot">
{(g.tags || []).slice(0, 3).map((t) => (
<span key={t}>{t}</span>
))}
</div>
</Link>
))}
</div>
<div className="social-ugc-row reveal">
{SEED_EBOOKS.slice(0, 2).map((book) => (
<Link
key={book.id}
href={socialPath("/ebook")}
className="social-ugc-card"
>
<span className="social-ugc-ico" aria-hidden>
<BookOpen size={20} />
</span>
<div>
<em>{socialTx("共创 · 小册")}</em>
<strong>{book.title}</strong>
<p>{book.blurb}</p>
</div>
<ArrowUpRight size={16} />
</Link>
))}
{SEED_VIDEOS.slice(0, 2).map((vid) => (
<Link
key={vid.id}
href={socialPath("/videos")}
className="social-ugc-card is-video"
>
<span className="social-ugc-ico" aria-hidden>
{vid.coverEmoji}
</span>
<div>
<em>{socialTx("共创 · 视频")}</em>
<strong>{vid.title}</strong>
<p>
{vid.city} · {vid.minutes} 分钟
</p>
</div>
<ArrowUpRight size={16} />
</Link>
))}
</div>
<div className="social-section-actions reveal">
<Link href={socialPath("/team")} className="btn btn-ghost">
{socialTx("更多机会")}
</Link>
<Link href={socialPath("/ebook")} className="btn btn-ghost">
{socialTx("逛共创")}
</Link>
<button
type="button"
className="btn btn-ghost"
onClick={() => setJoinOpen(true)}
>
{t.joinCommunity}
</button>
</div>
</div>
</section>
<section
className="connection-invite container"
aria-label={t.joinCommunity}
>
<div className="connection-invite-orbit" aria-hidden="true">
<span />
<span />
<Sparkles size={52} strokeWidth={1} />
</div>
<div>
<span className="connection-eyebrow">{t.joinCommunity}</span>
<h2>{landingCopy.socialInviteTitle}</h2>
<p>{landingCopy.socialInviteLead}</p>
</div>
<button
type="button"
className="btn connection-join"
onClick={() => setJoinOpen(true)}
>
{socialTx("加入游民社区")} <ArrowUpRight size={19} />
</button>
</section>
</main>
<footer className="footer social-home-footer">
<div className="container">
<div className="footer-grid footer-grid-rings">
<div className="footer-brand">
<SocialBrandLogo />
<p>{socialTx("认识同频的人 · 开视频聊聊 · 出来见一面 · 一起做点事")}</p>
</div>
<div className="footer-links footer-links-primary">
<h4>{socialTx("认识人")}</h4>
<button
type="button"
className="social-footer-link"
onClick={() => setJoinOpen(true)}
>
{t.joinCommunity}
</button>
<Link href={socialPath("/people")}>{socialTx("想见的人")}</Link>
<Link href={socialPath("/date")}>{socialTx("认识一下")}</Link>
<Link href={socialPath("/meetup")}>{socialTx("开视频聊聊")}</Link>
<Link href={socialPath("/chat")}>{socialTx("大家聊天")}</Link>
</div>
<div className="footer-links footer-links-secondary">
<h4>{socialTx("见面 · 做事")}</h4>
<Link href={socialPath("/places")}>{socialTx("城市")}</Link>
<Link href={socialPath("/team")}>{socialTx("找搭子做事")}</Link>
<Link href={socialPath("/ebook")}>{socialTx("共创")}</Link>
<Link href={socialPath("/feedback")}>{socialTx("说说想法")}</Link>
</div>
<div className="footer-links footer-links-more">
<h4>{socialTx("更多")}</h4>
<Link href="/">{socialTx("门户首页")}</Link>
<Link href="/community">{socialTx("旅居社群")}</Link>
<Link href="/book">{socialTx("数字游民小册")}</Link>
<Link href={socialPath("/blog")}>{socialTx("博客")}</Link>
</div>
</div>
<div className="footer-bottom social-home-footer-bottom">
<p suppressHydrationWarning>
© {new Date().getFullYear()} nomadro · 游民社区
</p>
<div className="social-home-follow-row">
<Link href={socialPath("/blog")}>{socialTx("博客")}</Link>
<a
className="social-home-follow-x"
href={xProfileUrl(DEFAULT_X_HANDLE)}
target="_blank"
rel="noopener noreferrer"
onClick={() =>
trackFollow("click", {
channel: "x",
place: "social_home_footer",
})
}
>
<span aria-hidden>𝕏</span> Follow {formatXHandle()}
</a>
</div>
</div>
</div>
</footer>
</SiteShell>
<JoinPayModal open={joinOpen} onClose={() => setJoinOpen(false)} />
</div>
);
}