"use client"; import Link from "next/link"; import { useMemo, useSyncExternalStore } from "react"; import { ArrowUpRight, Camera, Check, MapPin, UserRound } from "lucide-react"; import { getCommunityUnlockServerSnapshot, getCommunityUnlockSnapshot, getLivenessServerSnapshot, getLivenessSnapshot, subscribeLivenessState, type LivenessState, } from "@social/lib/livenessGate"; import { loadJson } from "@social/lib/storage"; import type { SocialRosterProfile } from "@social/lib/types"; import { socialPath } from "@social/lib/socialPath"; import { socialTx } from "@social/lib/socialTx"; import SocialAvatar from "./SocialAvatar"; const CHANGE = "nomadro-social-storage"; function subscribeProfile(cb: () => void) { window.addEventListener(CHANGE, cb); window.addEventListener("storage", cb); return () => { window.removeEventListener(CHANGE, cb); window.removeEventListener("storage", cb); }; } const EMPTY_PROFILE: SocialRosterProfile = { name: "", title: "", city: "", phone: "", linktree: "", skills: "", bio: "", avatar: "", intents: "", availability: "", status: "", lookingFor: "", gender: "", }; export default function HomeStatusStrip() { const liveSnap = useSyncExternalStore( subscribeLivenessState, getLivenessSnapshot, getLivenessServerSnapshot, ); const profileSnap = useSyncExternalStore( subscribeProfile, () => JSON.stringify(loadJson("roster", EMPTY_PROFILE)), () => JSON.stringify(EMPTY_PROFILE), ); const state = useMemo( () => JSON.parse(liveSnap) as LivenessState, [liveSnap], ); const profile = useMemo(() => { const raw = JSON.parse(profileSnap) as Partial; return { ...EMPTY_PROFILE, ...raw }; }, [profileSnap]); const name = profile.name.trim() || socialTx("游民"); const city = profile.city.trim() || socialTx("城市待填"); const avatar = (profile.avatar || "").trim(); const faceOk = state.faceOk; const liveOk = state.livenessStatus === "verified"; const livePending = state.livenessStatus === "pending"; let nextHref = socialPath("/join?step=profile"); let nextLabel = socialTx("去完善"); let nextHint = socialTx("先上传头像,再拍张自拍"); if (!faceOk) { nextHint = socialTx("下一步:上传一张清晰的正面头像"); } else if (!liveOk) { nextHint = livePending ? socialTx("自拍已提交,稍等一下") : socialTx("下一步:拍张自拍,确认是你"); } else { nextHref = socialPath("/coffeechat"); nextLabel = socialTx("去咖啡聊"); nextHint = socialTx("都好了,可以去约会 / 咖啡聊"); } const secondaryHref = liveOk ? socialPath("/date") : socialPath("/roster"); const secondaryLabel = liveOk ? socialTx("去左右滑") : socialTx("我的介绍"); const avatarSrc = avatar || `https://api.dicebear.com/7.x/initials/svg?seed=${encodeURIComponent(name)}`; return (
{name} {city}
  • {faceOk ? : } {socialTx("头像")}
  • {liveOk ? : } {socialTx("自拍")}

{nextHint}

{nextLabel} {secondaryLabel}
); } /** Soft-gate helper for home CTAs (date / coffee / map). */ export function useHomeLivenessGate(): { faceOk: boolean; liveOk: boolean; verifyHref: string; } { const liveSnap = useSyncExternalStore( subscribeLivenessState, getLivenessSnapshot, getLivenessServerSnapshot, ); const unlockSnap = useSyncExternalStore( subscribeLivenessState, getCommunityUnlockSnapshot, getCommunityUnlockServerSnapshot, ); const state = JSON.parse(liveSnap) as LivenessState; return { faceOk: state.faceOk, liveOk: unlockSnap === "1", verifyHref: socialPath("/join"), }; }