Document the 2026-11-05 UI/UX upgrade and keep roster/live gates aligned with face-check and presence. Co-authored-by: Cursor <cursoragent@cursor.com>
181 lines
5.3 KiB
TypeScript
181 lines
5.3 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 { openSocialJoinModal } from "@social/lib/joinModal";
|
|
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: string | null = null;
|
|
let nextLabel = socialTx("去完善");
|
|
let nextHint = socialTx("先上传头像,再拍张自拍");
|
|
let nextOpensJoin = true;
|
|
|
|
if (!faceOk) {
|
|
nextHint = socialTx("下一步:上传头像");
|
|
} else if (!liveOk) {
|
|
nextHint = livePending
|
|
? socialTx("自拍已提交,稍等一下")
|
|
: socialTx("下一步:拍张自拍,确认是你");
|
|
} else {
|
|
nextHref = socialPath("/coffeechat");
|
|
nextLabel = socialTx("去咖啡聊");
|
|
nextHint = socialTx("都好了,可以去约会 / 咖啡聊");
|
|
nextOpensJoin = false;
|
|
}
|
|
|
|
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} allowPlaceholder />
|
|
</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">
|
|
{nextOpensJoin || !nextHref ? (
|
|
<button
|
|
type="button"
|
|
className="btn btn-primary btn-sm"
|
|
onClick={() => openSocialJoinModal({ reason: "gate" })}
|
|
>
|
|
{nextLabel} <ArrowUpRight size={14} />
|
|
</button>
|
|
) : (
|
|
<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;
|
|
openVerify: () => void;
|
|
} {
|
|
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",
|
|
openVerify: () => openSocialJoinModal({ reason: "gate" }),
|
|
};
|
|
}
|