= {
export default function HomeClient() {
const config = useSocialConfig();
const { locale, t } = useSocialI18n();
- const roster = useAudienceRoster();
+ const roster = useDiscoveryRoster();
const [joinOpen, setJoinOpen] = useState(false);
const [activeSection, setActiveSection] = useState("people");
const promoUrl =
@@ -62,12 +62,12 @@ export default function HomeClient() {
);
const meetups = catalog.meetups;
const gigs = catalog.gigs;
- // 封面必须是美女:女生优先,不够再用在线的人补
- const datePreview = (() => {
+ // Ranked discovery (same-city → online → tags); soft bias women for cover strip
+ const datePreview = useMemo(() => {
const women = roster.filter((m) => m.gender === "f");
- const rest = roster.filter((m) => m.gender !== "f" && m.online);
+ const rest = roster.filter((m) => m.gender !== "f");
return [...women, ...rest].slice(0, 3);
- })();
+ }, [roster]);
useEffect(() => {
const root = document.querySelector(".social-home");
diff --git a/src/modules/social/components/ProfileStudio.tsx b/src/modules/social/components/ProfileStudio.tsx
index 6798967..b637507 100644
--- a/src/modules/social/components/ProfileStudio.tsx
+++ b/src/modules/social/components/ProfileStudio.tsx
@@ -27,6 +27,11 @@ const EMPTY: SocialRosterProfile = {
skills: "",
bio: "",
avatar: "",
+ intents: "",
+ availability: "",
+ status: "",
+ lookingFor: "",
+ gender: "",
};
const FIELDS = [
{
diff --git a/src/modules/social/lib/api.ts b/src/modules/social/lib/api.ts
index b1f9b27..1775669 100644
--- a/src/modules/social/lib/api.ts
+++ b/src/modules/social/lib/api.ts
@@ -225,6 +225,38 @@ export const socialApi = {
saveRoster: (payload: Record
) =>
req("/roster/me", { method: "PUT", json: payload }),
+ /** Ranked public profiles: same-city → online → tag match. */
+ discoveryRoster: (opts?: { city?: string; limit?: number }) => {
+ const q = new URLSearchParams();
+ if (opts?.city) q.set("city", opts.city);
+ if (opts?.limit) q.set("limit", String(opts.limit));
+ const qs = q.toString();
+ return req<{
+ ok: boolean;
+ viewerCity: string;
+ count: number;
+ items: Array<{
+ guestId: string;
+ name: string;
+ title: string;
+ city: string;
+ skills: string;
+ bio: string;
+ avatar: string;
+ gender: string;
+ intents: string;
+ availability: string;
+ status: string;
+ lookingFor: string;
+ online: boolean;
+ tags: string[];
+ score: number;
+ updatedAt: string;
+ linktree?: string;
+ }>;
+ }>(`/roster/discovery${qs ? `?${qs}` : ""}`, { ttlMs: 20_000 });
+ },
+
/** Two-frame live selfie challenge → verified front frame stored as avatar. */
uploadAvatarChallenge: async (front: Blob, turn: Blob) => {
const form = new FormData();
diff --git a/src/modules/social/lib/discoveryRoster.ts b/src/modules/social/lib/discoveryRoster.ts
index 6db0705..818cc2b 100644
--- a/src/modules/social/lib/discoveryRoster.ts
+++ b/src/modules/social/lib/discoveryRoster.ts
@@ -1,9 +1,14 @@
"use client";
-import { useMemo, useSyncExternalStore } from "react";
+import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
import { useAudienceModule } from "~/modules/audience";
+import { socialApi } from "./api";
import { MOCK_ROSTER, type SocialRosterMember } from "./rosterMock";
import { cnAvatarForSeed, mapRosterAvatarPack } from "./rosterAvatars";
+import {
+ discoveryItemToMember,
+ sortDiscoveryMembers,
+} from "./rankDiscovery";
import { loadJson, saveJson } from "./storage";
import type { SocialRosterProfile } from "./types";
@@ -20,6 +25,11 @@ const EMPTY: SocialRosterProfile = {
skills: "",
bio: "",
avatar: "",
+ intents: "",
+ availability: "",
+ status: "",
+ lookingFor: "",
+ gender: "",
};
const STORAGE_CHANGE = "nomadro-social-storage";
@@ -60,8 +70,10 @@ export function profileToMember(
const avatar = ownOk
? own
: avatarPack === "cn"
- ? cnAvatarForSeed(name, "f")
+ ? cnAvatarForSeed(name, (profile.gender as "f" | "m") || "f")
: `https://api.dicebear.com/7.x/initials/svg?seed=${encodeURIComponent(name)}`;
+ const status = (profile.status || "online").trim();
+ const online = status === "online" || status === "here" || status === "available";
return {
id: SELF_MEMBER_ID,
name,
@@ -70,14 +82,31 @@ export function profileToMember(
tags: tags.length ? tags : ["新朋友"],
avatar,
bio: profile.bio.trim() || "刚写好介绍,想认识同频的人。",
- vibe: "刚出现",
- online: true,
- lookingFor: "想认识同频游民",
- gender: "f",
+ vibe: status === "here" ? "同城想出来" : online ? "在线" : "刚出现",
+ online,
+ lookingFor:
+ (profile.lookingFor || "").trim() ||
+ (profile.intents || "").replace(/,/g, " · ") ||
+ "想认识同频游民",
+ gender: profile.gender === "m" ? "m" : "f",
+ availability: (profile.availability || "").trim() || undefined,
};
}
-/** Seed roster + optional self card when user opted into discovery. */
+function readLocalProfile(): SocialRosterProfile {
+ const raw = loadJson>("roster", EMPTY);
+ const next = { ...EMPTY };
+ (Object.keys(EMPTY) as (keyof SocialRosterProfile)[]).forEach((key) => {
+ const val = raw?.[key];
+ if (typeof val === "string") next[key] = val;
+ });
+ return next;
+}
+
+/**
+ * Discovery list: live API (same-city / online / tags) → merge mock fallback →
+ * optional self card. Ranked for local viewer profile.
+ */
export function useDiscoveryRoster(): SocialRosterMember[] {
const { bundle } = useAudienceModule();
const pack = bundle.module.social.rosterAvatarPack;
@@ -86,8 +115,6 @@ export function useDiscoveryRoster(): SocialRosterMember[] {
() => loadJson(ROSTER_PUBLISH_KEY, false),
() => false,
);
- // getSnapshot must be referentially stable: JSON.parse creates a new object
- // on every read once a local profile exists, causing a React render loop.
const profileSnapshot = useSyncExternalStore(
subscribeSocialStorage,
() => JSON.stringify(loadJson("roster", EMPTY)),
@@ -102,13 +129,46 @@ export function useDiscoveryRoster(): SocialRosterMember[] {
});
return next;
}, [profileSnapshot]);
+
+ const [remote, setRemote] = useState(null);
+
+ useEffect(() => {
+ let cancelled = false;
+ void socialApi
+ .discoveryRoster({ limit: 48 })
+ .then((res) => {
+ if (cancelled || !res?.items?.length) return;
+ setRemote(res.items.map(discoveryItemToMember));
+ })
+ .catch(() => {
+ /* offline → keep mock */
+ });
+ return () => {
+ cancelled = true;
+ };
+ }, [profile.city, profile.skills, profile.intents]);
+
const seed = useMemo(
() => mapRosterAvatarPack(MOCK_ROSTER, pack),
[pack],
);
+
return useMemo(() => {
+ const live = remote || [];
+ const liveIds = new Set(live.map((m) => m.id));
+ // Prefer real people; pad with mock so empty cities still feel alive
+ const merged = [
+ ...live,
+ ...seed.filter((m) => !liveIds.has(m.id)),
+ ];
+ const ranked = sortDiscoveryMembers(merged, profile);
const self = published ? profileToMember(profile, pack) : null;
- if (!self) return seed;
- return [self, ...seed.filter((m) => m.id !== SELF_MEMBER_ID)];
- }, [published, profile, seed, pack]);
+ if (!self) return ranked;
+ return [self, ...ranked.filter((m) => m.id !== SELF_MEMBER_ID)];
+ }, [published, profile, seed, pack, remote]);
+}
+
+/** One-shot helper for non-hook call sites. */
+export function getLocalViewerProfile(): SocialRosterProfile {
+ return readLocalProfile();
}
diff --git a/src/modules/social/lib/joinFlow.ts b/src/modules/social/lib/joinFlow.ts
index aa9b961..008798b 100644
--- a/src/modules/social/lib/joinFlow.ts
+++ b/src/modules/social/lib/joinFlow.ts
@@ -18,7 +18,12 @@ export type JoinProfileDraft = {
education: string;
graduation: string;
relationship: string;
+ /** who-to-meet / why join — required for cold-start matching */
intents: string[];
+ /** e.g. 本周可 coffeechat / 欧洲晚间可视频 */
+ availability: string;
+ /** online | away | offline — discovery “在线优先” */
+ status: string;
linktree: string;
bio: string;
};
@@ -58,12 +63,30 @@ export const JOIN_INTENT_OPTIONS: JoinOption[] = [
{ value: "online", labelZh: "线上分享", labelEn: "Online hangouts" },
{ value: "cowork", labelZh: "远程 cowork", labelEn: "Remote cowork" },
{ value: "collab", labelZh: "找搭子做事", labelEn: "Find collaborators" },
+ { value: "cofounder", labelZh: "找联创", labelEn: "Find a cofounder" },
{ value: "friends", labelZh: "交朋友", labelEn: "Make friends" },
{ value: "date", labelZh: "认识有缘人", labelEn: "Meet someone" },
{ value: "learn", labelZh: "学习成长", labelEn: "Learn & grow" },
{ value: "resource", labelZh: "资源互助", labelEn: "Share resources" },
];
+/** Preferred hangout windows for coffeechat / meetup matching. */
+export const JOIN_AVAILABILITY_OPTIONS: JoinOption[] = [
+ { value: "", labelZh: "先不填", labelEn: "Skip for now" },
+ { value: "weekday-eve", labelZh: "工作日晚上", labelEn: "Weekday evenings" },
+ { value: "weekend", labelZh: "周末可约", labelEn: "Weekends" },
+ { value: "flexible", labelZh: "时间灵活", labelEn: "Flexible" },
+ { value: "tz-async", labelZh: "跨时区异步", labelEn: "Async / timezone-friendly" },
+];
+
+/** Discovery presence signal (not GPS). */
+export const JOIN_STATUS_OPTIONS: JoinOption[] = [
+ { value: "online", labelZh: "在线 · 想认识人", labelEn: "Online · open to meet" },
+ { value: "here", labelZh: "同城 · 想出来", labelEn: "In city · want to hang" },
+ { value: "away", labelZh: "先潜水看看", labelEn: "Lurking for now" },
+ { value: "offline", labelZh: "暂时隐身", labelEn: "Appear offline" },
+];
+
export function markJoinPayIntent(): void {
try {
localStorage.setItem(JOIN_PENDING_PROFILE_KEY, "1");
diff --git a/src/modules/social/lib/phrases.ts b/src/modules/social/lib/phrases.ts
index 8f226b7..05729c1 100644
--- a/src/modules/social/lib/phrases.ts
+++ b/src/modules/social/lib/phrases.ts
@@ -343,6 +343,14 @@ export const SOCIAL_PHRASES_EN: Record = {
"Prefer a front-camera selfie — we check face presence & liveness",
"建议现场自拍核验:正脸 + 微转头":
"Live selfie check: front face + slight head turn",
+ "请填写当前城市,方便同城推荐":
+ "Add your city so we can recommend people nearby",
+ "请至少选一个「想认识 / 想做什么」":
+ "Pick at least one “who / what you’re looking for”",
+ "请填写技能或兴趣标签(逗号分隔)":
+ "Add skill or interest tags (comma-separated)",
+ "当前状态": "Status",
+ "可约时段": "Availability",
"检测设备中…": "Detecting device…",
"电脑已检测到摄像头:建议现场预览自拍(正脸 + 微转头)":
"Webcam found — live preview selfie recommended (front + slight turn)",
diff --git a/src/modules/social/lib/rankDiscovery.ts b/src/modules/social/lib/rankDiscovery.ts
new file mode 100644
index 0000000..8807d01
--- /dev/null
+++ b/src/modules/social/lib/rankDiscovery.ts
@@ -0,0 +1,96 @@
+import type { SocialRosterMember } from "./rosterMock";
+import type { SocialRosterProfile } from "./types";
+
+function normCity(city: string): string {
+ return city.trim().toLowerCase().replace(/\s+/g, "");
+}
+
+function tagSet(raw: string | string[] | undefined): Set {
+ const parts = Array.isArray(raw)
+ ? raw
+ : String(raw || "")
+ .split(/[,,、·|/\s]+/)
+ .map((t) => t.trim())
+ .filter(Boolean);
+ return new Set(parts.map((t) => t.toLowerCase()));
+}
+
+/** Client-side mirror of social_svc.score_discovery for mock merge. */
+export function scoreDiscoveryMember(
+ viewer: Partial | null | undefined,
+ member: SocialRosterMember,
+): number {
+ let score = 0;
+ const vCity = normCity(viewer?.city || "");
+ const mCity = normCity(member.city || "");
+ if (vCity && mCity && vCity === mCity) score += 1000;
+ else if (vCity && mCity && (vCity.includes(mCity) || mCity.includes(vCity)))
+ score += 600;
+ if (member.online) score += 200;
+ const vTags = new Set([
+ ...tagSet(viewer?.skills),
+ ...tagSet(viewer?.intents),
+ ...tagSet(viewer?.lookingFor),
+ ]);
+ const mTags = new Set([
+ ...tagSet(member.tags),
+ ...tagSet(member.lookingFor),
+ ]);
+ let overlap = 0;
+ vTags.forEach((t) => {
+ if (mTags.has(t)) overlap += 1;
+ });
+ score += Math.min(120, overlap * 40);
+ return score;
+}
+
+export function sortDiscoveryMembers(
+ members: SocialRosterMember[],
+ viewer: Partial | null | undefined,
+): SocialRosterMember[] {
+ return [...members].sort((a, b) => {
+ const sb = scoreDiscoveryMember(viewer, b);
+ const sa = scoreDiscoveryMember(viewer, a);
+ if (sb !== sa) return sb - sa;
+ return (a.name || "").localeCompare(b.name || "", "zh");
+ });
+}
+
+export function discoveryItemToMember(item: {
+ guestId: string;
+ name: string;
+ title?: string;
+ city?: string;
+ skills?: string;
+ bio?: string;
+ avatar?: string;
+ gender?: string;
+ lookingFor?: string;
+ availability?: string;
+ online?: boolean;
+ tags?: string[];
+ status?: string;
+}): SocialRosterMember {
+ const tags =
+ item.tags?.length
+ ? item.tags
+ : String(item.skills || "")
+ .split(/[,,、]/)
+ .map((t) => t.trim())
+ .filter(Boolean)
+ .slice(0, 8);
+ return {
+ id: item.guestId,
+ name: item.name,
+ title: item.title || "游民",
+ city: item.city || "探索中",
+ tags: tags.length ? tags : ["新朋友"],
+ avatar: item.avatar || "",
+ bio: item.bio || "",
+ vibe: item.status === "here" ? "同城想出来" : item.online ? "在线" : "刚出现",
+ online: Boolean(item.online),
+ lookingFor: item.lookingFor || "想认识同频游民",
+ gender: (item.gender as SocialRosterMember["gender"]) || "f",
+ availability: item.availability || "",
+ };
+}
diff --git a/src/modules/social/lib/types.ts b/src/modules/social/lib/types.ts
index 10713b0..7fa48fd 100644
--- a/src/modules/social/lib/types.ts
+++ b/src/modules/social/lib/types.ts
@@ -125,5 +125,10 @@ export type SocialRosterProfile = {
skills: string;
bio: string;
avatar?: string;
+ gender?: string;
+ intents?: string;
+ availability?: string;
+ status?: string;
+ lookingFor?: string;
updatedAt?: string;
};