nomadro/src/modules/social/components/HomeStatusStrip.tsx
Eric 9b7ffb24dc Ship social-first admin console, soft trials, and safer join gates.
Rebuild admin.nomadro.com around community ops, add configurable free peeks instead of nav locks, humanize user copy, and harden UGC/liveness admin APIs with backup/self-test scripts.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-04 23:47:04 +08:00

168 lines
4.9 KiB
TypeScript

"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<SocialRosterProfile>("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<SocialRosterProfile>;
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 (
<section
className="home-status-strip container reveal"
aria-label={socialTx("我的状态")}
>
<div className="home-status-card">
<span className="home-status-ava">
<SocialAvatar src={avatarSrc} size={52} />
</span>
<div className="home-status-meta">
<strong>{name}</strong>
<span>
<MapPin size={12} aria-hidden /> {city}
</span>
</div>
<ul className="home-status-steps" aria-label={socialTx("资料进度")}>
<li className={faceOk ? "is-done" : "is-todo"}>
{faceOk ? <Check size={14} /> : <UserRound size={14} />}
<em>{socialTx("头像")}</em>
</li>
<li
className={
liveOk ? "is-done" : livePending ? "is-pending" : "is-todo"
}
>
{liveOk ? <Check size={14} /> : <Camera size={14} />}
<em>{socialTx("自拍")}</em>
</li>
</ul>
<p className="home-status-hint">{nextHint}</p>
<div className="home-status-acts">
<Link className="btn btn-primary btn-sm" href={nextHref}>
{nextLabel} <ArrowUpRight size={14} />
</Link>
<Link className="btn btn-ghost btn-sm" href={secondaryHref}>
{secondaryLabel}
</Link>
</div>
</div>
</section>
);
}
/** 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"),
};
}