Restore immersive /social motion FX and expand the glass community workspace.
Keep Codex layout polish, but force emoji/orbit/constellation animations when immersive is on even under OS reduced-motion. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
4789785f11
commit
bbe2514e96
@ -4,11 +4,85 @@ import { useCallback, useEffect, useState } from "react";
|
||||
import type { NomadroRemoteConfig } from "~/lib/remote-config";
|
||||
import styles from "../admin.module.css";
|
||||
|
||||
function SocialJsonEditor({
|
||||
label,
|
||||
value,
|
||||
type,
|
||||
onValue,
|
||||
onValidity,
|
||||
}: {
|
||||
label: string;
|
||||
value: unknown;
|
||||
type: "pages" | "sources";
|
||||
onValue: (value: Record<string, never>) => void;
|
||||
onValidity: (valid: boolean) => void;
|
||||
}) {
|
||||
const [text, setText] = useState(() => JSON.stringify(value || {}, null, 2));
|
||||
const [error, setError] = useState("");
|
||||
return (
|
||||
<label style={{ display: "block", marginBottom: 18 }}>
|
||||
<span className={styles.muted}>{label}</span>
|
||||
<textarea
|
||||
className={styles.input}
|
||||
rows={7}
|
||||
spellCheck={false}
|
||||
style={{ width: "100%", marginTop: 6, fontFamily: "monospace" }}
|
||||
value={text}
|
||||
onChange={(event) => {
|
||||
const next = event.target.value;
|
||||
setText(next);
|
||||
try {
|
||||
const parsed = JSON.parse(next);
|
||||
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
||||
throw new Error("请输入 JSON 对象");
|
||||
for (const item of Object.values(parsed)) {
|
||||
if (type === "sources") {
|
||||
if (
|
||||
typeof item !== "string" ||
|
||||
(item && !/^https?:\/\//i.test(item) && !item.startsWith("/"))
|
||||
)
|
||||
throw new Error("片源需为 http(s) 地址或站内路径");
|
||||
} else if (
|
||||
!item ||
|
||||
typeof item !== "object" ||
|
||||
Array.isArray(item) ||
|
||||
Object.entries(item).some(
|
||||
([key, val]) =>
|
||||
!["eyebrow", "title", "accent", "description"].includes(
|
||||
key,
|
||||
) || typeof val !== "string",
|
||||
)
|
||||
)
|
||||
throw new Error(
|
||||
"页面内容仅支持 eyebrow / title / accent / description 字符串",
|
||||
);
|
||||
}
|
||||
setError("");
|
||||
onValidity(true);
|
||||
onValue(parsed);
|
||||
} catch (cause) {
|
||||
setError(cause instanceof Error ? cause.message : "JSON 格式错误");
|
||||
onValidity(false);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{error && (
|
||||
<span role="alert" className={styles.error}>
|
||||
{error}
|
||||
</span>
|
||||
)}
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
export default function AdminConfigPage() {
|
||||
const [config, setConfig] = useState<NomadroRemoteConfig | null>(null);
|
||||
const [error, setError] = useState("");
|
||||
const [saved, setSaved] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [socialJsonErrors, setSocialJsonErrors] = useState<
|
||||
Record<string, boolean>
|
||||
>({});
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setError("");
|
||||
@ -26,7 +100,7 @@ export default function AdminConfigPage() {
|
||||
}, [load]);
|
||||
|
||||
async function save() {
|
||||
if (!config) return;
|
||||
if (!config || Object.values(socialJsonErrors).some(Boolean)) return;
|
||||
setBusy(true);
|
||||
setSaved("");
|
||||
setError("");
|
||||
@ -57,7 +131,9 @@ export default function AdminConfigPage() {
|
||||
);
|
||||
}
|
||||
|
||||
const moduleKeys = Object.keys(config.modules) as (keyof typeof config.modules)[];
|
||||
const moduleKeys = Object.keys(
|
||||
config.modules,
|
||||
) as (keyof typeof config.modules)[];
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -75,8 +151,18 @@ export default function AdminConfigPage() {
|
||||
{moduleKeys.map((key) => {
|
||||
const m = config.modules[key] ?? { enabled: false, title: key };
|
||||
return (
|
||||
<label key={key} className={styles.panel} style={{ cursor: "pointer" }}>
|
||||
<div style={{ display: "flex", justifyContent: "space-between", gap: 8 }}>
|
||||
<label
|
||||
key={key}
|
||||
className={styles.panel}
|
||||
style={{ cursor: "pointer" }}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
gap: 8,
|
||||
}}
|
||||
>
|
||||
<strong>{m.title || key}</strong>
|
||||
<input
|
||||
type="checkbox"
|
||||
@ -188,7 +274,10 @@ export default function AdminConfigPage() {
|
||||
/>
|
||||
<span>
|
||||
<strong>{label}</strong>
|
||||
<span className={styles.muted} style={{ display: "block", fontSize: 12 }}>
|
||||
<span
|
||||
className={styles.muted}
|
||||
style={{ display: "block", fontSize: 12 }}
|
||||
>
|
||||
{hint} · <code>{key}</code>
|
||||
</span>
|
||||
</span>
|
||||
@ -205,6 +294,16 @@ export default function AdminConfigPage() {
|
||||
["homeLead", "导语"],
|
||||
["vipProductId", "VIP productId"],
|
||||
["vipCta", "VIP 按钮"],
|
||||
["socialEyebrow", "游民社区 · 首屏眉题"],
|
||||
["socialHeroLine1", "游民社区 · 标题首行"],
|
||||
["socialHeroAccent", "游民社区 · 标题强调词"],
|
||||
["socialJoinCta", "游民社区 · 主按钮"],
|
||||
["socialOnlineTitle", "游民社区 · 线上入口"],
|
||||
["socialOfflineTitle", "游民社区 · 线下入口"],
|
||||
["socialTeamTitle", "游民社区 · 共创入口"],
|
||||
["socialInviteTitle", "游民社区 · 底部邀请标题"],
|
||||
["socialInviteLead", "游民社区 · 底部邀请说明"],
|
||||
["socialPromoUrl", "游民社区 · 宣传片地址(留空使用默认)"],
|
||||
] as const
|
||||
).map(([key, label]) => (
|
||||
<label key={key} style={{ display: "block", marginBottom: 10 }}>
|
||||
@ -212,7 +311,7 @@ export default function AdminConfigPage() {
|
||||
<input
|
||||
className={styles.input}
|
||||
style={{ width: "100%", marginTop: 4 }}
|
||||
value={String(config.copy[key])}
|
||||
value={String(config.copy[key] ?? "")}
|
||||
onChange={(e) =>
|
||||
setConfig({
|
||||
...config,
|
||||
@ -222,6 +321,21 @@ export default function AdminConfigPage() {
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
<label style={{ display: "block", marginBottom: 10 }}>
|
||||
<span className={styles.muted}>游民社区 · 首屏导语(支持换行)</span>
|
||||
<textarea
|
||||
className={styles.input}
|
||||
rows={4}
|
||||
style={{ width: "100%", marginTop: 4 }}
|
||||
value={config.copy.socialHeroLead ?? ""}
|
||||
onChange={(event) =>
|
||||
setConfig({
|
||||
...config,
|
||||
copy: { ...config.copy, socialHeroLead: event.target.value },
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label style={{ display: "block", marginBottom: 10 }}>
|
||||
<span className={styles.muted}>VIP 价格(分)</span>
|
||||
<input
|
||||
@ -232,14 +346,64 @@ export default function AdminConfigPage() {
|
||||
onChange={(e) =>
|
||||
setConfig({
|
||||
...config,
|
||||
copy: { ...config.copy, vipPriceFen: Number(e.target.value) || 0 },
|
||||
copy: {
|
||||
...config.copy,
|
||||
vipPriceFen: Number(e.target.value) || 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<button type="button" className={styles.primaryBtn} disabled={busy} onClick={save}>
|
||||
<div className={styles.panel} style={{ marginBottom: 12 }}>
|
||||
<h3>游民社区 · 子页面内容</h3>
|
||||
<p className={styles.muted}>
|
||||
按路由键覆盖页头:people / chat / meetup / coffeechat / roster / team
|
||||
/ gigs / videos / date / ebook / join / vip /
|
||||
feedback。留空对象使用内置文案。
|
||||
</p>
|
||||
<SocialJsonEditor
|
||||
key={`pages:${config.updatedAt}`}
|
||||
label={
|
||||
'页面文案 JSON,例如 {"people":{"title":"遇见同类,","accent":"从这里开始。"}}'
|
||||
}
|
||||
type="pages"
|
||||
value={config.copy.socialPages}
|
||||
onValue={(value) =>
|
||||
setConfig({
|
||||
...config,
|
||||
copy: { ...config.copy, socialPages: value },
|
||||
})
|
||||
}
|
||||
onValidity={(valid) =>
|
||||
setSocialJsonErrors((current) => ({ ...current, pages: !valid }))
|
||||
}
|
||||
/>
|
||||
<SocialJsonEditor
|
||||
key={`sources:${config.updatedAt}`}
|
||||
label={
|
||||
'视频片源 JSON,例如 {"cm-morning":"https://你的媒体域名/video.mp4"};未配置时仅展示目录'
|
||||
}
|
||||
type="sources"
|
||||
value={config.copy.socialVideoSources}
|
||||
onValue={(value) =>
|
||||
setConfig({
|
||||
...config,
|
||||
copy: { ...config.copy, socialVideoSources: value },
|
||||
})
|
||||
}
|
||||
onValidity={(valid) =>
|
||||
setSocialJsonErrors((current) => ({ ...current, sources: !valid }))
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className={styles.primaryBtn}
|
||||
disabled={busy || Object.values(socialJsonErrors).some(Boolean)}
|
||||
onClick={save}
|
||||
>
|
||||
{busy ? "保存中…" : "保存到后端"}
|
||||
</button>
|
||||
</>
|
||||
|
||||
@ -4,10 +4,17 @@ import "@community/app/globals.css";
|
||||
import "@social/app/globals.css";
|
||||
import "@social/app/fx.css";
|
||||
import "@social/app/theme2.css";
|
||||
import "@social/app/home.css";
|
||||
import "@social/app/experience.css";
|
||||
import "@social/app/interaction.css";
|
||||
import "@social/app/studio.css";
|
||||
import "@social/app/motion.css";
|
||||
import SocialExperience from "@social/components/SocialExperience";
|
||||
|
||||
export const metadata = {
|
||||
title: "游民社区 · nomadro",
|
||||
description: "数字游民社交:线上聊天 · Meetup · Coffeechat · 职业花名册 · UGC",
|
||||
description:
|
||||
"数字游民社交:线上聊天 · Meetup · Coffeechat · 职业花名册 · UGC",
|
||||
};
|
||||
|
||||
export default function SocialLayout({
|
||||
@ -24,7 +31,7 @@ export default function SocialLayout({
|
||||
__html: `(function(){try{localStorage.setItem('nomadro-social-skin','1');}catch(e){}document.documentElement.setAttribute('data-social-skin','1');})();`,
|
||||
}}
|
||||
/>
|
||||
{children}
|
||||
<SocialExperience>{children}</SocialExperience>
|
||||
</div>
|
||||
</ModuleBoundary>
|
||||
);
|
||||
|
||||
6
src/app/social/people/page.tsx
Normal file
6
src/app/social/people/page.tsx
Normal file
@ -0,0 +1,6 @@
|
||||
import { Suspense } from "react";
|
||||
import PeopleClient from "@social/components/PeopleClient";
|
||||
|
||||
export default function PeoplePage() {
|
||||
return <Suspense fallback={<div className="social-status">正在发现同类…</div>}><PeopleClient /></Suspense>;
|
||||
}
|
||||
@ -13,7 +13,6 @@ export type ModuleToggle = {
|
||||
note?: string;
|
||||
};
|
||||
|
||||
|
||||
/** 导航链接(远程可 CRUD;hidden=软隐藏) */
|
||||
export type NavLinkItem = {
|
||||
id: string;
|
||||
@ -128,6 +127,28 @@ export type NomadroRemoteConfig = {
|
||||
wechatOaName?: string;
|
||||
joinGroupDouyinHint?: string;
|
||||
joinGroupDouyinQr?: string;
|
||||
/** 游民社区落地页;/admin/config 可编辑,客户端有默认文案兜底。 */
|
||||
socialEyebrow?: string;
|
||||
socialHeroLine1?: string;
|
||||
socialHeroAccent?: string;
|
||||
socialHeroLead?: string;
|
||||
socialJoinCta?: string;
|
||||
socialInviteTitle?: string;
|
||||
socialInviteLead?: string;
|
||||
socialPromoUrl?: string;
|
||||
socialOnlineTitle?: string;
|
||||
socialOfflineTitle?: string;
|
||||
socialTeamTitle?: string;
|
||||
socialPages?: Record<
|
||||
string,
|
||||
{
|
||||
eyebrow?: string;
|
||||
title?: string;
|
||||
accent?: string;
|
||||
description?: string;
|
||||
}
|
||||
>;
|
||||
socialVideoSources?: Record<string, string>;
|
||||
};
|
||||
/** 导航页分类 / 链接(后台可增删改隐) */
|
||||
navContent?: NavContent;
|
||||
@ -137,9 +158,11 @@ export type NomadroRemoteConfig = {
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
function normalizeNavLink(raw: unknown, i: number): NavLinkItem {
|
||||
const r = (raw && typeof raw === "object" ? raw : {}) as Record<string, unknown>;
|
||||
const r = (raw && typeof raw === "object" ? raw : {}) as Record<
|
||||
string,
|
||||
unknown
|
||||
>;
|
||||
const action = r.action === "copy" ? "copy" : "open";
|
||||
return {
|
||||
id: String(r.id || `link-${i}`),
|
||||
@ -153,7 +176,10 @@ function normalizeNavLink(raw: unknown, i: number): NavLinkItem {
|
||||
}
|
||||
|
||||
function normalizeNavGroup(raw: unknown, i: number): NavGroupItem {
|
||||
const r = (raw && typeof raw === "object" ? raw : {}) as Record<string, unknown>;
|
||||
const r = (raw && typeof raw === "object" ? raw : {}) as Record<
|
||||
string,
|
||||
unknown
|
||||
>;
|
||||
const links = Array.isArray(r.links) ? r.links.map(normalizeNavLink) : [];
|
||||
return {
|
||||
id: String(r.id || `group-${i}`),
|
||||
@ -164,7 +190,10 @@ function normalizeNavGroup(raw: unknown, i: number): NavGroupItem {
|
||||
}
|
||||
|
||||
function normalizeNavCategory(raw: unknown, i: number): NavCategoryItem {
|
||||
const r = (raw && typeof raw === "object" ? raw : {}) as Record<string, unknown>;
|
||||
const r = (raw && typeof raw === "object" ? raw : {}) as Record<
|
||||
string,
|
||||
unknown
|
||||
>;
|
||||
const groups = Array.isArray(r.groups) ? r.groups.map(normalizeNavGroup) : [];
|
||||
return {
|
||||
id: String(r.id || `cat-${i}`),
|
||||
@ -176,7 +205,10 @@ function normalizeNavCategory(raw: unknown, i: number): NavCategoryItem {
|
||||
}
|
||||
|
||||
export function normalizeNavContent(raw: unknown): NavContent {
|
||||
const r = (raw && typeof raw === "object" ? raw : {}) as Record<string, unknown>;
|
||||
const r = (raw && typeof raw === "object" ? raw : {}) as Record<
|
||||
string,
|
||||
unknown
|
||||
>;
|
||||
const categories = Array.isArray(r.categories)
|
||||
? r.categories.map(normalizeNavCategory)
|
||||
: [];
|
||||
@ -189,7 +221,8 @@ export function normalizeNavContent(raw: unknown): NavContent {
|
||||
};
|
||||
}
|
||||
|
||||
export const DEFAULT_NAV_CONTENT: NavContent = normalizeNavContent(navDefaultLinks);
|
||||
export const DEFAULT_NAV_CONTENT: NavContent =
|
||||
normalizeNavContent(navDefaultLinks);
|
||||
|
||||
/** 后台完整提交 categories 时整表替换;否则保留 base */
|
||||
export function mergeNavContent(
|
||||
@ -212,7 +245,11 @@ export function mergeNavContent(
|
||||
/** 导航内容:远程有分类则用远程,否则包内 seed */
|
||||
export function resolveNavContent(config: NomadroRemoteConfig): NavContent {
|
||||
const remote = config.navContent;
|
||||
if (remote && Array.isArray(remote.categories) && remote.categories.length > 0) {
|
||||
if (
|
||||
remote &&
|
||||
Array.isArray(remote.categories) &&
|
||||
remote.categories.length > 0
|
||||
) {
|
||||
return mergeNavContent(DEFAULT_NAV_CONTENT, remote);
|
||||
}
|
||||
return structuredClone(DEFAULT_NAV_CONTENT);
|
||||
@ -332,6 +369,19 @@ export const DEFAULT_REMOTE_CONFIG: NomadroRemoteConfig = {
|
||||
wechatOaName: "异度世界",
|
||||
joinGroupDouyinHint: "打开抖音搜群「数字游民」或扫码进群",
|
||||
joinGroupDouyinQr: "",
|
||||
socialEyebrow: "自由生活,同频相遇",
|
||||
socialHeroLine1: "世界很大,",
|
||||
socialHeroAccent: "同类",
|
||||
socialHeroLead:
|
||||
"换一座城市,不必重新孤独。\n从一句你好、一杯咖啡开始,找到一起生活、\n一起探索、一起做点什么的人。",
|
||||
socialJoinCta: "找到我的同频",
|
||||
socialInviteTitle: "下一站,和同类一起。",
|
||||
socialInviteLead:
|
||||
"无论你正在出发,还是已经在路上,这里都有一个属于你的位置。",
|
||||
socialPromoUrl: "",
|
||||
socialOnlineTitle: "随时,聊得来",
|
||||
socialOfflineTitle: "同城,见一面",
|
||||
socialTeamTitle: "一起,做点事",
|
||||
},
|
||||
navContent: structuredClone(DEFAULT_NAV_CONTENT),
|
||||
platforms: {
|
||||
@ -430,8 +480,10 @@ export function mergeRemoteConfig(
|
||||
const modKeys = Object.keys(base.modules) as (keyof typeof base.modules)[];
|
||||
const modules = { ...base.modules };
|
||||
for (const key of modKeys) {
|
||||
const baseModule = base.modules[key];
|
||||
if (!baseModule) continue;
|
||||
modules[key] = mergeModuleToggle(
|
||||
base.modules[key],
|
||||
baseModule,
|
||||
partial.modules?.[key] as Partial<ModuleToggle> | undefined,
|
||||
);
|
||||
}
|
||||
@ -449,7 +501,10 @@ export function mergeRemoteConfig(
|
||||
flags: {
|
||||
payEnabled: asBool(pf.payEnabled, base.flags.payEnabled),
|
||||
socialFollow: asBool(pf.socialFollow, base.flags.socialFollow),
|
||||
socialFollowAuto: asBool(pf.socialFollowAuto, base.flags.socialFollowAuto),
|
||||
socialFollowAuto: asBool(
|
||||
pf.socialFollowAuto,
|
||||
base.flags.socialFollowAuto,
|
||||
),
|
||||
joinGroupWechat: asBool(pf.joinGroupWechat, base.flags.joinGroupWechat),
|
||||
joinGroupDouyin: asBool(pf.joinGroupDouyin, base.flags.joinGroupDouyin),
|
||||
joinGroupAction: joinAction,
|
||||
|
||||
@ -15,13 +15,41 @@
|
||||
|
||||
- **T1**(默认):社区对齐;`lib/skin.ts` · `SOCIAL_SKIN_DEFAULT = "1"`
|
||||
- **T2**:`app/theme2.css`(琥珀信号);切换器默认隐藏
|
||||
- **首页动效**:`SocialOrbitScene`(three.js)· `FloatingEmojiField` · framer-motion · aurora / sheen CSS;`prefers-reduced-motion` 降级
|
||||
- **首页视觉**:`ConnectionHero` 的 SVG 连接轨道、成员浮层、鼠标视差、柔光粒子;`home.css` 隔离首页样式,保留珊瑚红 / 薄荷绿 / 暖黄配色。
|
||||
- **动效与可访问性**:区块滚动显现、卡片聚光、悬停声波、阅读进度;尊重 `prefers-reduced-motion`,视频按需加载,离开页面时清理监听。
|
||||
- **交互**:粘性区块导航与当前位置、方向键筛选成员、关注本地保存;原生 `dialog` 管理视频与加群弹窗的焦点、Escape、背景锁定。
|
||||
- **全站布局**:桌面为宽幅内容 + 顶部分组导航;移动端为顶部菜单 + 底部快捷入口。没有侧栏,聊天室频道也使用横向切换。
|
||||
- **全站动效**:`SocialExperience` / `experience.css` 提供星点连线、鼠标柔光、漂移光晕、卡片聚光和页面入场;`interaction.css` / `studio.css` 提供声波、会前雷达、名片透视与书封动效。动效可切为轻量,系统减少动态效果设置优先;离开页面或标签页隐藏时清理/暂停动画。
|
||||
|
||||
## 子页面与交互边界
|
||||
|
||||
- `/people`:按城市 / 技能 / 兴趣搜索展示成员,收藏与名片弹窗;成员和在线状态为演示资料,交流入口通向真实公开频道,没有虚构私信或匹配结果。
|
||||
- `/chat`、`/chat/[id]`:频道搜索、破冰话题、引用回复、表情、IME 友好的 Enter 发送、独立消息区滚动、本机草稿。连接现有 API / Centrifugo,失败保留「仅本机」消息并支持手动重试;反应与频道收藏仅本机保存。
|
||||
- `/meetup`、`/meetup/[id]`:活动收藏表示本机参与计划,不是预约成功;导出日历按活动 IANA 时区转换为 UTC,种子默认 `Asia/Shanghai`。视频房间在明确点击进入后才加载,麦克风 / 摄像头默认关闭,支持布局切换、重连、新窗口和离开。音视频能力依赖现有 MiroTalk 服务及用户授权。
|
||||
- `/coffeechat`:城市 / 关键词 / 网络 / 评分筛选,地点收藏、可分享选中地点、真实评价提交与离线重试。目录中的地点、带宽、评分仅作种子参考;邀约进入公开频道,不伪造订位或即时到场人数。
|
||||
- `/roster`:编辑时实时预览名片与完成度,本机草稿优先;慢返回的服务端资料不会覆盖正在编辑的内容。保存调用现有资料 API,明确区别同步成功与尚未同步。
|
||||
- `/team`、`/gigs`:搜索技能与角色、类型筛选、收藏、参与申请弹窗,校验必填项、保留本机草稿、失败重试和重复提交保护。目录机会是否开放需另行确认。
|
||||
- `/videos`、`/date`、`/ebook`:统一搜索、收藏、内容详情和话题讨论入口。视频没有片源时明确展示目录预览,不显示假播放器;小册入口通向门户书库,不承诺目录主题已有对应完整正文。
|
||||
- `/join`、`/vip`、`/feedback`:加入步骤、已有社群引导、会员中心入口、反馈草稿与离线重试;购买遵循 `payEnabled`,不承诺未实现的优先席位等权益。
|
||||
- **子页面运营**:`/admin/config` 的 `copy.socialPages` 支持按路由键覆盖 `{ eyebrow, title, accent, description }`;`copy.socialVideoSources` 按目录 ID 配置 http(s) 或站内片源。编辑器校验 JSON,非法配置禁止提交;空配置使用内置默认文案。
|
||||
- **存储**:`useLocalState` 统一草稿、偏好和收藏,兼容服务端渲染和跨标签页更新。本机保存不会冒充服务器发布、真实关注关系或账号登录。
|
||||
|
||||
## 首页(数字游民社交)
|
||||
|
||||
- 右侧:宣传片 `<video>`(`modules.social.promoVideoUrl` 可覆盖默认源)
|
||||
- 右侧:同频引力轨道与演示成员;「看看社区故事」打开宣传片,首屏不加载视频。
|
||||
- **后台文案**:`/admin/config` 可编辑 `copy.socialEyebrow` / `socialHeroLine1` / `socialHeroAccent` / `socialHeroLead` / `socialJoinCta` / `socialInviteTitle` / `socialInviteLead` / `socialOnlineTitle` / `socialOfflineTitle` / `socialTeamTitle`。空值或异常字段使用客户端默认值。
|
||||
- **宣传片**:`copy.socialPromoUrl` 优先,其次兼容 `modules.social.promoVideoUrl`,最后使用默认源。
|
||||
- CTA:仅「加群」→ 邮箱弹窗 → PC/H5 `zpay`、微信内 H5 `xpay`、小程序引导虚拟支付(`JoinPayModal` + `triggerPay`)
|
||||
- 下方:成员花名册 → Meetup → Coffeechat → **远程团队**(`/social/team`:志愿者 / 兼职 / 全职);原 PATH/HUB/NEXT 已去掉
|
||||
- 下方:三种连接入口 → 成员花名册 → Meetup → Coffeechat → **远程团队**(`/social/team`:志愿者 / 兼职 / 全职)→ 加入邀请。
|
||||
- 首页成员 / 活动预览沿用种子数据,演示在线状态明确标注,非实时成员统计。
|
||||
- 世界时钟展示清迈、大理、里斯本、巴厘岛的实际本地时间,并链接对应城市发现页。
|
||||
|
||||
## 本地验收
|
||||
|
||||
- TypeScript 全量检查与改动范围 ESLint。
|
||||
- Chrome / Playwright 覆盖 17 个路由的 320 / 390 / 768 / 1440 宽度;首页补充 700 / 900 / 1024 宽度。
|
||||
- 检查明暗主题、减少动态效果、菜单 / 原生弹窗、搜索收藏、公开话题草稿、聊天与表单提交成功 / 离线 / 重试、日历时区与视频会前确认。
|
||||
- 自动化写接口使用拦截响应,不向实际社区发布消息、评价或申请,不触发真实支付。视频房间仅验证加载与控制流程,不代表外部音视频连通性已验收。
|
||||
|
||||
## 本地
|
||||
|
||||
|
||||
1275
src/modules/social/app/experience.css
Normal file
1275
src/modules/social/app/experience.css
Normal file
File diff suppressed because it is too large
Load Diff
@ -557,25 +557,27 @@
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.social-emoji-float,
|
||||
.social-fx-orb,
|
||||
.social-fx-belt-track,
|
||||
.social-btn-pulse::before,
|
||||
.social-btn-pulse::after,
|
||||
.social-promo-glow,
|
||||
.social-promo-live,
|
||||
.social-panel-fx,
|
||||
.social-chip-pop,
|
||||
.social-title-emoji,
|
||||
.social-panel-ico,
|
||||
.social-ring-spin,
|
||||
.social-logo-spin,
|
||||
.social-people-chip.is-online .social-people-chip-ava::before,
|
||||
.social-people-bar-avs img,
|
||||
.social-count-pulse,
|
||||
.social-spark-path,
|
||||
.social-spark-dot,
|
||||
.social-hero-fx .shape {
|
||||
.social-experience[data-immersive="false"] .social-emoji-float,
|
||||
.social-experience[data-immersive="false"] .social-fx-orb,
|
||||
.social-experience[data-immersive="false"] .social-fx-belt-track,
|
||||
.social-experience[data-immersive="false"] .social-btn-pulse::before,
|
||||
.social-experience[data-immersive="false"] .social-btn-pulse::after,
|
||||
.social-experience[data-immersive="false"] .social-promo-glow,
|
||||
.social-experience[data-immersive="false"] .social-promo-live,
|
||||
.social-experience[data-immersive="false"] .social-panel-fx,
|
||||
.social-experience[data-immersive="false"] .social-chip-pop,
|
||||
.social-experience[data-immersive="false"] .social-title-emoji,
|
||||
.social-experience[data-immersive="false"] .social-panel-ico,
|
||||
.social-experience[data-immersive="false"] .social-ring-spin,
|
||||
.social-experience[data-immersive="false"] .social-logo-spin,
|
||||
.social-experience[data-immersive="false"]
|
||||
.social-people-chip.is-online
|
||||
.social-people-chip-ava::before,
|
||||
.social-experience[data-immersive="false"] .social-people-bar-avs img,
|
||||
.social-experience[data-immersive="false"] .social-count-pulse,
|
||||
.social-experience[data-immersive="false"] .social-spark-path,
|
||||
.social-experience[data-immersive="false"] .social-spark-dot,
|
||||
.social-experience[data-immersive="false"] .social-hero-fx .shape {
|
||||
animation: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
2139
src/modules/social/app/home.css
Normal file
2139
src/modules/social/app/home.css
Normal file
File diff suppressed because it is too large
Load Diff
1178
src/modules/social/app/interaction.css
Normal file
1178
src/modules/social/app/interaction.css
Normal file
File diff suppressed because it is too large
Load Diff
464
src/modules/social/app/motion.css
Normal file
464
src/modules/social/app/motion.css
Normal file
@ -0,0 +1,464 @@
|
||||
/* Immersive motion — beat Codex home.css mutes (loaded last). */
|
||||
|
||||
.social-experience[data-immersive="true"] .social-ambient i {
|
||||
opacity: 0.22 !important;
|
||||
filter: blur(80px);
|
||||
animation: sx-aurora 18s ease-in-out infinite alternate !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-ambient i:nth-child(2) {
|
||||
opacity: 0.16 !important;
|
||||
animation-duration: 22s !important;
|
||||
animation-direction: alternate-reverse !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-ambient i:nth-child(3) {
|
||||
opacity: 0.12 !important;
|
||||
animation-duration: 26s !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .social-fx-orbs {
|
||||
opacity: 0.72 !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .social-fx-orb.o3 {
|
||||
display: block !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .social-fx-orb {
|
||||
animation: social-orb-drift 8s ease-in-out infinite !important;
|
||||
filter: blur(48px) !important;
|
||||
opacity: 0.62 !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .social-fx-orb.o2 {
|
||||
animation-duration: 10s !important;
|
||||
animation-delay: -3s !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .social-fx-orb.o3 {
|
||||
animation-duration: 12s !important;
|
||||
animation-delay: -6s !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-constellation {
|
||||
opacity: 1 !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-pointer-glow {
|
||||
background: radial-gradient(
|
||||
480px circle at var(--pointer-x, -1000px) var(--pointer-y, -1000px),
|
||||
rgba(78, 205, 196, 0.18),
|
||||
rgba(255, 107, 107, 0.06) 42%,
|
||||
transparent 72%
|
||||
) !important;
|
||||
}
|
||||
|
||||
/* Hero floating emoji */
|
||||
.connection-hero {
|
||||
position: relative;
|
||||
overflow: clip;
|
||||
}
|
||||
|
||||
.connection-hero .social-emoji-field {
|
||||
z-index: 1;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.connection-hero-layout {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-emoji-float {
|
||||
opacity: 0.82 !important;
|
||||
filter: drop-shadow(0 14px 26px rgba(0, 0, 0, 0.45)) !important;
|
||||
animation-name: social-emoji-fly !important;
|
||||
animation-timing-function: ease-in-out !important;
|
||||
animation-iteration-count: infinite !important;
|
||||
will-change: transform, opacity;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="false"] .social-emoji-field,
|
||||
.social-experience[data-immersive="false"] .social-fx-belt {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* Signal bars */
|
||||
.social-experience[data-immersive="true"] .connection-signal i {
|
||||
animation: social-signal-bars 1s ease-in-out infinite !important;
|
||||
transform-origin: bottom !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-signal i:nth-child(2) {
|
||||
animation-delay: 0.1s !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-signal i:nth-child(3) {
|
||||
animation-delay: 0.2s !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-signal i:nth-child(4) {
|
||||
animation-delay: 0.3s !important;
|
||||
}
|
||||
|
||||
@keyframes social-signal-bars {
|
||||
0%,
|
||||
100% {
|
||||
transform: scaleY(0.4);
|
||||
opacity: 0.4;
|
||||
}
|
||||
50% {
|
||||
transform: scaleY(1);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-status-dot {
|
||||
box-shadow: 0 0 0 0 rgba(78, 205, 196, 0.6) !important;
|
||||
animation: social-live-ping 1.25s ease-out infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-orbit-traveler {
|
||||
animation-duration: 12s !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-orbit-traveler-second {
|
||||
animation-duration: 16s !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-flight-path {
|
||||
animation-duration: 10s !important;
|
||||
opacity: 0.95 !important;
|
||||
stroke-width: 2.2 !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-center-icon {
|
||||
animation: social-center-glow 2.4s ease-in-out infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-center-icon svg {
|
||||
animation: connection-breathe 2s ease-in-out infinite !important;
|
||||
}
|
||||
|
||||
@keyframes social-center-glow {
|
||||
0%,
|
||||
100% {
|
||||
box-shadow:
|
||||
0 0 36px rgba(78, 205, 196, 0.14),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.08);
|
||||
}
|
||||
50% {
|
||||
box-shadow:
|
||||
0 0 80px rgba(78, 205, 196, 0.42),
|
||||
0 0 120px rgba(255, 107, 107, 0.12),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.16);
|
||||
}
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-person {
|
||||
animation-duration: 4s !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-universe:hover .connection-person,
|
||||
.social-experience[data-immersive="true"]
|
||||
.connection-universe:focus-within
|
||||
.connection-person {
|
||||
animation-play-state: running !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-person-avatar > i {
|
||||
animation: social-live-ping 1.35s ease-out infinite !important;
|
||||
}
|
||||
|
||||
/* Undo Codex display:none / animation:none */
|
||||
.social-experience[data-immersive="true"] .social-home .social-title-emoji {
|
||||
display: inline-block !important;
|
||||
margin-right: 0.3em !important;
|
||||
animation: social-emoji-wiggle 1.6s ease-in-out infinite !important;
|
||||
transform-origin: 50% 80%;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .social-btn-pulse {
|
||||
position: relative !important;
|
||||
overflow: visible !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .social-btn-pulse::before,
|
||||
.social-experience[data-immersive="true"] .social-home .social-btn-pulse::after {
|
||||
content: "" !important;
|
||||
display: block !important;
|
||||
position: absolute !important;
|
||||
inset: -5px !important;
|
||||
border-radius: inherit !important;
|
||||
border: 2px solid rgba(78, 205, 196, 0.55) !important;
|
||||
pointer-events: none !important;
|
||||
animation: social-btn-ring 1.4s ease-out infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .social-btn-pulse::before {
|
||||
animation-delay: 0.7s !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .social-people-bar-avs img {
|
||||
animation: social-ava-bob 1.8s ease-in-out infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"]
|
||||
.social-home
|
||||
.social-people-bar-avs
|
||||
img:nth-child(2) {
|
||||
animation-delay: 0.1s !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"]
|
||||
.social-home
|
||||
.social-people-bar-avs
|
||||
img:nth-child(3) {
|
||||
animation-delay: 0.2s !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"]
|
||||
.social-home
|
||||
.social-people-bar-avs
|
||||
img:nth-child(4) {
|
||||
animation-delay: 0.3s !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .social-count-pulse {
|
||||
animation: social-count-glow 1.15s ease-in-out infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .nav-logo .logo-icon {
|
||||
animation: social-logo-spin 6s linear infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .social-path-track a,
|
||||
.social-experience[data-immersive="true"]
|
||||
.social-home
|
||||
.social-path-track.reveal.visible
|
||||
.social-path-link {
|
||||
animation: social-path-pop 0.55s cubic-bezier(0.2, 0.9, 0.2, 1.15) both !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"]
|
||||
.social-home
|
||||
.social-path-track.reveal.visible
|
||||
a:nth-child(1) {
|
||||
animation-delay: 0.04s !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"]
|
||||
.social-home
|
||||
.social-path-track.reveal.visible
|
||||
a:nth-child(2) {
|
||||
animation-delay: 0.1s !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"]
|
||||
.social-home
|
||||
.social-path-track.reveal.visible
|
||||
a:nth-child(3) {
|
||||
animation-delay: 0.16s !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"]
|
||||
.social-home
|
||||
.social-path-track.reveal.visible
|
||||
a:nth-child(4) {
|
||||
animation-delay: 0.22s !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .social-path-emoji {
|
||||
display: inline-block !important;
|
||||
transition: transform 0.25s !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"]
|
||||
.social-home
|
||||
.social-path-link:hover
|
||||
.social-path-emoji {
|
||||
animation: social-emoji-wiggle 0.5s ease !important;
|
||||
}
|
||||
|
||||
/* Meetup equalizer always on in immersive */
|
||||
.social-experience[data-immersive="true"] .connection-audio-bars i {
|
||||
animation: connection-audio 1.05s ease-in-out infinite !important;
|
||||
animation-play-state: running !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"]
|
||||
.social-home
|
||||
.connection-cafe
|
||||
.social-panel-ico {
|
||||
animation: social-ico-bounce 1.55s ease-in-out infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-chip-pop {
|
||||
animation: social-chip-in 0.5s cubic-bezier(0.2, 0.9, 0.2, 1.15) both !important;
|
||||
animation-delay: var(--stagger, 0ms) !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"]
|
||||
.social-people-chip.is-online
|
||||
.social-people-chip-ava {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"]
|
||||
.social-people-chip.is-online
|
||||
.social-people-chip-ava::before {
|
||||
content: "" !important;
|
||||
position: absolute !important;
|
||||
inset: -5px !important;
|
||||
border-radius: 999px !important;
|
||||
border: 2px solid rgba(78, 205, 196, 0.7) !important;
|
||||
animation: social-btn-ring 1.25s ease-out infinite !important;
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
/* Emoji belt */
|
||||
.social-experience[data-immersive="true"] .social-fx-belt {
|
||||
opacity: 1 !important;
|
||||
padding: 14px 0 22px !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-fx-belt-track {
|
||||
animation: social-belt-run 14s linear infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-fx-belt-track span {
|
||||
font-size: 1.65rem !important;
|
||||
opacity: 0.82 !important;
|
||||
letter-spacing: 0.45em !important;
|
||||
}
|
||||
|
||||
/* Join CTA ring */
|
||||
.social-experience[data-immersive="true"] .connection-join {
|
||||
position: relative !important;
|
||||
overflow: visible !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-join::after {
|
||||
content: "" !important;
|
||||
position: absolute !important;
|
||||
inset: -6px !important;
|
||||
border-radius: inherit !important;
|
||||
border: 2px solid rgba(255, 107, 107, 0.5) !important;
|
||||
animation: social-btn-ring 1.45s ease-out infinite !important;
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
/* Section spark always draws when visible */
|
||||
.social-experience[data-immersive="true"] .reveal.visible .social-spark-path {
|
||||
animation: social-spark-draw 1s ease forwards !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-spark-dot {
|
||||
animation: social-spark-blink 1.2s ease-in-out infinite !important;
|
||||
}
|
||||
|
||||
/* Panel lift */
|
||||
.social-experience[data-immersive="true"] .reveal.visible .social-panel-fx,
|
||||
.social-experience[data-immersive="true"] .social-panel-fx.reveal.visible {
|
||||
animation: social-panel-in 0.65s cubic-bezier(0.2, 0.8, 0.2, 1) both !important;
|
||||
animation-delay: var(--stagger, 0ms) !important;
|
||||
}
|
||||
|
||||
/*
|
||||
* Immersive is an explicit opt-in. It must beat OS prefers-reduced-motion
|
||||
* (Windows “显示动画” off, automation browsers, etc.). Light mode still respects reduce.
|
||||
*/
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.social-experience[data-immersive="true"] .social-constellation,
|
||||
.social-experience[data-immersive="true"] .social-pointer-glow {
|
||||
display: block !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-emoji-float {
|
||||
animation-name: social-emoji-fly !important;
|
||||
animation-timing-function: ease-in-out !important;
|
||||
animation-iteration-count: infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .social-fx-orb {
|
||||
animation: social-orb-drift 8s ease-in-out infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-fx-belt-track {
|
||||
animation: social-belt-run 14s linear infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-signal i {
|
||||
animation: social-signal-bars 1s ease-in-out infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-status-dot,
|
||||
.social-experience[data-immersive="true"] .connection-person-avatar > i {
|
||||
animation: social-live-ping 1.25s ease-out infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-orbit-traveler {
|
||||
animation-duration: 12s !important;
|
||||
animation-play-state: running !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-flight-path {
|
||||
animation-play-state: running !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-center-icon {
|
||||
animation: social-center-glow 2.4s ease-in-out infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-center-icon svg {
|
||||
animation: connection-breathe 2s ease-in-out infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .social-title-emoji {
|
||||
display: inline-block !important;
|
||||
animation: social-emoji-wiggle 1.6s ease-in-out infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .social-btn-pulse::before,
|
||||
.social-experience[data-immersive="true"] .social-home .social-btn-pulse::after,
|
||||
.social-experience[data-immersive="true"] .connection-join::after,
|
||||
.social-experience[data-immersive="true"]
|
||||
.social-people-chip.is-online
|
||||
.social-people-chip-ava::before {
|
||||
animation: social-btn-ring 1.4s ease-out infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .connection-audio-bars i {
|
||||
animation: connection-audio 1.05s ease-in-out infinite !important;
|
||||
animation-play-state: running !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .connection-cafe .social-panel-ico {
|
||||
animation: social-ico-bounce 1.55s ease-in-out infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .social-people-bar-avs img {
|
||||
animation: social-ava-bob 1.8s ease-in-out infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .social-count-pulse {
|
||||
animation: social-count-glow 1.15s ease-in-out infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-home .nav-logo .logo-icon {
|
||||
animation: social-logo-spin 6s linear infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-ambient i {
|
||||
animation: sx-aurora 18s ease-in-out infinite alternate !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .social-spark-dot {
|
||||
animation: social-spark-blink 1.2s ease-in-out infinite !important;
|
||||
}
|
||||
|
||||
.social-experience[data-immersive="true"] .reveal.visible .social-spark-path {
|
||||
animation: social-spark-draw 1s ease forwards !important;
|
||||
}
|
||||
}
|
||||
691
src/modules/social/app/studio.css
Normal file
691
src/modules/social/app/studio.css
Normal file
@ -0,0 +1,691 @@
|
||||
.social-fieldset {
|
||||
display: grid;
|
||||
gap: 18px;
|
||||
border: 0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
min-width: 0;
|
||||
}
|
||||
.social-fieldset:disabled {
|
||||
opacity: 0.7;
|
||||
}
|
||||
.social-profile-studio {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
|
||||
gap: 28px;
|
||||
align-items: start;
|
||||
}
|
||||
.social-profile-studio .social-form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
.social-profile-studio .social-section-label {
|
||||
margin-top: 0;
|
||||
}
|
||||
.social-profile-studio .social-form small {
|
||||
text-align: right;
|
||||
color: var(--text-muted);
|
||||
font-size: 10px;
|
||||
}
|
||||
.social-profile-preview {
|
||||
min-width: 0;
|
||||
padding: 12px 8px;
|
||||
}
|
||||
.social-profile-passport {
|
||||
position: relative;
|
||||
isolation: isolate;
|
||||
overflow: hidden;
|
||||
min-height: 415px;
|
||||
border: 1px solid #4ecdc43b;
|
||||
border-radius: 22px;
|
||||
padding: 31px;
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
color-mix(in srgb, var(--bg-secondary) 85%, #4ecdc4),
|
||||
var(--bg-secondary) 62%
|
||||
);
|
||||
box-shadow: 0 20px 55px #0002;
|
||||
transform: perspective(1000px) rotateY(-4deg) rotateX(2deg);
|
||||
transition:
|
||||
transform 0.6s var(--sx-ease),
|
||||
box-shadow 0.6s;
|
||||
}
|
||||
.social-profile-passport:hover {
|
||||
transform: perspective(1000px) rotateY(0) rotateX(0) translateY(-5px);
|
||||
box-shadow: 0 26px 65px #4ecdc415;
|
||||
}
|
||||
.social-passport-pattern {
|
||||
position: absolute;
|
||||
z-index: -1;
|
||||
color: #4ecdc430;
|
||||
top: 13px;
|
||||
right: -35px;
|
||||
animation: sx-orbit 90s linear infinite;
|
||||
}
|
||||
.social-profile-monogram {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
border: 1px solid #4ecdc443;
|
||||
border-radius: 18px;
|
||||
color: var(--sx-mint);
|
||||
font-size: 28px;
|
||||
background: #4ecdc40c;
|
||||
margin-bottom: 24px;
|
||||
box-shadow: 0 0 35px #4ecdc411;
|
||||
}
|
||||
.social-profile-passport .social-page-kicker {
|
||||
font-size: 8px;
|
||||
letter-spacing: 0.18em;
|
||||
}
|
||||
.social-profile-passport h2 {
|
||||
font-size: 30px;
|
||||
margin: 11px 0 6px;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.social-profile-passport > p {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
line-height: 1.9;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.social-profile-passport .social-member-city {
|
||||
margin: 15px 0;
|
||||
}
|
||||
.social-profile-passport .social-tags {
|
||||
margin: 16px 0;
|
||||
}
|
||||
.social-profile-passport .social-profile-bio {
|
||||
min-height: 55px;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
.social-profile-passport footer {
|
||||
margin-top: 25px;
|
||||
border-top: 1px dashed var(--sx-line);
|
||||
padding-top: 17px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 14px;
|
||||
font-size: 8px;
|
||||
letter-spacing: 0.15em;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.social-profile-passport footer span {
|
||||
font-size: 18px;
|
||||
color: var(--sx-coral);
|
||||
}
|
||||
.social-profile-progress {
|
||||
margin: 27px 0;
|
||||
}
|
||||
.social-profile-progress > div {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: 11px;
|
||||
margin-bottom: 9px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
.social-profile-progress strong {
|
||||
color: var(--sx-mint);
|
||||
}
|
||||
.social-profile-progress progress {
|
||||
width: 100%;
|
||||
height: 4px;
|
||||
appearance: none;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.social-profile-progress progress::-webkit-progress-bar {
|
||||
background: var(--bg-glass);
|
||||
}
|
||||
.social-profile-progress progress::-webkit-progress-value {
|
||||
background: var(--sx-mint);
|
||||
transition: width 0.6s var(--sx-ease);
|
||||
}
|
||||
.social-profile-progress p {
|
||||
font-size: 10px;
|
||||
color: var(--text-muted);
|
||||
margin-top: 9px;
|
||||
}
|
||||
.social-role-card {
|
||||
gap: 15px;
|
||||
}
|
||||
.social-role-symbol {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 54px;
|
||||
height: 54px;
|
||||
border-radius: 16px;
|
||||
border: 1px solid #4ecdc42b;
|
||||
color: var(--sx-mint);
|
||||
background: #4ecdc40c;
|
||||
transition:
|
||||
rotate 0.5s var(--sx-ease),
|
||||
scale 0.5s;
|
||||
}
|
||||
.social-role-symbol.tone-1 {
|
||||
color: var(--sx-coral);
|
||||
background: #ff6b6b0c;
|
||||
border-color: #ff6b6b2b;
|
||||
}
|
||||
.social-role-symbol.tone-2 {
|
||||
color: var(--sx-gold);
|
||||
background: #ffe1950c;
|
||||
border-color: #ffe1952b;
|
||||
}
|
||||
.social-role-card:hover .social-role-symbol {
|
||||
rotate: -7deg;
|
||||
scale: 1.08;
|
||||
}
|
||||
.social-role-type {
|
||||
font-size: 9px;
|
||||
letter-spacing: 0.1em;
|
||||
color: var(--sx-mint);
|
||||
}
|
||||
.social-role-card h2 {
|
||||
font-size: 19px;
|
||||
}
|
||||
.social-role-card > p {
|
||||
margin: 0;
|
||||
}
|
||||
.social-role-meta {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
padding-block: 13px;
|
||||
border-block: 1px solid var(--sx-line);
|
||||
font-size: 10px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
.social-role-meta > span:first-child {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
align-items: center;
|
||||
}
|
||||
.social-role-card .social-tags {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.social-role-card > .social-btn {
|
||||
margin-top: auto;
|
||||
}
|
||||
.social-library-card {
|
||||
padding: 16px !important;
|
||||
gap: 16px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.social-library-art {
|
||||
position: relative;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 100%;
|
||||
height: 205px;
|
||||
padding: 0;
|
||||
border: 1px solid var(--sx-line);
|
||||
border-radius: 13px;
|
||||
background:
|
||||
radial-gradient(ellipse at 80% 0%, #4ecdc42a, transparent 70%),
|
||||
linear-gradient(160deg, #15302e, #142231 70%);
|
||||
color: #e4f1ee;
|
||||
overflow: hidden;
|
||||
isolation: isolate;
|
||||
cursor: pointer;
|
||||
}
|
||||
.social-library-art.library-tone-1 {
|
||||
background:
|
||||
radial-gradient(ellipse at 80% 0%, #ff6b6b3b, transparent 70%),
|
||||
linear-gradient(160deg, #3c262a, #192534 70%);
|
||||
}
|
||||
.social-library-art.library-tone-2 {
|
||||
background:
|
||||
radial-gradient(ellipse at 80% 0%, #ffe19527, transparent 70%),
|
||||
linear-gradient(160deg, #333427, #172835 70%);
|
||||
}
|
||||
.social-library-number {
|
||||
position: absolute;
|
||||
top: 17px;
|
||||
left: 18px;
|
||||
font-size: 10px;
|
||||
font-family: monospace;
|
||||
letter-spacing: 0.15em;
|
||||
color: #fff7;
|
||||
}
|
||||
.social-film-scene {
|
||||
font-size: 63px;
|
||||
filter: drop-shadow(0 12px 18px #0004);
|
||||
transition: transform 0.65s var(--sx-ease);
|
||||
transform: rotate(-8deg);
|
||||
}
|
||||
.social-library-art:hover .social-film-scene {
|
||||
transform: rotate(6deg) scale(1.15) translateY(-7px);
|
||||
}
|
||||
.social-film-orbit {
|
||||
position: absolute;
|
||||
width: 230px;
|
||||
height: 230px;
|
||||
border: 1px solid #4ecdc42b;
|
||||
border-radius: 50%;
|
||||
transform: rotateX(58deg) rotate(-25deg);
|
||||
animation: social-film-drift 9s ease-in-out infinite alternate;
|
||||
}
|
||||
.social-film-orbit::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 25px;
|
||||
border: 1px dashed #ffffff20;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.social-film-grain {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
opacity: 0.4;
|
||||
background-image: radial-gradient(#fff4 0.6px, transparent 0.6px);
|
||||
background-size: 5px 5px;
|
||||
pointer-events: none;
|
||||
mask-image: linear-gradient(transparent, #000);
|
||||
}
|
||||
.social-film-play {
|
||||
position: absolute;
|
||||
right: 17px;
|
||||
bottom: 16px;
|
||||
width: 41px;
|
||||
height: 41px;
|
||||
border: 1px solid #ffffff40;
|
||||
border-radius: 50%;
|
||||
background: #ffffff0b;
|
||||
backdrop-filter: blur(7px);
|
||||
display: grid;
|
||||
place-items: center;
|
||||
transition:
|
||||
background 0.25s,
|
||||
scale 0.25s;
|
||||
}
|
||||
.social-library-art:hover .social-film-play {
|
||||
background: #4ecdc42a;
|
||||
scale: 1.1;
|
||||
}
|
||||
.social-library-art > small {
|
||||
position: absolute;
|
||||
left: 18px;
|
||||
bottom: 21px;
|
||||
font-size: 10px;
|
||||
color: #ffffffa8;
|
||||
}
|
||||
.social-library-meta {
|
||||
font-size: 10px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.social-library-card h2 {
|
||||
font-size: 18px;
|
||||
letter-spacing: -0.02em;
|
||||
padding-inline: 3px;
|
||||
}
|
||||
.social-library-card > p {
|
||||
padding-inline: 3px;
|
||||
min-height: 43px;
|
||||
}
|
||||
.social-library-card .social-card-actions {
|
||||
margin-top: auto;
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
.social-library-grid.is-books {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
.is-books .social-library-art {
|
||||
height: 265px;
|
||||
}
|
||||
.social-book-cover {
|
||||
width: 155px;
|
||||
height: 212px;
|
||||
border-radius: 2px 9px 9px 2px;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
#4ecdc438 0 4px,
|
||||
#0d302c 4px,
|
||||
#134a43 10px,
|
||||
#173b35 11px,
|
||||
#173b35 100%
|
||||
);
|
||||
box-shadow:
|
||||
-14px 15px 30px #0004,
|
||||
inset -4px 0 0 #ffffff12;
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 16px;
|
||||
color: #b7e0d2;
|
||||
transform: perspective(600px) rotateY(-14deg) rotateZ(-8deg);
|
||||
transition: transform 0.6s var(--sx-ease);
|
||||
}
|
||||
.library-tone-1 .social-book-cover {
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
#ff6b6b38 0 4px,
|
||||
#4a2327 4px,
|
||||
#612d34 10px,
|
||||
#4b2930 11px,
|
||||
#4b2930 100%
|
||||
);
|
||||
color: #eec3b4;
|
||||
}
|
||||
.social-library-art:hover .social-book-cover {
|
||||
transform: perspective(600px) rotateY(-2deg) rotateZ(0) translateY(-5px);
|
||||
}
|
||||
.social-book-cover small {
|
||||
font-size: 6px;
|
||||
letter-spacing: 0.15em;
|
||||
}
|
||||
.social-book-cover strong {
|
||||
font-size: 20px;
|
||||
font-weight: 500;
|
||||
line-height: 1.5;
|
||||
text-align: left;
|
||||
}
|
||||
.social-book-cover > span {
|
||||
font-size: 5px;
|
||||
margin-top: auto;
|
||||
letter-spacing: 0.12em;
|
||||
}
|
||||
.social-resource-player {
|
||||
width: 100%;
|
||||
border-radius: 12px;
|
||||
margin-bottom: 20px;
|
||||
background: #000;
|
||||
max-height: 360px;
|
||||
}
|
||||
.social-library-prompt {
|
||||
padding: 20px;
|
||||
border: 1px solid var(--sx-line);
|
||||
border-radius: 12px;
|
||||
background: #4ecdc406;
|
||||
}
|
||||
.social-library-prompt span {
|
||||
display: block;
|
||||
font-size: 10px;
|
||||
color: var(--sx-mint);
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.social-library-prompt strong {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
line-height: 1.8;
|
||||
}
|
||||
.social-feedback-panel {
|
||||
max-width: 800px;
|
||||
margin: auto;
|
||||
}
|
||||
.social-feedback-heading {
|
||||
display: flex;
|
||||
gap: 19px;
|
||||
align-items: center;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
.social-feedback-heart {
|
||||
color: var(--sx-coral);
|
||||
width: 65px;
|
||||
height: 65px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
border: 1px solid #ff6b6b30;
|
||||
border-radius: 19px;
|
||||
background: #ff6b6b07;
|
||||
flex-shrink: 0;
|
||||
animation: sx-breathe 4s ease-in-out infinite;
|
||||
}
|
||||
.social-feedback-heading h2 {
|
||||
font-size: 21px;
|
||||
margin-bottom: 9px;
|
||||
}
|
||||
.social-feedback-heading p {
|
||||
color: var(--text-muted);
|
||||
font-size: 12px;
|
||||
line-height: 1.8;
|
||||
}
|
||||
.social-welcome-banner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 24px;
|
||||
padding: 30px;
|
||||
margin-bottom: 25px;
|
||||
border: 1px solid #4ecdc432;
|
||||
border-radius: 18px;
|
||||
background: linear-gradient(110deg, #4ecdc40c, transparent);
|
||||
}
|
||||
.social-welcome-banner h2 {
|
||||
font-size: 21px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.social-welcome-banner p {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
line-height: 1.8;
|
||||
}
|
||||
.social-welcome-banner .social-btn {
|
||||
margin-left: auto;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.social-welcome-faces {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
width: 85px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.social-welcome-faces span {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 39px;
|
||||
height: 39px;
|
||||
border-radius: 50%;
|
||||
border: 1px solid var(--sx-line);
|
||||
background: var(--bg-secondary);
|
||||
font-size: 19px;
|
||||
margin: -2px;
|
||||
animation: social-welcome-bob 4s ease-in-out infinite alternate;
|
||||
}
|
||||
.social-welcome-faces span:nth-child(2n) {
|
||||
animation-delay: -2s;
|
||||
}
|
||||
.social-onboarding-card {
|
||||
gap: 18px;
|
||||
}
|
||||
.social-onboarding-card .social-card-top {
|
||||
color: var(--sx-mint);
|
||||
}
|
||||
.social-onboarding-card .social-card-top > span {
|
||||
font-family: monospace;
|
||||
font-size: 27px;
|
||||
color: var(--text-muted);
|
||||
opacity: 0.4;
|
||||
}
|
||||
.social-onboarding-card h2 {
|
||||
font-size: 19px;
|
||||
}
|
||||
.social-onboarding-card .social-btn {
|
||||
margin-top: auto;
|
||||
}
|
||||
.social-membership-banner {
|
||||
display: flex;
|
||||
gap: 45px;
|
||||
align-items: center;
|
||||
border: 1px solid #ffe19533;
|
||||
border-radius: 21px;
|
||||
padding: 50px;
|
||||
background:
|
||||
radial-gradient(ellipse at 0% 20%, #ffe1950d, transparent 65%),
|
||||
var(--sx-surface);
|
||||
}
|
||||
.social-membership-emblem {
|
||||
width: 155px;
|
||||
height: 155px;
|
||||
flex-shrink: 0;
|
||||
position: relative;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
color: var(--sx-gold);
|
||||
border: 1px solid #ffe19525;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.social-membership-emblem i {
|
||||
position: absolute;
|
||||
inset: 10px;
|
||||
border: 1px dashed #ffe19535;
|
||||
border-radius: 50%;
|
||||
animation: sx-orbit 25s linear infinite;
|
||||
}
|
||||
.social-membership-emblem i:last-child {
|
||||
inset: 28px;
|
||||
animation-direction: reverse;
|
||||
}
|
||||
.social-membership-emblem::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 36px;
|
||||
border-radius: 50%;
|
||||
box-shadow: 0 0 60px #ffe19515;
|
||||
}
|
||||
.social-membership-banner h2 {
|
||||
font-size: 30px;
|
||||
margin: 15px 0;
|
||||
letter-spacing: -0.03em;
|
||||
}
|
||||
.social-membership-banner p {
|
||||
font-size: 13px;
|
||||
line-height: 1.9;
|
||||
color: var(--text-secondary);
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
.social-membership-banner .social-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
.social-membership-card {
|
||||
gap: 18px;
|
||||
}
|
||||
.social-membership-card > svg {
|
||||
color: var(--sx-gold);
|
||||
}
|
||||
.social-membership-card h2 {
|
||||
font-size: 17px;
|
||||
}
|
||||
.social-membership-card > span {
|
||||
margin-top: auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 12px;
|
||||
color: var(--sx-mint);
|
||||
}
|
||||
@keyframes social-film-drift {
|
||||
to {
|
||||
transform: rotateX(45deg) rotate(10deg);
|
||||
scale: 1.1;
|
||||
}
|
||||
}
|
||||
@keyframes social-welcome-bob {
|
||||
to {
|
||||
translate: 0 -6px;
|
||||
rotate: 7deg;
|
||||
}
|
||||
}
|
||||
@media (max-width: 900px) {
|
||||
.social-profile-studio {
|
||||
gap: 20px;
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.social-profile-preview {
|
||||
max-width: 550px;
|
||||
width: 100%;
|
||||
margin: auto;
|
||||
}
|
||||
.social-welcome-banner {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.social-welcome-banner .social-btn {
|
||||
margin-left: 0;
|
||||
}
|
||||
.social-membership-banner {
|
||||
padding: 30px;
|
||||
gap: 26px;
|
||||
}
|
||||
.social-membership-emblem {
|
||||
width: 115px;
|
||||
height: 115px;
|
||||
}
|
||||
}
|
||||
@media (max-width: 600px) {
|
||||
.social-profile-studio .social-form-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.social-profile-passport {
|
||||
transform: none;
|
||||
padding: 25px;
|
||||
}
|
||||
.social-library-grid.is-books {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.social-feedback-heading {
|
||||
align-items: flex-start;
|
||||
gap: 13px;
|
||||
}
|
||||
.social-feedback-heading h2 {
|
||||
font-size: 18px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.social-feedback-heart {
|
||||
width: 45px;
|
||||
height: 45px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
.social-feedback-heart svg {
|
||||
width: 24px;
|
||||
}
|
||||
.social-welcome-banner {
|
||||
padding: 22px;
|
||||
gap: 20px;
|
||||
}
|
||||
.social-welcome-banner h2 {
|
||||
font-size: 19px;
|
||||
}
|
||||
.social-membership-banner {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
padding: 25px;
|
||||
}
|
||||
.social-membership-banner h2 {
|
||||
font-size: 25px;
|
||||
}
|
||||
.social-membership-emblem {
|
||||
width: 95px;
|
||||
height: 95px;
|
||||
}
|
||||
.social-membership-emblem svg {
|
||||
width: 36px;
|
||||
}
|
||||
.social-library-art {
|
||||
height: 210px;
|
||||
}
|
||||
.social-profile-preview > .social-btn {
|
||||
width: 100%;
|
||||
}
|
||||
.social-filters button,
|
||||
.social-save,
|
||||
.social-room-channels a {
|
||||
min-height: 44px;
|
||||
}
|
||||
.social-message-tools button {
|
||||
min-height: 40px;
|
||||
font-size: 11px;
|
||||
}
|
||||
.social-fx-control {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
min-height: 44px;
|
||||
}
|
||||
.social-search button {
|
||||
min-width: 32px;
|
||||
min-height: 42px;
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,40 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import {
|
||||
useEffect,
|
||||
useId,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
useSyncExternalStore,
|
||||
} from "react";
|
||||
import { MOCK_ROSTER, type SocialRosterMember } from "@social/lib/rosterMock";
|
||||
import { loadJson, saveJson } from "@social/lib/storage";
|
||||
import SocialAvatar from "./SocialAvatar";
|
||||
import SectionSpark from "./SectionSpark";
|
||||
|
||||
const LIKE_KEY = "social-roster-likes";
|
||||
const LIKES_CHANGED = "social-roster-likes-changed";
|
||||
|
||||
function subscribeLikes(callback: () => void) {
|
||||
window.addEventListener("storage", callback);
|
||||
window.addEventListener(LIKES_CHANGED, callback);
|
||||
return () => {
|
||||
window.removeEventListener("storage", callback);
|
||||
window.removeEventListener(LIKES_CHANGED, callback);
|
||||
};
|
||||
}
|
||||
|
||||
function getLikesSnapshot() {
|
||||
const stored = loadJson<unknown>(LIKE_KEY, {});
|
||||
return JSON.stringify(
|
||||
stored && typeof stored === "object" && !Array.isArray(stored)
|
||||
? stored
|
||||
: {},
|
||||
);
|
||||
}
|
||||
|
||||
const getServerLikes = () => "{}";
|
||||
|
||||
const FILTERS = [
|
||||
{ id: "all" as const, label: "全部", emoji: "✨" },
|
||||
@ -14,15 +44,44 @@ const FILTERS = [
|
||||
];
|
||||
|
||||
export default function AttractiveRoster({ onJoin }: { onJoin: () => void }) {
|
||||
const [likes, setLikes] = useState<Record<string, boolean>>({});
|
||||
const likesSnapshot = useSyncExternalStore(
|
||||
subscribeLikes,
|
||||
getLikesSnapshot,
|
||||
getServerLikes,
|
||||
);
|
||||
const likes = useMemo(
|
||||
() => JSON.parse(likesSnapshot) as Record<string, boolean>,
|
||||
[likesSnapshot],
|
||||
);
|
||||
const [filter, setFilter] = useState<"all" | "online" | "f" | "m">("all");
|
||||
const [activeId, setActiveId] = useState<string | null>(null);
|
||||
const [burst, setBurst] = useState(false);
|
||||
const burstTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const filterId = useId();
|
||||
|
||||
useEffect(() => {
|
||||
setLikes(loadJson<Record<string, boolean>>(LIKE_KEY, {}));
|
||||
const selectMember = (event: Event) => {
|
||||
const id: unknown = (event as CustomEvent).detail;
|
||||
if (
|
||||
typeof id !== "string" ||
|
||||
!MOCK_ROSTER.some((member) => member.id === id)
|
||||
)
|
||||
return;
|
||||
setFilter("all");
|
||||
setActiveId(id);
|
||||
};
|
||||
window.addEventListener("nomadro-social-select-member", selectMember);
|
||||
return () =>
|
||||
window.removeEventListener("nomadro-social-select-member", selectMember);
|
||||
}, []);
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
if (burstTimer.current) clearTimeout(burstTimer.current);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
const list = useMemo(() => {
|
||||
return MOCK_ROSTER.filter((m) => {
|
||||
if (filter === "online") return m.online;
|
||||
@ -35,63 +94,105 @@ export default function AttractiveRoster({ onJoin }: { onJoin: () => void }) {
|
||||
const active = list.find((m) => m.id === activeId) || null;
|
||||
|
||||
const toggleLike = (m: SocialRosterMember) => {
|
||||
setLikes((prev) => {
|
||||
const next = { ...prev, [m.id]: !prev[m.id] };
|
||||
saveJson(LIKE_KEY, next);
|
||||
return next;
|
||||
});
|
||||
saveJson(LIKE_KEY, { ...likes, [m.id]: !likes[m.id] });
|
||||
window.dispatchEvent(new Event(LIKES_CHANGED));
|
||||
setBurst(true);
|
||||
window.setTimeout(() => setBurst(false), 700);
|
||||
if (burstTimer.current) clearTimeout(burstTimer.current);
|
||||
burstTimer.current = setTimeout(() => setBurst(false), 700);
|
||||
};
|
||||
|
||||
return (
|
||||
<section className="section section-compact" id="people" aria-label="在线游民">
|
||||
<section
|
||||
className="section section-compact"
|
||||
id="people"
|
||||
aria-label="在线游民"
|
||||
>
|
||||
<div className="container">
|
||||
<div className="section-header reveal">
|
||||
<span className="section-tag">PEOPLE</span>
|
||||
<SectionSpark label="people" />
|
||||
<span className="section-tag">
|
||||
<span>01 / FIND YOUR PEOPLE</span>
|
||||
<span>有相似的热爱,也有不同的精彩</span>
|
||||
</span>
|
||||
<h2>
|
||||
<span className="social-title-emoji" aria-hidden>
|
||||
👋
|
||||
</span>
|
||||
这些人,也许你会想见
|
||||
</h2>
|
||||
<p>点选查看简介 · 关注本地记录 · 加群再认识真人。</p>
|
||||
<p>从好奇一个人的生活开始,让下一次相遇自然发生。</p>
|
||||
</div>
|
||||
|
||||
<div className="social-people-bar reveal">
|
||||
<div className="social-people-bar-avs" aria-hidden>
|
||||
{online.slice(0, 6).map((m) => (
|
||||
<img key={m.id} src={m.avatar} alt="" />
|
||||
<SocialAvatar key={m.id} src={m.avatar} size={30} lazy />
|
||||
))}
|
||||
</div>
|
||||
<p>
|
||||
<strong className="social-count-pulse">{online.length}</strong> 位演示在线
|
||||
<strong className="social-count-pulse">{online.length}</strong>{" "}
|
||||
位演示在线
|
||||
<span> · 非实时统计</span>
|
||||
</p>
|
||||
<button type="button" className="btn btn-primary btn-sm social-btn-pulse" onClick={onJoin}>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary btn-sm social-btn-pulse"
|
||||
onClick={onJoin}
|
||||
>
|
||||
加群认识
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="social-people-filters reveal" role="tablist" aria-label="筛选">
|
||||
{FILTERS.map((f) => (
|
||||
<div
|
||||
className="social-people-filters reveal"
|
||||
role="tablist"
|
||||
aria-label="筛选"
|
||||
>
|
||||
{FILTERS.map((f, index) => (
|
||||
<button
|
||||
key={f.id}
|
||||
type="button"
|
||||
role="tab"
|
||||
id={`${filterId}-${f.id}`}
|
||||
aria-controls={`${filterId}-panel`}
|
||||
aria-selected={filter === f.id}
|
||||
tabIndex={filter === f.id ? 0 : -1}
|
||||
className={`social-people-filter${filter === f.id ? " active" : ""}`}
|
||||
onClick={() => {
|
||||
setFilter(f.id);
|
||||
setActiveId(null);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
const key = event.key;
|
||||
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(key))
|
||||
return;
|
||||
event.preventDefault();
|
||||
const nextIndex =
|
||||
key === "Home"
|
||||
? 0
|
||||
: key === "End"
|
||||
? FILTERS.length - 1
|
||||
: (index +
|
||||
(key === "ArrowRight" ? 1 : -1) +
|
||||
FILTERS.length) %
|
||||
FILTERS.length;
|
||||
const next = FILTERS[nextIndex];
|
||||
setFilter(next.id);
|
||||
setActiveId(null);
|
||||
document.getElementById(`${filterId}-${next.id}`)?.focus();
|
||||
}}
|
||||
>
|
||||
<span aria-hidden>{f.emoji}</span> {f.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="social-people-grid">
|
||||
<div
|
||||
className="social-people-grid"
|
||||
id={`${filterId}-panel`}
|
||||
role="tabpanel"
|
||||
aria-labelledby={`${filterId}-${filter}`}
|
||||
>
|
||||
{list.map((m, i) => (
|
||||
<button
|
||||
key={m.id}
|
||||
@ -102,7 +203,7 @@ export default function AttractiveRoster({ onJoin }: { onJoin: () => void }) {
|
||||
aria-pressed={activeId === m.id}
|
||||
>
|
||||
<span className="social-people-chip-ava">
|
||||
<img src={m.avatar} alt="" loading="lazy" width={52} height={52} />
|
||||
<SocialAvatar src={m.avatar} size={52} lazy />
|
||||
{m.online ? <i aria-hidden /> : null}
|
||||
{likes[m.id] ? (
|
||||
<em className="social-chip-heart" aria-hidden>
|
||||
@ -111,19 +212,23 @@ export default function AttractiveRoster({ onJoin }: { onJoin: () => void }) {
|
||||
) : null}
|
||||
</span>
|
||||
<strong>{m.name}</strong>
|
||||
<span className="connection-member-role">{m.title}</span>
|
||||
<em>{m.city.split("·")[0].trim()}</em>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{active ? (
|
||||
<div className={`social-people-detail social-detail-in reveal visible${burst ? " is-burst" : ""}`} role="status">
|
||||
<div
|
||||
className={`social-people-detail social-detail-in reveal visible${burst ? " is-burst" : ""}`}
|
||||
role="status"
|
||||
>
|
||||
{burst ? (
|
||||
<span className="social-burst" aria-hidden>
|
||||
✨💫💖
|
||||
</span>
|
||||
) : null}
|
||||
<img src={active.avatar} alt="" width={44} height={44} />
|
||||
<SocialAvatar src={active.avatar} size={44} />
|
||||
<div>
|
||||
<strong>
|
||||
{active.name}
|
||||
@ -147,17 +252,27 @@ export default function AttractiveRoster({ onJoin }: { onJoin: () => void }) {
|
||||
>
|
||||
{likes[active.id] ? "♥ 已关注" : "♡ 关注"}
|
||||
</button>
|
||||
<button type="button" className="btn btn-primary btn-sm social-btn-pulse" onClick={onJoin}>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary btn-sm social-btn-pulse"
|
||||
onClick={onJoin}
|
||||
>
|
||||
打招呼 👋
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<p className="social-people-hint">👆 点选一位,看 TA 想认识什么样的人</p>
|
||||
<p className="social-people-hint">
|
||||
👆 点选一位,看 TA 想认识什么样的人
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="social-section-actions reveal">
|
||||
<button type="button" className="btn btn-primary social-btn-pulse" onClick={onJoin}>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary social-btn-pulse"
|
||||
onClick={onJoin}
|
||||
>
|
||||
加群,认识他们 ✨
|
||||
</button>
|
||||
</div>
|
||||
|
||||
398
src/modules/social/components/CafeDirectory.tsx
Normal file
398
src/modules/social/components/CafeDirectory.tsx
Normal file
@ -0,0 +1,398 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
useEffect,
|
||||
useId,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
useSyncExternalStore,
|
||||
type FormEvent,
|
||||
} from "react";
|
||||
import Link from "next/link";
|
||||
import {
|
||||
ArrowUpRight,
|
||||
Coffee,
|
||||
MapPin,
|
||||
MessageCircle,
|
||||
Plug,
|
||||
Star,
|
||||
Wifi,
|
||||
} from "lucide-react";
|
||||
import SiteShell from "./SiteShell";
|
||||
import {
|
||||
BookmarkButton,
|
||||
EmptyState,
|
||||
PageIntro,
|
||||
SearchField,
|
||||
ShareButton,
|
||||
} from "./SocialUI";
|
||||
import { SEED_CAFES } from "@social/lib/seed";
|
||||
import { socialApi } from "@social/lib/api";
|
||||
import { useLocalState } from "@social/lib/useLocalState";
|
||||
import { uid } from "@social/lib/storage";
|
||||
import type { SocialCafe, SocialCafeReview } from "@social/lib/types";
|
||||
|
||||
type Review = SocialCafeReview & { local?: boolean };
|
||||
|
||||
function subscribeHash(callback: () => void) {
|
||||
window.addEventListener("hashchange", callback);
|
||||
window.addEventListener("popstate", callback);
|
||||
return () => {
|
||||
window.removeEventListener("hashchange", callback);
|
||||
window.removeEventListener("popstate", callback);
|
||||
};
|
||||
}
|
||||
|
||||
function CafeDetail({ cafe, id }: { cafe: SocialCafe; id: string }) {
|
||||
const [reviews, setReviews] = useLocalState<Review[]>(
|
||||
`cafe-reviews:${cafe.id}`,
|
||||
[],
|
||||
);
|
||||
const [author, setAuthor] = useLocalState("nick", "游民");
|
||||
const [score, setScore] = useState(5);
|
||||
const [text, setText] = useState("");
|
||||
const [status, setStatus] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const lock = useRef(false);
|
||||
const textRef = useRef(text);
|
||||
textRef.current = text;
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
void socialApi
|
||||
.listReviews(cafe.id)
|
||||
.then((response) => {
|
||||
if (!active) return;
|
||||
setReviews((current) => [
|
||||
...(response.items || []),
|
||||
...current.filter((review) => review.local),
|
||||
]);
|
||||
setStatus("评价已连接社区。");
|
||||
})
|
||||
.catch(() => {
|
||||
if (active)
|
||||
setStatus("当前离线:本机评价尚未送达社区,可联网后手动重试。");
|
||||
});
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, [cafe.id, setReviews]);
|
||||
const submit = async (event?: FormEvent, retry?: Review) => {
|
||||
event?.preventDefault();
|
||||
const payload = retry
|
||||
? { author: retry.author, score: retry.score, text: retry.text }
|
||||
: { author: author.trim() || "游民", score, text: text.trim() };
|
||||
if (!payload.text || lock.current) return;
|
||||
lock.current = true;
|
||||
setBusy(true);
|
||||
try {
|
||||
await socialApi.postReview(cafe.id, payload);
|
||||
if (retry)
|
||||
setReviews((current) =>
|
||||
current.filter((review) => review.id !== retry.id),
|
||||
);
|
||||
void socialApi
|
||||
.listReviews(cafe.id)
|
||||
.then((response) => {
|
||||
setReviews((current) => [
|
||||
...(response.items || []),
|
||||
...current.filter((review) => review.local),
|
||||
]);
|
||||
})
|
||||
.catch(() =>
|
||||
setStatus("评价已发布;列表暂未刷新,请稍后重新打开查看。"),
|
||||
);
|
||||
setStatus("评价已发布,谢谢你分享真实体验。");
|
||||
if (!retry && textRef.current.trim() === payload.text) setText("");
|
||||
} catch {
|
||||
if (!retry)
|
||||
setReviews((current) => [
|
||||
{
|
||||
id: uid("local_review"),
|
||||
cafeId: cafe.id,
|
||||
...payload,
|
||||
at: new Date().toISOString(),
|
||||
local: true,
|
||||
},
|
||||
...current,
|
||||
]);
|
||||
setStatus("已保存到本机,尚未发布。联网后可点击评价下方的「重试发布」。");
|
||||
if (!retry && textRef.current.trim() === payload.text) setText("");
|
||||
} finally {
|
||||
lock.current = false;
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
const invitation = `有朋友想在${cafe.city}的 ${cafe.name} 喝杯咖啡聊聊吗?想交流远程工作和最近的生活。`;
|
||||
return (
|
||||
<section className="social-panel social-cafe-detail" id={id}>
|
||||
<div className="social-section-label">
|
||||
<span>THE NEXT COFFEE COULD CHANGE EVERYTHING</span>
|
||||
<ShareButton
|
||||
path={`/social/coffeechat#${cafe.id}`}
|
||||
title={`${cafe.city} · ${cafe.name}`}
|
||||
/>
|
||||
</div>
|
||||
<h2>{cafe.name}</h2>
|
||||
<p className="social-muted">
|
||||
{cafe.city} · {cafe.vibe}
|
||||
</p>
|
||||
<div className="social-cafe-facts">
|
||||
<span>
|
||||
<Wifi size={15} />
|
||||
{cafe.wifiMbps} Mbps
|
||||
</span>
|
||||
<span>
|
||||
<Plug size={15} />
|
||||
{cafe.power}
|
||||
</span>
|
||||
<span>
|
||||
<Star size={15} />
|
||||
目录评分 {cafe.rating}
|
||||
</span>
|
||||
</div>
|
||||
<Link
|
||||
className="social-btn primary"
|
||||
href={`/social/chat/coffee?intro=${encodeURIComponent(invitation)}`}
|
||||
>
|
||||
<MessageCircle size={15} />
|
||||
发起公开 Coffeechat 邀约 <ArrowUpRight size={15} />
|
||||
</Link>
|
||||
<p className="social-muted social-cafe-invite-note">
|
||||
先在公开频道交流时间与人数,确认后再安排见面。
|
||||
</p>
|
||||
<div className="social-review-layout">
|
||||
<div>
|
||||
<h3>真实体验,让下一次约见更轻松。</h3>
|
||||
<form
|
||||
className="social-form"
|
||||
onSubmit={(event) => void submit(event)}
|
||||
>
|
||||
<label>
|
||||
你的名字
|
||||
<input
|
||||
value={author}
|
||||
onChange={(event) => setAuthor(event.target.value)}
|
||||
maxLength={40}
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<fieldset className="social-star-rating">
|
||||
<legend>你的评分</legend>
|
||||
{[1, 2, 3, 4, 5].map((value) => (
|
||||
<button
|
||||
type="button"
|
||||
key={value}
|
||||
aria-label={`评分 ${value} 星`}
|
||||
aria-pressed={score === value}
|
||||
onClick={() => setScore(value)}
|
||||
className={value <= score ? "selected" : ""}
|
||||
>
|
||||
<Star
|
||||
size={23}
|
||||
fill={value <= score ? "currentColor" : "none"}
|
||||
/>
|
||||
</button>
|
||||
))}
|
||||
</fieldset>
|
||||
<label>
|
||||
分享一次真实体验
|
||||
<textarea
|
||||
required
|
||||
rows={4}
|
||||
maxLength={1000}
|
||||
value={text}
|
||||
onChange={(event) => setText(event.target.value)}
|
||||
placeholder="网络稳定吗?插座够不够?适合安静工作还是深聊?"
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
type="submit"
|
||||
className="social-btn"
|
||||
disabled={busy || !text.trim()}
|
||||
>
|
||||
{busy ? "正在提交…" : "发布评价"}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<div>
|
||||
<div className="social-section-label">
|
||||
社区评价 <span>{reviews.length} 条(含本机未发布)</span>
|
||||
</div>
|
||||
{!reviews.length ? (
|
||||
<EmptyState
|
||||
title="第一条真实评价,从你开始"
|
||||
description="你的一个小建议,可能帮下一位游民找到熟悉感。"
|
||||
/>
|
||||
) : (
|
||||
<div className="social-review-list">
|
||||
{reviews.map((review) => (
|
||||
<article key={review.id}>
|
||||
<header>
|
||||
<strong>{review.author}</strong>
|
||||
<span>
|
||||
{"★".repeat(Math.max(1, Math.min(5, review.score)))}
|
||||
</span>
|
||||
</header>
|
||||
<p>{review.text}</p>
|
||||
<small suppressHydrationWarning>
|
||||
{new Date(review.at).toLocaleDateString()}
|
||||
</small>
|
||||
{review.local && (
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy}
|
||||
onClick={() => void submit(undefined, review)}
|
||||
>
|
||||
仅本机 · 重试发布
|
||||
</button>
|
||||
)}
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{status && (
|
||||
<p
|
||||
className={`social-status${status.includes("本机") ? " warn" : ""}`}
|
||||
role="status"
|
||||
>
|
||||
{status}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export default function CafeDirectory() {
|
||||
const [query, setQuery] = useState("");
|
||||
const [city, setCity] = useState("all");
|
||||
const [sort, setSort] = useState("recommended");
|
||||
const selected =
|
||||
useSyncExternalStore(
|
||||
subscribeHash,
|
||||
() => location.hash.slice(1),
|
||||
() => "",
|
||||
) || SEED_CAFES[0].id;
|
||||
const [saved] = useLocalState<string[]>("saved-cafes", []);
|
||||
const id = useId();
|
||||
const cafes = useMemo(
|
||||
() =>
|
||||
SEED_CAFES.filter(
|
||||
(cafe) =>
|
||||
(city === "all" || cafe.city === city) &&
|
||||
(sort !== "saved" || saved.includes(cafe.id)) &&
|
||||
`${cafe.name} ${cafe.city} ${cafe.vibe}`
|
||||
.toLowerCase()
|
||||
.includes(query.toLowerCase()),
|
||||
).sort((a, b) =>
|
||||
sort === "wifi"
|
||||
? b.wifiMbps - a.wifiMbps
|
||||
: sort === "rating"
|
||||
? b.rating - a.rating
|
||||
: 0,
|
||||
),
|
||||
[query, city, sort, saved],
|
||||
);
|
||||
const active = cafes.find((cafe) => cafe.id === selected) || cafes[0];
|
||||
return (
|
||||
<SiteShell title="Coffeechat">
|
||||
<PageIntro
|
||||
eyebrow="GOOD COFFEE. BETTER COMPANY."
|
||||
title="先约一杯咖啡,"
|
||||
accent="再把网友变成朋友。"
|
||||
description="找一个有插座、有好咖啡,也容得下好对话的地方。按城市找店,把下一次见面安排得更轻松。"
|
||||
/>
|
||||
<div className="social-toolbar">
|
||||
<SearchField
|
||||
value={query}
|
||||
onChange={setQuery}
|
||||
label="搜索咖啡馆"
|
||||
placeholder="搜索店名、城市、氛围…"
|
||||
/>
|
||||
<select
|
||||
aria-label="咖啡馆排序"
|
||||
className="social-select"
|
||||
value={sort}
|
||||
onChange={(event) => setSort(event.target.value)}
|
||||
>
|
||||
<option value="recommended">目录顺序</option>
|
||||
<option value="wifi">网络优先</option>
|
||||
<option value="rating">评分优先</option>
|
||||
<option value="saved">我的收藏</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="social-filters social-city-filters">
|
||||
{["all", ...new Set(SEED_CAFES.map((cafe) => cafe.city))].map(
|
||||
(value) => (
|
||||
<button
|
||||
type="button"
|
||||
className={city === value ? "active" : ""}
|
||||
aria-pressed={city === value}
|
||||
key={value}
|
||||
onClick={() => setCity(value)}
|
||||
>
|
||||
{value === "all" ? "所有城市" : value}
|
||||
</button>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
<div className="social-section-label">
|
||||
把相遇放进日常{" "}
|
||||
<span>地点与评分为种子目录参考,出发前请核实营业信息。</span>
|
||||
</div>
|
||||
<div className="social-grid social-cafe-grid">
|
||||
{cafes.map((cafe, index) => (
|
||||
<article
|
||||
key={cafe.id}
|
||||
id={cafe.id}
|
||||
className={`social-card cafe-color-${index % 4}${active?.id === cafe.id ? " active" : ""}`}
|
||||
>
|
||||
<div className="social-cafe-art" aria-hidden="true">
|
||||
<Coffee size={45} strokeWidth={1} />
|
||||
<i />
|
||||
<span>{cafe.city}</span>
|
||||
</div>
|
||||
<div className="social-card-top">
|
||||
<span className="social-member-city">
|
||||
<MapPin size={12} />
|
||||
{cafe.city}
|
||||
</span>
|
||||
<BookmarkButton id={cafe.id} collection="saved-cafes" />
|
||||
</div>
|
||||
<strong>{cafe.name}</strong>
|
||||
<p>{cafe.vibe}</p>
|
||||
<div className="social-tags">
|
||||
<span>★ {cafe.rating}</span>
|
||||
<span>WiFi {cafe.wifiMbps}M</span>
|
||||
<span>{cafe.partners ? "合作目录" : "社区收录"}</span>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="social-btn"
|
||||
aria-pressed={active?.id === cafe.id}
|
||||
aria-controls={id}
|
||||
onClick={() => {
|
||||
history.replaceState(null, "", `#${cafe.id}`);
|
||||
window.dispatchEvent(new Event("hashchange"));
|
||||
document.getElementById(id)?.scrollIntoView({
|
||||
behavior: matchMedia("(prefers-reduced-motion: reduce)")
|
||||
.matches
|
||||
? "instant"
|
||||
: "smooth",
|
||||
block: "start",
|
||||
});
|
||||
}}
|
||||
>
|
||||
{active?.id === cafe.id ? "正在查看" : "看看这里"}
|
||||
<ArrowUpRight size={14} />
|
||||
</button>
|
||||
</article>
|
||||
))}
|
||||
{!cafes.length && <EmptyState />}
|
||||
</div>
|
||||
{active && <CafeDetail key={active.id} cafe={active} id={id} />}
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
102
src/modules/social/components/ChannelDirectory.tsx
Normal file
102
src/modules/social/components/ChannelDirectory.tsx
Normal file
@ -0,0 +1,102 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import Link from "next/link";
|
||||
import {
|
||||
ArrowUpRight,
|
||||
Coffee,
|
||||
Hash,
|
||||
MessageCircle,
|
||||
Radio,
|
||||
Sparkles,
|
||||
} from "lucide-react";
|
||||
import SiteShell from "./SiteShell";
|
||||
import { BookmarkButton, EmptyState, PageIntro, SearchField } from "./SocialUI";
|
||||
import { SEED_CHANNELS } from "@social/lib/seed";
|
||||
import { socialPath } from "@social/lib/socialPath";
|
||||
|
||||
const ICONS = [MessageCircle, Sparkles, Radio, Coffee];
|
||||
const STARTERS = [
|
||||
"大家好,第一次加入!你们都在哪座城市远程工作?",
|
||||
"最近在找适合办公的咖啡馆,有什么宝藏推荐?",
|
||||
"最近在做一个小项目,有想一起交流产品的朋友吗?",
|
||||
];
|
||||
export default function ChannelDirectory() {
|
||||
const [query, setQuery] = useState("");
|
||||
const channels = SEED_CHANNELS.filter((item) =>
|
||||
`${item.name} ${item.topic}`.toLowerCase().includes(query.toLowerCase()),
|
||||
);
|
||||
return (
|
||||
<SiteShell title="话题聊天室">
|
||||
<PageIntro
|
||||
eyebrow="CONVERSATIONS THAT CONNECT"
|
||||
title="一句你好,"
|
||||
accent="打开一整个世界。"
|
||||
description="聊远程工作,交换城市情报,分享一个今天的小发现。公开频道里,总有一段对话值得你加入。"
|
||||
/>
|
||||
<div className="social-toolbar">
|
||||
<SearchField
|
||||
value={query}
|
||||
onChange={setQuery}
|
||||
placeholder="搜索城市、频道或话题…"
|
||||
label="搜索频道"
|
||||
/>
|
||||
<span className="social-muted">{channels.length} 个话题频道</span>
|
||||
</div>
|
||||
<div className="social-grid social-channel-grid">
|
||||
{channels.map((channel) => {
|
||||
const index = SEED_CHANNELS.findIndex(
|
||||
(item) => item.id === channel.id,
|
||||
);
|
||||
const Icon = ICONS[index % ICONS.length];
|
||||
return (
|
||||
<article
|
||||
className={`social-card social-channel-card channel-${index}`}
|
||||
key={channel.id}
|
||||
>
|
||||
<div className="social-card-top">
|
||||
<span className="social-card-ico">
|
||||
<Icon size={25} strokeWidth={1.5} />
|
||||
</span>
|
||||
<span className="social-badge">公开频道</span>
|
||||
</div>
|
||||
<strong>{channel.name}</strong>
|
||||
<p>{channel.topic}</p>
|
||||
<div className="social-channel-preview">
|
||||
<Hash size={13} />
|
||||
<span>从报到开始,也可以先听听大家在聊什么。</span>
|
||||
</div>
|
||||
<div className="social-card-actions">
|
||||
<Link
|
||||
href={socialPath(`/chat/${channel.id}`)}
|
||||
className="social-btn primary"
|
||||
>
|
||||
加入对话 <ArrowUpRight size={14} />
|
||||
</Link>
|
||||
<BookmarkButton id={channel.id} collection="saved-channels" />
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
})}
|
||||
{!channels.length && <EmptyState />}
|
||||
</div>
|
||||
<div className="social-section-label">
|
||||
不知道怎么开场? <span>点一个破冰话题,带进频道慢慢聊。</span>
|
||||
</div>
|
||||
<div className="social-icebreakers">
|
||||
{STARTERS.map((starter, index) => (
|
||||
<Link
|
||||
key={starter}
|
||||
href={socialPath(
|
||||
`/chat/general?intro=${encodeURIComponent(starter)}`,
|
||||
)}
|
||||
>
|
||||
<span>0{index + 1}</span>
|
||||
<p>{starter}</p>
|
||||
<ArrowUpRight size={17} />
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
@ -1,33 +1,3 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import SiteShell from "./SiteShell";
|
||||
import { SEED_CHANNELS } from "@social/lib/seed";
|
||||
import { socialPath } from "@social/lib/socialPath";
|
||||
|
||||
export default function ChatListClient() {
|
||||
return (
|
||||
<SiteShell title="聊天室">
|
||||
<section className="social-hero">
|
||||
<div className="social-hero-tag">实时文字</div>
|
||||
<h1>
|
||||
聊天室
|
||||
<br />
|
||||
<span>自研频道 · 可扩展小程序</span>
|
||||
</h1>
|
||||
<p>自研频道 · Centrifugo 实时推送 · 离线自动降级本地缓存。不依赖 Lounge / web-view。</p>
|
||||
</section>
|
||||
<div className="social-list">
|
||||
{SEED_CHANNELS.map((c) => (
|
||||
<Link key={c.id} href={socialPath(`/chat/${c.id}`)} className="social-list-item">
|
||||
<div>
|
||||
<strong>{c.name}</strong>
|
||||
<p>{c.topic}</p>
|
||||
</div>
|
||||
<em>{c.members} 人</em>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
export { default } from "./ChannelDirectory";
|
||||
|
||||
@ -1,191 +1,3 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import SiteShell from "./SiteShell";
|
||||
import { socialApi } from "@social/lib/api";
|
||||
import { SEED_CHANNELS, SEED_MESSAGES } from "@social/lib/seed";
|
||||
import { loadJson, saveJson } from "@social/lib/storage";
|
||||
import type { SocialChatMessage } from "@social/lib/types";
|
||||
import { socialPath } from "@social/lib/socialPath";
|
||||
|
||||
export default function ChatRoomClient({ channelId }: { channelId: string }) {
|
||||
const channel = SEED_CHANNELS.find((c) => c.id === channelId) || SEED_CHANNELS[0];
|
||||
const storageKey = `chat:${channel.id}`;
|
||||
const [messages, setMessages] = useState<SocialChatMessage[]>([]);
|
||||
const [text, setText] = useState("");
|
||||
const [nick, setNick] = useState("游民");
|
||||
const [online, setOnline] = useState(true);
|
||||
const [sending, setSending] = useState(false);
|
||||
const bottomRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const seedForRoom = useMemo(
|
||||
() => SEED_MESSAGES.filter((m) => m.channelId === channel.id),
|
||||
[channel.id],
|
||||
);
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
try {
|
||||
const res = await socialApi.listMessages(channel.id);
|
||||
const items = (res.items || []).map((m) => ({
|
||||
id: m.id,
|
||||
channelId: m.channelId,
|
||||
author: m.author,
|
||||
text: m.text,
|
||||
at: m.at,
|
||||
}));
|
||||
if (items.length) {
|
||||
setMessages(items);
|
||||
saveJson(storageKey, items);
|
||||
} else {
|
||||
const local = loadJson<SocialChatMessage[]>(storageKey, seedForRoom);
|
||||
setMessages(local);
|
||||
}
|
||||
setOnline(true);
|
||||
} catch {
|
||||
setOnline(false);
|
||||
setMessages(loadJson<SocialChatMessage[]>(storageKey, seedForRoom));
|
||||
}
|
||||
}, [channel.id, seedForRoom, storageKey]);
|
||||
|
||||
useEffect(() => {
|
||||
setNick(loadJson("nick", "游民"));
|
||||
void refresh();
|
||||
|
||||
let cancelled = false;
|
||||
let stopRealtime: (() => void) | null = null;
|
||||
let pollId = 0;
|
||||
const startPoll = (ms: number) => {
|
||||
if (pollId) window.clearInterval(pollId);
|
||||
pollId = window.setInterval(() => void refresh(), ms);
|
||||
};
|
||||
startPoll(4000);
|
||||
|
||||
void (async () => {
|
||||
try {
|
||||
const { connectChatRealtime } = await import("@social/lib/realtime");
|
||||
const handle = await connectChatRealtime(channel.id, (msg) => {
|
||||
setMessages((prev) => {
|
||||
if (prev.some((p) => p.id === msg.id)) return prev;
|
||||
const next = [...prev, msg];
|
||||
saveJson(storageKey, next);
|
||||
return next;
|
||||
});
|
||||
setOnline(true);
|
||||
});
|
||||
if (cancelled) {
|
||||
handle?.disconnect();
|
||||
return;
|
||||
}
|
||||
if (handle) {
|
||||
stopRealtime = handle.disconnect;
|
||||
startPoll(30000);
|
||||
}
|
||||
} catch {
|
||||
/* 保持 4s 轮询 */
|
||||
}
|
||||
})();
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
if (pollId) window.clearInterval(pollId);
|
||||
stopRealtime?.();
|
||||
};
|
||||
}, [refresh, channel.id, storageKey]);
|
||||
|
||||
useEffect(() => {
|
||||
bottomRef.current?.scrollIntoView({ behavior: "smooth" });
|
||||
}, [messages]);
|
||||
|
||||
const send = async () => {
|
||||
const body = text.trim();
|
||||
if (!body || sending) return;
|
||||
setSending(true);
|
||||
const author = nick.trim() || "游民";
|
||||
try {
|
||||
const saved = await socialApi.sendMessage(channel.id, author, body);
|
||||
setText("");
|
||||
saveJson("nick", author);
|
||||
await refresh();
|
||||
if (!saved?.id) {
|
||||
/* refresh already applied */
|
||||
}
|
||||
setOnline(true);
|
||||
} catch {
|
||||
setOnline(false);
|
||||
const next: SocialChatMessage = {
|
||||
id: `local_${Date.now()}`,
|
||||
channelId: channel.id,
|
||||
author,
|
||||
text: body,
|
||||
at: new Date().toISOString(),
|
||||
mine: true,
|
||||
};
|
||||
const merged = [...messages, next];
|
||||
setMessages(merged);
|
||||
saveJson(storageKey, merged);
|
||||
saveJson("nick", author);
|
||||
setText("");
|
||||
} finally {
|
||||
setSending(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<SiteShell title={channel.name}>
|
||||
<div className="social-chat-head">
|
||||
<Link href={socialPath("/chat")} className="social-nav-back">
|
||||
← 频道列表
|
||||
</Link>
|
||||
<div>
|
||||
<strong>{channel.name}</strong>
|
||||
<p className="social-muted">
|
||||
{channel.topic}
|
||||
{" · "}
|
||||
{online ? "已同步服务器" : "离线本地模式"}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="social-chat-nick">
|
||||
<label>
|
||||
昵称
|
||||
<input
|
||||
value={nick}
|
||||
onChange={(e) => setNick(e.target.value)}
|
||||
maxLength={24}
|
||||
aria-label="聊天昵称"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="social-chat-thread">
|
||||
{messages.map((m) => (
|
||||
<div key={m.id} className={`social-bubble${m.mine ? " mine" : ""}`}>
|
||||
<header>
|
||||
{m.author}
|
||||
<time>{new Date(m.at).toLocaleString()}</time>
|
||||
</header>
|
||||
<p>{m.text}</p>
|
||||
</div>
|
||||
))}
|
||||
<div ref={bottomRef} />
|
||||
</div>
|
||||
|
||||
<div className="social-compose">
|
||||
<input
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") void send();
|
||||
}}
|
||||
placeholder="说点什么…"
|
||||
aria-label="消息内容"
|
||||
/>
|
||||
<button type="button" onClick={() => void send()} disabled={sending}>
|
||||
{sending ? "…" : "发送"}
|
||||
</button>
|
||||
</div>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
export { default } from "./ChatWorkspace";
|
||||
|
||||
376
src/modules/social/components/ChatWorkspace.tsx
Normal file
376
src/modules/social/components/ChatWorkspace.tsx
Normal file
@ -0,0 +1,376 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState, type FormEvent } from "react";
|
||||
import Link from "next/link";
|
||||
import {
|
||||
ArrowDown,
|
||||
ArrowLeft,
|
||||
CheckCheck,
|
||||
CornerUpLeft,
|
||||
Hash,
|
||||
Send,
|
||||
Smile,
|
||||
Wifi,
|
||||
WifiOff,
|
||||
X,
|
||||
} from "lucide-react";
|
||||
import SiteShell from "./SiteShell";
|
||||
import { EmptyState, ShareButton } from "./SocialUI";
|
||||
import { SEED_CHANNELS } from "@social/lib/seed";
|
||||
import { socialPath } from "@social/lib/socialPath";
|
||||
import { useSocialChat } from "@social/lib/useSocialChat";
|
||||
import { useLocalState } from "@social/lib/useLocalState";
|
||||
import { loadJson } from "@social/lib/storage";
|
||||
|
||||
const EMOJIS = ["👋", "☕", "🌍", "✨", "🙌", "❤️", "💻", "🌴"];
|
||||
const STATUS = {
|
||||
connecting: "正在连接",
|
||||
online: "已连接社区",
|
||||
offline: "离线 · 消息仅保存在本机",
|
||||
preview: "示例对话 · 可以开始真实聊天",
|
||||
};
|
||||
|
||||
export function Conversation({
|
||||
channelId,
|
||||
compact = false,
|
||||
}: {
|
||||
channelId: string;
|
||||
compact?: boolean;
|
||||
}) {
|
||||
const channel = SEED_CHANNELS.find((item) => item.id === channelId)!;
|
||||
const chat = useSocialChat(channelId);
|
||||
const setDraft = chat.setDraft;
|
||||
const [emojiOpen, setEmojiOpen] = useState(false);
|
||||
const [composerError, setComposerError] = useState("");
|
||||
const [reply, setReply] = useState<{ author: string; text: string } | null>(
|
||||
null,
|
||||
);
|
||||
const [reactions, setReactions] = useLocalState<Record<string, boolean>>(
|
||||
`message-hearts:${channelId}`,
|
||||
{},
|
||||
);
|
||||
const threadRef = useRef<HTMLDivElement>(null);
|
||||
const composerRef = useRef<HTMLTextAreaElement>(null);
|
||||
const atBottom = useRef(true);
|
||||
const introUsed = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
const intro = new URLSearchParams(location.search).get("intro");
|
||||
if (!intro || introUsed.current) return;
|
||||
introUsed.current = true;
|
||||
if (!loadJson(`chat-draft:${channelId}`, ""))
|
||||
setDraft(intro.slice(0, 2000));
|
||||
}, [channelId, setDraft]);
|
||||
|
||||
useEffect(() => {
|
||||
const thread = threadRef.current;
|
||||
if (!thread) return;
|
||||
if (atBottom.current)
|
||||
thread.scrollTo({
|
||||
top: thread.scrollHeight,
|
||||
behavior: matchMedia("(prefers-reduced-motion: reduce)").matches
|
||||
? "instant"
|
||||
: "smooth",
|
||||
});
|
||||
else thread.dataset.unread = "true";
|
||||
}, [chat.messages]);
|
||||
|
||||
const submit = async (event?: FormEvent) => {
|
||||
event?.preventDefault();
|
||||
if (!chat.draft.trim() || chat.sending) return;
|
||||
const submittedDraft = chat.draft;
|
||||
const body = reply
|
||||
? `回复 ${reply.author}:${reply.text.slice(0, 100)}\n${chat.draft}`
|
||||
: chat.draft;
|
||||
if (body.length > 2000) {
|
||||
setComposerError("包含引用的消息最多 2000 字,请缩短正文后重试。");
|
||||
return;
|
||||
}
|
||||
setComposerError("");
|
||||
await chat.send(body);
|
||||
if (reply) {
|
||||
if (loadJson(`chat-draft:${channelId}`, "") === submittedDraft)
|
||||
chat.setDraft("");
|
||||
setReply(null);
|
||||
}
|
||||
atBottom.current = true;
|
||||
composerRef.current?.focus();
|
||||
};
|
||||
|
||||
return (
|
||||
<section
|
||||
className={`social-conversation${compact ? " compact" : ""}`}
|
||||
aria-label={`${channel.name} 聊天`}
|
||||
>
|
||||
<div className="social-conversation-top">
|
||||
<div>
|
||||
<Hash size={21} />
|
||||
<div>
|
||||
<strong>{channel.name.replace("#", "")}</strong>
|
||||
<p>{channel.topic}</p>
|
||||
</div>
|
||||
</div>
|
||||
<ShareButton path={`/social/chat/${channelId}`} title={channel.topic} />
|
||||
</div>
|
||||
<div
|
||||
className={`social-connection-status ${chat.status === "offline" ? "offline" : ""}`}
|
||||
role="status"
|
||||
>
|
||||
{chat.status === "offline" ? <WifiOff size={12} /> : <Wifi size={12} />}
|
||||
{STATUS[chat.status]}
|
||||
<span>公开频道</span>
|
||||
</div>
|
||||
<div className="social-thread-wrap">
|
||||
<div
|
||||
className="social-chat-thread"
|
||||
ref={threadRef}
|
||||
role="log"
|
||||
aria-label="聊天消息"
|
||||
aria-live="polite"
|
||||
aria-relevant="additions"
|
||||
onScroll={() => {
|
||||
const thread = threadRef.current!;
|
||||
atBottom.current =
|
||||
thread.scrollHeight - thread.scrollTop - thread.clientHeight < 85;
|
||||
if (atBottom.current) thread.dataset.unread = "false";
|
||||
}}
|
||||
>
|
||||
{!chat.messages.length && (
|
||||
<EmptyState
|
||||
title="从你的一句你好开始"
|
||||
description="说说你在哪座城市,正在做什么,或最近对什么感兴趣。"
|
||||
/>
|
||||
)}
|
||||
{chat.messages.map((message) => (
|
||||
<article
|
||||
key={message.id}
|
||||
className={`social-message${message.mine ? " mine" : ""}`}
|
||||
>
|
||||
<div className="social-message-avatar" aria-hidden="true">
|
||||
{message.author.slice(0, 1).toUpperCase()}
|
||||
</div>
|
||||
<div className="social-message-body">
|
||||
<header>
|
||||
<strong>{message.author}</strong>
|
||||
<time suppressHydrationWarning dateTime={message.at}>
|
||||
{new Date(message.at).toLocaleTimeString([], {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
})}
|
||||
</time>
|
||||
{message.delivery === "demo" && <span>示例</span>}
|
||||
</header>
|
||||
<p>{message.text}</p>
|
||||
<div className="social-message-tools">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setReply({ author: message.author, text: message.text });
|
||||
composerRef.current?.focus();
|
||||
}}
|
||||
aria-label={`回复${message.author}`}
|
||||
>
|
||||
<CornerUpLeft size={12} />
|
||||
回复
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={reactions[message.id] ? "liked" : ""}
|
||||
aria-pressed={Boolean(reactions[message.id])}
|
||||
title="反应保存在当前设备"
|
||||
onClick={() =>
|
||||
setReactions((current) => ({
|
||||
...current,
|
||||
[message.id]: !current[message.id],
|
||||
}))
|
||||
}
|
||||
>
|
||||
{reactions[message.id] ? "♥ 1" : "♡"}
|
||||
</button>
|
||||
{message.delivery === "local" ? (
|
||||
<button
|
||||
type="button"
|
||||
className="social-local-message"
|
||||
disabled={chat.sending}
|
||||
onClick={() => void chat.send(message.text, message.id)}
|
||||
>
|
||||
仅本机 · 点击重试
|
||||
</button>
|
||||
) : (
|
||||
message.mine && (
|
||||
<span>
|
||||
<CheckCheck size={11} />
|
||||
已发送
|
||||
</span>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
))}
|
||||
{chat.sending && (
|
||||
<div className="social-chat-typing" role="status">
|
||||
<i />
|
||||
<i />
|
||||
<i />
|
||||
<span>正在发送…</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
className="social-new-messages"
|
||||
type="button"
|
||||
onClick={() => {
|
||||
const thread = threadRef.current!;
|
||||
thread.scrollTo({ top: thread.scrollHeight, behavior: "smooth" });
|
||||
}}
|
||||
>
|
||||
<ArrowDown size={13} />
|
||||
查看新消息
|
||||
</button>
|
||||
</div>
|
||||
<form
|
||||
className="social-chat-composer"
|
||||
onSubmit={(event) => void submit(event)}
|
||||
>
|
||||
{composerError && (
|
||||
<p className="social-status error" role="alert">
|
||||
{composerError}
|
||||
</p>
|
||||
)}
|
||||
{reply && (
|
||||
<div className="social-reply-preview">
|
||||
<CornerUpLeft size={13} />
|
||||
<span>
|
||||
回复 {reply.author} · {reply.text.slice(0, 50)}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setReply(null)}
|
||||
aria-label="取消回复"
|
||||
>
|
||||
<X size={14} />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<textarea
|
||||
ref={composerRef}
|
||||
aria-label="消息内容"
|
||||
placeholder="你在哪座城市?今天有什么新发现?"
|
||||
rows={2}
|
||||
maxLength={2000}
|
||||
value={chat.draft}
|
||||
onChange={(event) => chat.setDraft(event.target.value)}
|
||||
onKeyDown={(event) => {
|
||||
if (
|
||||
event.key === "Enter" &&
|
||||
!event.shiftKey &&
|
||||
!event.nativeEvent.isComposing
|
||||
) {
|
||||
event.preventDefault();
|
||||
void submit();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{emojiOpen && (
|
||||
<div
|
||||
className="social-emoji-picker"
|
||||
role="group"
|
||||
aria-label="选择表情"
|
||||
>
|
||||
{EMOJIS.map((emoji) => (
|
||||
<button
|
||||
key={emoji}
|
||||
type="button"
|
||||
aria-label={`插入${emoji}`}
|
||||
onClick={() => {
|
||||
chat.setDraft((chat.draft + emoji).slice(0, 2000));
|
||||
setEmojiOpen(false);
|
||||
composerRef.current?.focus();
|
||||
}}
|
||||
>
|
||||
{emoji}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div className="social-composer-toolbar">
|
||||
<button
|
||||
type="button"
|
||||
className="social-composer-emoji"
|
||||
aria-label="选择表情"
|
||||
aria-expanded={emojiOpen}
|
||||
onClick={() => setEmojiOpen(!emojiOpen)}
|
||||
>
|
||||
<Smile size={19} />
|
||||
</button>
|
||||
<label className="social-nick-label">
|
||||
昵称
|
||||
<input
|
||||
aria-label="聊天昵称"
|
||||
value={chat.nick}
|
||||
maxLength={24}
|
||||
onChange={(event) => chat.setNick(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<small>{chat.draft.length}/2000</small>
|
||||
<button
|
||||
className="social-btn primary"
|
||||
type="submit"
|
||||
disabled={!chat.draft.trim() || chat.sending}
|
||||
>
|
||||
<Send size={14} />
|
||||
发送
|
||||
</button>
|
||||
</div>
|
||||
<p className="social-composer-note">
|
||||
Enter 发送 · Shift + Enter 换行 · 草稿保存在当前设备
|
||||
</p>
|
||||
</form>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export default function ChatWorkspace({ channelId }: { channelId: string }) {
|
||||
const channel = SEED_CHANNELS.find((item) => item.id === channelId);
|
||||
return (
|
||||
<SiteShell title={channel?.name || "聊天室"}>
|
||||
{channel ? (
|
||||
<>
|
||||
<div className="social-room-heading">
|
||||
<Link href={socialPath("/chat")}>
|
||||
<ArrowLeft size={14} />
|
||||
所有频道
|
||||
</Link>
|
||||
<span>GOOD CONVERSATIONS START HERE</span>
|
||||
</div>
|
||||
<div className="social-chat-layout">
|
||||
<nav className="social-room-channels">
|
||||
<span>选择话题</span>
|
||||
{SEED_CHANNELS.map((item) => (
|
||||
<Link
|
||||
key={item.id}
|
||||
href={socialPath(`/chat/${item.id}`)}
|
||||
aria-current={item.id === channelId ? "page" : undefined}
|
||||
>
|
||||
<Hash size={14} />
|
||||
{item.name.replace("#", "")}
|
||||
</Link>
|
||||
))}
|
||||
</nav>
|
||||
<Conversation key={channelId} channelId={channelId} />
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<EmptyState
|
||||
title="这个频道还不存在"
|
||||
description="回到话题广场,找一个感兴趣的频道开始。"
|
||||
>
|
||||
<Link className="social-btn primary" href={socialPath("/chat")}>
|
||||
浏览所有频道
|
||||
</Link>
|
||||
</EmptyState>
|
||||
)}
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
@ -1,190 +1,3 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import SiteShell from "./SiteShell";
|
||||
import { socialApi } from "@social/lib/api";
|
||||
import { SEED_CAFES } from "@social/lib/seed";
|
||||
import { loadJson, saveJson } from "@social/lib/storage";
|
||||
import type { SocialCafeReview } from "@social/lib/types";
|
||||
|
||||
export default function CoffeechatClient() {
|
||||
const [cafeId, setCafeId] = useState(SEED_CAFES[0]?.id || "");
|
||||
const [reviews, setReviews] = useState<SocialCafeReview[]>([]);
|
||||
const [author, setAuthor] = useState("游民");
|
||||
const [score, setScore] = useState(5);
|
||||
const [text, setText] = useState("");
|
||||
const [photoNote, setPhotoNote] = useState("");
|
||||
const [online, setOnline] = useState(true);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const cafe = SEED_CAFES.find((c) => c.id === cafeId) || SEED_CAFES[0];
|
||||
const cacheKey = `cafe-reviews:${cafeId}`;
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
if (!cafeId) return;
|
||||
try {
|
||||
const res = await socialApi.listReviews(cafeId);
|
||||
const items = (res.items || []).map((r) => ({
|
||||
id: r.id,
|
||||
cafeId: r.cafeId,
|
||||
author: r.author,
|
||||
score: r.score,
|
||||
text: r.text,
|
||||
photoNote: r.photoNote,
|
||||
at: r.at,
|
||||
}));
|
||||
setReviews(items);
|
||||
saveJson(cacheKey, items);
|
||||
setOnline(true);
|
||||
} catch {
|
||||
setOnline(false);
|
||||
setReviews(loadJson<SocialCafeReview[]>(cacheKey, []));
|
||||
}
|
||||
}, [cafeId, cacheKey]);
|
||||
|
||||
useEffect(() => {
|
||||
setAuthor(loadJson("nick", "游民"));
|
||||
void refresh();
|
||||
}, [refresh]);
|
||||
|
||||
const submit = async () => {
|
||||
if (!cafe || !text.trim() || busy) return;
|
||||
setBusy(true);
|
||||
const payload = {
|
||||
author: author.trim() || "游民",
|
||||
score,
|
||||
text: text.trim(),
|
||||
photoNote: photoNote.trim(),
|
||||
};
|
||||
try {
|
||||
await socialApi.postReview(cafe.id, payload);
|
||||
saveJson("nick", payload.author);
|
||||
setText("");
|
||||
setPhotoNote("");
|
||||
setOnline(true);
|
||||
await refresh();
|
||||
} catch {
|
||||
setOnline(false);
|
||||
const item: SocialCafeReview = {
|
||||
id: `local_${Date.now()}`,
|
||||
cafeId: cafe.id,
|
||||
...payload,
|
||||
at: new Date().toISOString(),
|
||||
};
|
||||
const next = [item, ...reviews];
|
||||
setReviews(next);
|
||||
saveJson(cacheKey, next);
|
||||
saveJson("nick", payload.author);
|
||||
setText("");
|
||||
setPhotoNote("");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<SiteShell title="Coffeechat">
|
||||
<section className="social-hero">
|
||||
<div className="social-hero-tag">COFFEECHAT</div>
|
||||
<h1>
|
||||
Coffeechat
|
||||
<br />
|
||||
<span>约见 · 评价 · 同城</span>
|
||||
</h1>
|
||||
<p>
|
||||
选店、看评价、约见面。
|
||||
{online ? " 评价已同步后端。" : " 离线时评价先存本机。"}
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<div className="social-grid">
|
||||
{SEED_CAFES.map((c) => (
|
||||
<button
|
||||
key={c.id}
|
||||
type="button"
|
||||
className={`social-card social-card-btn${c.id === cafeId ? " active" : ""}`}
|
||||
onClick={() => setCafeId(c.id)}
|
||||
>
|
||||
<div className="social-card-top">
|
||||
<span className="social-card-ico">☕</span>
|
||||
{c.partners ? (
|
||||
<span className="social-badge live">合作</span>
|
||||
) : (
|
||||
<span className="social-badge">收录</span>
|
||||
)}
|
||||
</div>
|
||||
<strong>{c.name}</strong>
|
||||
<p>
|
||||
{c.city} · WiFi ~{c.wifiMbps}Mbps · ★{c.rating}
|
||||
</p>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{cafe ? (
|
||||
<section className="social-panel">
|
||||
<h2>{cafe.name}</h2>
|
||||
<p className="social-muted">
|
||||
{cafe.vibe} · 电源:{cafe.power} · 评价 {reviews.length} 条
|
||||
</p>
|
||||
|
||||
<div className="social-form">
|
||||
<label>
|
||||
你的名字
|
||||
<input value={author} onChange={(e) => setAuthor(e.target.value)} />
|
||||
</label>
|
||||
<label>
|
||||
评分 {score}
|
||||
<input
|
||||
type="range"
|
||||
min={1}
|
||||
max={5}
|
||||
value={score}
|
||||
onChange={(e) => setScore(Number(e.target.value))}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
评价
|
||||
<textarea
|
||||
rows={3}
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
placeholder="网络、插座、适不适合深聊…"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
合照备注
|
||||
<input
|
||||
value={photoNote}
|
||||
onChange={(e) => setPhotoNote(e.target.value)}
|
||||
placeholder="例如:门口合照 / 工位视角 jpg"
|
||||
/>
|
||||
</label>
|
||||
<button type="button" className="social-btn primary" onClick={() => void submit()} disabled={busy}>
|
||||
{busy ? "提交中…" : "提交评价"}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="social-list" style={{ marginTop: 20 }}>
|
||||
{reviews.length === 0 ? (
|
||||
<p className="social-muted">还没有评价,来写第一条吧。</p>
|
||||
) : (
|
||||
reviews.map((r) => (
|
||||
<article key={r.id} className="social-list-item social-list-stack">
|
||||
<div>
|
||||
<strong>
|
||||
{r.author} · {"★".repeat(r.score)}
|
||||
</strong>
|
||||
<p>{r.text}</p>
|
||||
{r.photoNote ? <p className="social-muted">合照:{r.photoNote}</p> : null}
|
||||
</div>
|
||||
<time className="social-muted">{new Date(r.at).toLocaleString()}</time>
|
||||
</article>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
) : null}
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
export { default } from "./CafeDirectory";
|
||||
|
||||
303
src/modules/social/components/CommunityWelcome.tsx
Normal file
303
src/modules/social/components/CommunityWelcome.tsx
Normal file
@ -0,0 +1,303 @@
|
||||
"use client";
|
||||
|
||||
import { useRef, useState, type FormEvent } from "react";
|
||||
import Link from "next/link";
|
||||
import {
|
||||
ArrowUpRight,
|
||||
Check,
|
||||
Heart,
|
||||
MessageCircle,
|
||||
Send,
|
||||
Sparkles,
|
||||
Users,
|
||||
} from "lucide-react";
|
||||
import { WechatOaModal } from "~/components/social-follow";
|
||||
import SiteShell from "./SiteShell";
|
||||
import { PageIntro } from "./SocialUI";
|
||||
import { useSocialConfig } from "./SocialExperience";
|
||||
import { socialApi } from "@social/lib/api";
|
||||
import { useLocalState } from "@social/lib/useLocalState";
|
||||
|
||||
export function CommunityFeedback() {
|
||||
const [draft, setDraft] = useLocalState<{
|
||||
kind: "反馈" | "建议";
|
||||
text: string;
|
||||
contact: string;
|
||||
}>("feedback-draft", { kind: "建议", text: "", contact: "" });
|
||||
const [delivery, setDelivery] = useLocalState("feedback-delivery", "draft");
|
||||
const [status, setStatus] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const lock = useRef(false);
|
||||
const update = (key: keyof typeof draft, value: string) => {
|
||||
setDraft((current) => ({ ...current, [key]: value }));
|
||||
setDelivery("draft");
|
||||
setStatus("");
|
||||
};
|
||||
const submit = async (event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
if (!draft.text.trim() || lock.current || delivery === "sent") return;
|
||||
lock.current = true;
|
||||
setBusy(true);
|
||||
try {
|
||||
await socialApi.postFeedback({
|
||||
...draft,
|
||||
text: draft.text.trim(),
|
||||
contact: draft.contact.trim(),
|
||||
});
|
||||
setDelivery("sent");
|
||||
setStatus("你的想法已提交,谢谢你一起把社区变得更好。");
|
||||
} catch {
|
||||
setDelivery("local");
|
||||
setStatus("内容已保存在本机,尚未送达社区。联网后可以在这里重试。");
|
||||
} finally {
|
||||
lock.current = false;
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<SiteShell title="共建社区">
|
||||
<PageIntro
|
||||
eyebrow="A COMMUNITY BUILT WITH YOU"
|
||||
title="你的一点想法,"
|
||||
accent="可能改变很多人的相遇。"
|
||||
description="想要什么新功能?哪一步不够顺手?或者,你有一个想和大家一起实现的点子。我们想听见。"
|
||||
/>
|
||||
<section className="social-panel social-feedback-panel">
|
||||
<div className="social-feedback-heading">
|
||||
<span className="social-feedback-heart">
|
||||
<Heart size={32} />
|
||||
</span>
|
||||
<div>
|
||||
<h2>下一次更新,从这里开始。</h2>
|
||||
<p>具体的场景、期待的体验,都值得被认真写下来。</p>
|
||||
</div>
|
||||
</div>
|
||||
<form className="social-form" onSubmit={(event) => void submit(event)}>
|
||||
<fieldset disabled={busy} className="social-fieldset">
|
||||
<div className="social-filters">
|
||||
{(["建议", "反馈"] as const).map((kind) => (
|
||||
<button
|
||||
type="button"
|
||||
key={kind}
|
||||
className={draft.kind === kind ? "active" : ""}
|
||||
aria-pressed={draft.kind === kind}
|
||||
onClick={() => update("kind", kind)}
|
||||
>
|
||||
{kind === "建议" ? "✦ 我有一个点子" : "↗ 这里可以更好"}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<label>
|
||||
说说你的想法
|
||||
<textarea
|
||||
rows={6}
|
||||
required
|
||||
maxLength={3000}
|
||||
value={draft.text}
|
||||
onChange={(event) => update("text", event.target.value)}
|
||||
placeholder="比如:我想在新城市快速找到一起办公的人,希望能按工作时间和兴趣找伙伴…"
|
||||
/>
|
||||
<small>{draft.text.length}/3000</small>
|
||||
</label>
|
||||
<label>
|
||||
方便继续交流的联系方式(选填)
|
||||
<input
|
||||
maxLength={120}
|
||||
value={draft.contact}
|
||||
onChange={(event) => update("contact", event.target.value)}
|
||||
placeholder="邮箱 / 微信 / 其他"
|
||||
/>
|
||||
</label>
|
||||
</fieldset>
|
||||
<button
|
||||
type="submit"
|
||||
className="social-btn primary"
|
||||
disabled={busy || delivery === "sent" || !draft.text.trim()}
|
||||
>
|
||||
<Send size={15} />
|
||||
{busy
|
||||
? "提交中…"
|
||||
: delivery === "sent"
|
||||
? "已收到你的想法"
|
||||
: delivery === "local"
|
||||
? "重试提交"
|
||||
: "让这个想法被看见"}
|
||||
</button>
|
||||
{status && (
|
||||
<p
|
||||
role="status"
|
||||
className={`social-status${delivery === "local" ? " warn" : ""}`}
|
||||
>
|
||||
{status}
|
||||
</p>
|
||||
)}
|
||||
<p className="social-muted">
|
||||
草稿保存在当前设备,提交成功后才会送达社区。
|
||||
</p>
|
||||
</form>
|
||||
</section>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
|
||||
export function CommunityJoin() {
|
||||
const [open, setOpen] = useState(false);
|
||||
return (
|
||||
<SiteShell title="加入社区">
|
||||
<PageIntro
|
||||
eyebrow="YOUR PEOPLE ARE OUT THERE"
|
||||
title="世界很大,"
|
||||
accent="总有人和你同频。"
|
||||
description="不需要一个完美的开场。从一句你好、一张名片、一杯咖啡开始,在新的城市找到熟悉感。"
|
||||
/>
|
||||
<div className="social-welcome-banner">
|
||||
<div className="social-welcome-faces" aria-hidden="true">
|
||||
<span>👋</span>
|
||||
<span>🌍</span>
|
||||
<span>☕</span>
|
||||
<span>💻</span>
|
||||
</div>
|
||||
<div>
|
||||
<h2>来这里,做真实的自己。</h2>
|
||||
<p>分享经验,保持好奇,尊重每个人的边界。</p>
|
||||
</div>
|
||||
<button
|
||||
className="social-btn primary"
|
||||
type="button"
|
||||
onClick={() => setOpen(true)}
|
||||
>
|
||||
查看社群加入方式 <ArrowUpRight size={15} />
|
||||
</button>
|
||||
</div>
|
||||
<div className="social-grid social-onboarding-grid">
|
||||
{[
|
||||
{
|
||||
n: "01",
|
||||
icon: Users,
|
||||
title: "让大家认识你",
|
||||
text: "写下城市、兴趣和正在做的事。好的连接,始于一个具体的你。",
|
||||
href: "/social/roster",
|
||||
cta: "制作我的名片",
|
||||
},
|
||||
{
|
||||
n: "02",
|
||||
icon: MessageCircle,
|
||||
title: "加入一场好对话",
|
||||
text: "打个招呼,交换一条城市经验,问一个你一直想问的问题。",
|
||||
href:
|
||||
"/social/chat/general?intro=" +
|
||||
encodeURIComponent(
|
||||
"大家好,我刚来到这里 👋 很想认识同城或同频的新朋友!",
|
||||
),
|
||||
cta: "去公开频道报到",
|
||||
},
|
||||
{
|
||||
n: "03",
|
||||
icon: Sparkles,
|
||||
title: "把连接带到生活里",
|
||||
text: "看看下一场 Meetup,或挑一家咖啡馆,公开发起一次见面邀约。",
|
||||
href: "/social/meetup",
|
||||
cta: "发现下一次相遇",
|
||||
},
|
||||
].map((item) => (
|
||||
<article className="social-card social-onboarding-card" key={item.n}>
|
||||
<div className="social-card-top">
|
||||
<item.icon size={27} strokeWidth={1.3} />
|
||||
<span>{item.n}</span>
|
||||
</div>
|
||||
<h2>{item.title}</h2>
|
||||
<p>{item.text}</p>
|
||||
<Link className="social-btn" href={item.href}>
|
||||
{item.cta}
|
||||
<ArrowUpRight size={14} />
|
||||
</Link>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
<WechatOaModal open={open} onClose={() => setOpen(false)} />
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
|
||||
export function CommunityMembership() {
|
||||
const config = useSocialConfig();
|
||||
const price = ((config.copy.vipPriceFen ?? 29800) / 100).toLocaleString(
|
||||
"zh-CN",
|
||||
{ maximumFractionDigits: 2 },
|
||||
);
|
||||
return (
|
||||
<SiteShell title="会员与连接">
|
||||
<PageIntro
|
||||
eyebrow="MORE CONNECTION. MORE POSSIBILITY."
|
||||
title="连接,从参与开始。"
|
||||
accent="把社区变成生活的一部分。"
|
||||
description="先认识这里的人、加入感兴趣的对话,再选择适合自己的参与方式。会员方案与实际权益可在会员中心查看。"
|
||||
/>
|
||||
<section className="social-membership-banner">
|
||||
<div className="social-membership-emblem" aria-hidden="true">
|
||||
<Sparkles size={51} strokeWidth={1} />
|
||||
<i />
|
||||
<i />
|
||||
</div>
|
||||
<div>
|
||||
<span className="social-page-kicker">NOMADRO MEMBERSHIP</span>
|
||||
<h2>留给更深入探索的你。</h2>
|
||||
<p>
|
||||
当前会员展示价 <strong>¥{price}</strong>
|
||||
,具体有效期、权益与最终价格以会员中心为准。
|
||||
</p>
|
||||
<div className="social-actions">
|
||||
{config.flags.payEnabled ? (
|
||||
<Link className="social-btn primary" href="/vip">
|
||||
{config.copy.vipCta || "查看会员方案"}
|
||||
<ArrowUpRight size={15} />
|
||||
</Link>
|
||||
) : (
|
||||
<span className="social-status">
|
||||
会员购买暂未开放,欢迎先参与社区。
|
||||
</span>
|
||||
)}
|
||||
<Link className="social-btn" href="/social/join">
|
||||
先加入社区
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<div className="social-section-label">
|
||||
现在就能开始的连接 <span>以下是社区入口,不代表额外付费权益</span>
|
||||
</div>
|
||||
<div className="social-grid">
|
||||
{[
|
||||
{
|
||||
title: "一张有温度的名片",
|
||||
text: "让你的技能、城市与兴趣有一个清晰的介绍。",
|
||||
href: "/social/roster",
|
||||
},
|
||||
{
|
||||
title: "一次公开的 Coffeechat",
|
||||
text: "从一个地方、一杯咖啡和一次公开邀约开始。",
|
||||
href: "/social/coffeechat",
|
||||
},
|
||||
{
|
||||
title: "一场值得参与的对话",
|
||||
text: "走进话题频道和线上活动,与不同城市的人交流。",
|
||||
href: "/social/chat",
|
||||
},
|
||||
].map((item) => (
|
||||
<Link
|
||||
className="social-card social-membership-card"
|
||||
href={item.href}
|
||||
key={item.href}
|
||||
>
|
||||
<Check size={21} />
|
||||
<h2>{item.title}</h2>
|
||||
<p>{item.text}</p>
|
||||
<span>
|
||||
去看看 <ArrowUpRight size={14} />
|
||||
</span>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
394
src/modules/social/components/ConnectionHero.tsx
Normal file
394
src/modules/social/components/ConnectionHero.tsx
Normal file
@ -0,0 +1,394 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState, type CSSProperties } from "react";
|
||||
import Link from "next/link";
|
||||
import {
|
||||
ArrowDown,
|
||||
ArrowUpRight,
|
||||
Coffee,
|
||||
Globe2,
|
||||
MoveUpRight,
|
||||
Play,
|
||||
Radio,
|
||||
Sparkles,
|
||||
Users,
|
||||
X,
|
||||
} from "lucide-react";
|
||||
import { MOCK_ROSTER } from "@social/lib/rosterMock";
|
||||
import { socialPath } from "@social/lib/socialPath";
|
||||
import SocialAvatar from "./SocialAvatar";
|
||||
import FloatingEmojiField from "./FloatingEmojiField";
|
||||
import type { SocialLandingCopy } from "@social/lib/landing";
|
||||
|
||||
const NODES = [
|
||||
{ member: 0, x: 22, y: 22, rotate: -8 },
|
||||
{ member: 1, x: 79, y: 26, rotate: 7 },
|
||||
{ member: 4, x: 85, y: 65, rotate: -6 },
|
||||
{ member: 3, x: 18, y: 69, rotate: 6 },
|
||||
];
|
||||
|
||||
export default function ConnectionHero({
|
||||
onJoin,
|
||||
promoUrl,
|
||||
copy,
|
||||
}: {
|
||||
onJoin: () => void;
|
||||
promoUrl: string;
|
||||
copy: SocialLandingCopy;
|
||||
}) {
|
||||
const [videoOpen, setVideoOpen] = useState(false);
|
||||
const dialogRef = useRef<HTMLDialogElement>(null);
|
||||
const stageRef = useRef<HTMLDivElement>(null);
|
||||
const triggerRef = useRef<HTMLButtonElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const dialog = dialogRef.current;
|
||||
if (!dialog) return;
|
||||
if (videoOpen) dialog.showModal();
|
||||
else if (dialog.open) dialog.close();
|
||||
if (!videoOpen) return;
|
||||
const previousOverflow = document.body.style.overflow;
|
||||
document.body.style.overflow = "hidden";
|
||||
return () => {
|
||||
document.body.style.overflow = previousOverflow;
|
||||
};
|
||||
}, [videoOpen]);
|
||||
|
||||
const closeVideo = () => {
|
||||
setVideoOpen(false);
|
||||
triggerRef.current?.focus();
|
||||
};
|
||||
|
||||
return (
|
||||
<section
|
||||
className="connection-hero"
|
||||
id="hero"
|
||||
aria-labelledby="connection-title"
|
||||
>
|
||||
<div className="connection-hero-grid" aria-hidden="true" />
|
||||
<FloatingEmojiField />
|
||||
<div className="container connection-hero-layout">
|
||||
<div className="connection-copy">
|
||||
<div className="connection-eyebrow">
|
||||
<span className="connection-status-dot" /> NOMADRO SOCIAL{" "}
|
||||
<span className="connection-eyebrow-divider" /> {copy.socialEyebrow}
|
||||
</div>
|
||||
<h1 id="connection-title">
|
||||
{copy.socialHeroLine1}
|
||||
<br />
|
||||
还好
|
||||
<span className="connection-title-accent">
|
||||
{copy.socialHeroAccent}
|
||||
</span>
|
||||
不远<span className="connection-title-period">。</span>
|
||||
</h1>
|
||||
<p className="connection-description">{copy.socialHeroLead}</p>
|
||||
<div className="connection-actions">
|
||||
<button
|
||||
className="btn connection-join"
|
||||
type="button"
|
||||
onClick={onJoin}
|
||||
>
|
||||
{copy.socialJoinCta} <ArrowUpRight size={19} />
|
||||
</button>
|
||||
<button
|
||||
ref={triggerRef}
|
||||
className="connection-film"
|
||||
type="button"
|
||||
onClick={() => setVideoOpen(true)}
|
||||
>
|
||||
<span>
|
||||
<Play size={13} fill="currentColor" />
|
||||
</span>{" "}
|
||||
看看社区故事
|
||||
</button>
|
||||
</div>
|
||||
<div className="connection-proof">
|
||||
<div className="connection-avatar-stack" aria-hidden="true">
|
||||
{MOCK_ROSTER.slice(0, 4).map((m) => (
|
||||
<SocialAvatar key={m.id} src={m.avatar} size={34} />
|
||||
))}
|
||||
</div>
|
||||
<div>
|
||||
<strong>有趣的人,正在这里相遇</strong>
|
||||
<span>自由职业者 · 远程工作者 · 生活探索家</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="connection-universe"
|
||||
ref={stageRef}
|
||||
onPointerMove={(event) => {
|
||||
if (
|
||||
event.pointerType !== "mouse" ||
|
||||
window.matchMedia("(prefers-reduced-motion: reduce)").matches
|
||||
)
|
||||
return;
|
||||
const rect = event.currentTarget.getBoundingClientRect();
|
||||
event.currentTarget.style.setProperty(
|
||||
"--orbit-x",
|
||||
`${(event.clientX - rect.left - rect.width / 2) / 45}deg`,
|
||||
);
|
||||
event.currentTarget.style.setProperty(
|
||||
"--orbit-y",
|
||||
`${-(event.clientY - rect.top - rect.height / 2) / 60}deg`,
|
||||
);
|
||||
}}
|
||||
onPointerLeave={() => {
|
||||
stageRef.current?.style.setProperty("--orbit-x", "0deg");
|
||||
stageRef.current?.style.setProperty("--orbit-y", "0deg");
|
||||
}}
|
||||
>
|
||||
<div className="connection-universe-label">
|
||||
<Globe2 size={13} />
|
||||
<span>不止在线,更在身边</span>
|
||||
<span className="connection-signal">
|
||||
<i />
|
||||
<i />
|
||||
<i />
|
||||
<i />
|
||||
</span>
|
||||
</div>
|
||||
<div className="connection-orbit-scene">
|
||||
<svg
|
||||
className="connection-orbits"
|
||||
viewBox="0 0 560 480"
|
||||
fill="none"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<defs>
|
||||
<radialGradient id="connection-globe">
|
||||
<stop stopColor="#4ecdc4" stopOpacity=".15" />
|
||||
<stop offset="1" stopColor="#4ecdc4" stopOpacity="0" />
|
||||
</radialGradient>
|
||||
<linearGradient
|
||||
id="connection-line"
|
||||
x1="100"
|
||||
y1="100"
|
||||
x2="450"
|
||||
y2="400"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
>
|
||||
<stop stopColor="#4ecdc4" />
|
||||
<stop offset=".5" stopColor="#ffe66d" />
|
||||
<stop offset="1" stopColor="#ff6b6b" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<circle cx="280" cy="240" r="185" fill="url(#connection-globe)" />
|
||||
<g
|
||||
className="connection-globe-lines"
|
||||
stroke="currentColor"
|
||||
strokeWidth=".7"
|
||||
>
|
||||
<circle cx="280" cy="240" r="121" />
|
||||
<ellipse cx="280" cy="240" rx="121" ry="45" />
|
||||
<ellipse cx="280" cy="240" rx="121" ry="88" />
|
||||
<ellipse cx="280" cy="240" rx="45" ry="121" />
|
||||
<ellipse cx="280" cy="240" rx="88" ry="121" />
|
||||
<path d="M159 240h242M280 119v242" />
|
||||
</g>
|
||||
<g stroke="url(#connection-line)" strokeWidth="1">
|
||||
<ellipse
|
||||
cx="280"
|
||||
cy="240"
|
||||
rx="221"
|
||||
ry="148"
|
||||
transform="rotate(-28 280 240)"
|
||||
opacity=".35"
|
||||
/>
|
||||
<ellipse
|
||||
cx="280"
|
||||
cy="240"
|
||||
rx="230"
|
||||
ry="186"
|
||||
transform="rotate(24 280 240)"
|
||||
strokeDasharray="3 9"
|
||||
opacity=".3"
|
||||
/>
|
||||
<circle cx="280" cy="240" r="170" opacity=".12" />
|
||||
</g>
|
||||
<g className="connection-orbit-traveler">
|
||||
<circle cx="280" cy="70" r="4" fill="#4ecdc4" />
|
||||
<circle
|
||||
cx="280"
|
||||
cy="70"
|
||||
r="9"
|
||||
stroke="#4ecdc4"
|
||||
strokeOpacity=".25"
|
||||
/>
|
||||
</g>
|
||||
<g className="connection-orbit-traveler connection-orbit-traveler-second">
|
||||
<circle cx="280" cy="410" r="3" fill="#ff6b6b" />
|
||||
</g>
|
||||
<path
|
||||
className="connection-flight-path"
|
||||
d="M126 106Q280 40 442 125M100 330Q270 440 470 310"
|
||||
stroke="url(#connection-line)"
|
||||
strokeWidth="1.5"
|
||||
strokeDasharray="5 8"
|
||||
opacity=".55"
|
||||
/>
|
||||
</svg>
|
||||
<div className="connection-center">
|
||||
<div className="connection-center-icon">
|
||||
<Sparkles size={27} strokeWidth={1.3} />
|
||||
</div>
|
||||
<strong>同频,自有引力</strong>
|
||||
<span>FIND YOUR PEOPLE</span>
|
||||
</div>
|
||||
{NODES.map(({ member, x, y, rotate }, i) => {
|
||||
const m = MOCK_ROSTER[member];
|
||||
return (
|
||||
<a
|
||||
href="#people"
|
||||
onClick={() =>
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("nomadro-social-select-member", {
|
||||
detail: m.id,
|
||||
}),
|
||||
)
|
||||
}
|
||||
className={`connection-person connection-person-${i}`}
|
||||
key={m.id}
|
||||
style={
|
||||
{
|
||||
"--node-x": `${x}%`,
|
||||
"--node-y": `${y}%`,
|
||||
"--node-rotate": `${rotate}deg`,
|
||||
"--node-delay": `${i * -1.4}s`,
|
||||
} as CSSProperties
|
||||
}
|
||||
aria-label={`认识${m.name},${m.title}`}
|
||||
>
|
||||
<span className="connection-person-avatar">
|
||||
<SocialAvatar src={m.avatar} size={44} />
|
||||
<i />
|
||||
</span>
|
||||
<span>
|
||||
<strong>
|
||||
{m.name}
|
||||
<MoveUpRight size={11} />
|
||||
</strong>
|
||||
<small>{m.title}</small>
|
||||
<em>{m.city.split("·")[0].trim()}</em>
|
||||
</span>
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
<span className="connection-coordinate connection-coordinate-one">
|
||||
18.79° N · 清迈
|
||||
</span>
|
||||
<span className="connection-coordinate connection-coordinate-two">
|
||||
25.60° N · 大理
|
||||
</span>
|
||||
<div className="connection-wave">
|
||||
<Coffee size={17} />
|
||||
<span>下一杯咖啡,和新朋友。</span>
|
||||
<span>↗</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="connection-universe-footer">
|
||||
<span>
|
||||
<span className="connection-status-dot" /> 连接没有边界
|
||||
</span>
|
||||
<span>成员展示 · 演示数据</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="container connection-hero-bottom">
|
||||
<a href="#people">
|
||||
<ArrowDown size={14} /> 向下探索你的下一次相遇
|
||||
</a>
|
||||
<span>LESS SCROLLING. MORE CONNECTING.</span>
|
||||
</div>
|
||||
|
||||
<dialog
|
||||
ref={dialogRef}
|
||||
className="connection-video-dialog"
|
||||
onCancel={(event) => {
|
||||
event.preventDefault();
|
||||
closeVideo();
|
||||
}}
|
||||
onClose={() => setVideoOpen(false)}
|
||||
onClick={(event) => {
|
||||
if (event.target === event.currentTarget) closeVideo();
|
||||
}}
|
||||
aria-labelledby="connection-film-title"
|
||||
>
|
||||
{videoOpen && (
|
||||
<div className="connection-video-content">
|
||||
<header>
|
||||
<h2 id="connection-film-title">游民社区 · 社区故事</h2>
|
||||
<button
|
||||
type="button"
|
||||
onClick={closeVideo}
|
||||
aria-label="关闭宣传片"
|
||||
>
|
||||
<X size={20} />
|
||||
</button>
|
||||
</header>
|
||||
<video
|
||||
src={promoUrl}
|
||||
controls
|
||||
autoPlay
|
||||
playsInline
|
||||
preload="metadata"
|
||||
aria-label="游民社区宣传片"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</dialog>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export function ConnectionWays({ copy }: { copy: SocialLandingCopy }) {
|
||||
const ways = [
|
||||
{
|
||||
id: "01",
|
||||
href: "/chat",
|
||||
icon: Radio,
|
||||
title: copy.socialOnlineTitle,
|
||||
sub: "线上闲聊 · 灵感碰撞",
|
||||
className: "mint",
|
||||
},
|
||||
{
|
||||
id: "02",
|
||||
href: "/coffeechat",
|
||||
icon: Coffee,
|
||||
title: copy.socialOfflineTitle,
|
||||
sub: "一杯咖啡 · 真实连接",
|
||||
className: "coral",
|
||||
},
|
||||
{
|
||||
id: "03",
|
||||
href: "/team",
|
||||
icon: Users,
|
||||
title: copy.socialTeamTitle,
|
||||
sub: "远程协作 · 共创可能",
|
||||
className: "yellow",
|
||||
},
|
||||
];
|
||||
return (
|
||||
<div className="container connection-ways" aria-label="选择连接方式">
|
||||
{ways.map((way) => (
|
||||
<Link
|
||||
href={socialPath(way.href)}
|
||||
className={`connection-way ${way.className}`}
|
||||
key={way.id}
|
||||
>
|
||||
<span className="connection-way-index">{way.id}</span>
|
||||
<span className="connection-way-icon">
|
||||
<way.icon size={23} strokeWidth={1.5} />
|
||||
</span>
|
||||
<span className="connection-way-copy">
|
||||
<strong>{way.title}</strong>
|
||||
<small>{way.sub}</small>
|
||||
</span>
|
||||
<ArrowUpRight className="connection-way-arrow" size={19} />
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -1,39 +1,3 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import SiteShell from "./SiteShell";
|
||||
import { SEED_VIDEOS } from "@social/lib/seed";
|
||||
import { socialPath } from "@social/lib/socialPath";
|
||||
|
||||
export default function DateClient() {
|
||||
return (
|
||||
<SiteShell title="Date">
|
||||
<section className="social-hero">
|
||||
<div className="social-hero-tag">线下访谈</div>
|
||||
<h1>
|
||||
Date / 访谈视频
|
||||
<br />
|
||||
<span>把偶遇做成故事</span>
|
||||
</h1>
|
||||
<p>线下 Coffeechat / 访谈成片沉淀在这里;完整播放器可接 PeerTube / 对象存储。</p>
|
||||
</section>
|
||||
<div className="social-grid">
|
||||
{SEED_VIDEOS.map((v) => (
|
||||
<article key={v.id} className="social-card">
|
||||
<div className="social-card-top">
|
||||
<span className="social-card-ico">{v.coverEmoji}</span>
|
||||
<span className="social-badge">{v.minutes} 分</span>
|
||||
</div>
|
||||
<strong>{v.title}</strong>
|
||||
<p>
|
||||
{v.city} · {v.summary}
|
||||
</p>
|
||||
<Link className="social-btn" href={socialPath(`/videos#${v.id}`)}>
|
||||
在视频库查看
|
||||
</Link>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
export { StoriesLibrary as default } from "./ResourceLibrary";
|
||||
|
||||
@ -1,38 +1,3 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import SiteShell from "./SiteShell";
|
||||
import { SEED_EBOOKS } from "@social/lib/seed";
|
||||
|
||||
export default function EbookClient() {
|
||||
return (
|
||||
<SiteShell title="电子书">
|
||||
<section className="social-hero">
|
||||
<div className="social-hero-tag">UGC · ebook</div>
|
||||
<h1>
|
||||
社区小册
|
||||
<br />
|
||||
<span>玩法沉淀成可读内容</span>
|
||||
</h1>
|
||||
<p>社区向小册在此聚合;完整阅读器复用门户数字游民小册能力。</p>
|
||||
</section>
|
||||
<div className="social-grid">
|
||||
{SEED_EBOOKS.map((b) => (
|
||||
<article key={b.id} className="social-card">
|
||||
<div className="social-card-top">
|
||||
<span className="social-card-ico">📖</span>
|
||||
<span className="social-badge">
|
||||
{b.chapters} 章 · {b.minutes} 分
|
||||
</span>
|
||||
</div>
|
||||
<strong>{b.title}</strong>
|
||||
<p>{b.blurb}</p>
|
||||
<Link className="social-btn" href="/book">
|
||||
打开小册阅读器
|
||||
</Link>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
export { BooksLibrary as default } from "./ResourceLibrary";
|
||||
|
||||
178
src/modules/social/components/EventDirectory.tsx
Normal file
178
src/modules/social/components/EventDirectory.tsx
Normal file
@ -0,0 +1,178 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import Link from "next/link";
|
||||
import {
|
||||
ArrowUpRight,
|
||||
CalendarPlus,
|
||||
Clock3,
|
||||
Globe2,
|
||||
MessageCircle,
|
||||
Radio,
|
||||
} from "lucide-react";
|
||||
import SiteShell from "./SiteShell";
|
||||
import {
|
||||
BookmarkButton,
|
||||
EmptyState,
|
||||
PageIntro,
|
||||
SearchField,
|
||||
ShareButton,
|
||||
} from "./SocialUI";
|
||||
import { SEED_MEETUPS } from "@social/lib/seed";
|
||||
import { eventDate, saveEventCalendar } from "@social/lib/calendar";
|
||||
import { useLocalState } from "@social/lib/useLocalState";
|
||||
import { socialPath } from "@social/lib/socialPath";
|
||||
|
||||
export default function EventDirectory() {
|
||||
const [query, setQuery] = useState("");
|
||||
const [filter, setFilter] = useState("all");
|
||||
const [saved] = useLocalState<string[]>("saved-events", []);
|
||||
const events = SEED_MEETUPS.filter(
|
||||
(item) =>
|
||||
`${item.title} ${item.city}`
|
||||
.toLowerCase()
|
||||
.includes(query.toLowerCase()) &&
|
||||
(filter !== "saved" || saved.includes(item.id)),
|
||||
);
|
||||
return (
|
||||
<SiteShell title="Meetup 活动">
|
||||
<PageIntro
|
||||
eyebrow="SHOW UP. FIND YOUR PEOPLE."
|
||||
title="把下一个晚上,"
|
||||
accent="留给有趣的对话。"
|
||||
description="线上办公室、城市闲聊、主题 AMA。你可以先听听,也可以分享一个正在探索的问题。"
|
||||
/>
|
||||
<div className="social-toolbar">
|
||||
<SearchField
|
||||
value={query}
|
||||
onChange={setQuery}
|
||||
label="搜索活动"
|
||||
placeholder="搜索主题或城市…"
|
||||
/>
|
||||
<div className="social-filters">
|
||||
<button
|
||||
aria-pressed={filter === "all"}
|
||||
className={filter === "all" ? "active" : ""}
|
||||
onClick={() => setFilter("all")}
|
||||
>
|
||||
全部活动
|
||||
</button>
|
||||
<button
|
||||
aria-pressed={filter === "saved"}
|
||||
className={filter === "saved" ? "active" : ""}
|
||||
onClick={() => setFilter("saved")}
|
||||
>
|
||||
我的计划
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="social-status">
|
||||
<Globe2 size={15} />
|
||||
活动目录预览 · 原始时间默认使用北京时间(UTC+8)·
|
||||
加入计划仅保存在当前设备
|
||||
</div>
|
||||
<div className="social-event-grid">
|
||||
{events.map((event, index) => (
|
||||
<article
|
||||
className={`social-card social-event-card event-${index}`}
|
||||
key={event.id}
|
||||
>
|
||||
<div className="social-event-art" aria-hidden="true">
|
||||
<span>0{index + 1}</span>
|
||||
<div>
|
||||
{Array.from({ length: 24 }, (_, i) => (
|
||||
<i
|
||||
key={i}
|
||||
style={{
|
||||
height: `${14 + ((i * 17) % 56)}px`,
|
||||
animationDelay: `${i * -0.13}s`,
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<Radio size={28} strokeWidth={1.3} />
|
||||
</div>
|
||||
<div className="social-card-top">
|
||||
<span className="social-badge live">
|
||||
{event.mode === "hybrid" ? "线上 + 线下" : "线上相聚"}
|
||||
</span>
|
||||
<span className="social-badge">活动预览</span>
|
||||
</div>
|
||||
<h2>{event.title}</h2>
|
||||
<p className="social-event-time">
|
||||
<Clock3 size={14} />
|
||||
{event.date} · {event.time} 北京时间
|
||||
</p>
|
||||
<p className="social-muted" suppressHydrationWarning>
|
||||
你的当地时间:
|
||||
{eventDate(event).toLocaleString([], {
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
timeZoneName: "short",
|
||||
})}
|
||||
</p>
|
||||
<div className="social-card-actions">
|
||||
<Link
|
||||
className="social-btn primary"
|
||||
href={socialPath(`/meetup/${event.id}`)}
|
||||
>
|
||||
进入活动空间 <ArrowUpRight size={15} />
|
||||
</Link>
|
||||
<BookmarkButton
|
||||
id={event.id}
|
||||
collection="saved-events"
|
||||
label="加入计划"
|
||||
/>
|
||||
</div>
|
||||
<div className="social-card-actions">
|
||||
<button
|
||||
type="button"
|
||||
className="social-save"
|
||||
onClick={() => saveEventCalendar(event)}
|
||||
>
|
||||
<CalendarPlus size={14} />
|
||||
添加到日历
|
||||
</button>
|
||||
<ShareButton
|
||||
path={`/social/meetup/${event.id}`}
|
||||
title={event.title}
|
||||
/>
|
||||
<Link
|
||||
className="social-save"
|
||||
href={socialPath(`/chat/${event.channelId}`)}
|
||||
>
|
||||
<MessageCircle size={14} />
|
||||
先去聊聊
|
||||
</Link>
|
||||
</div>
|
||||
</article>
|
||||
))}
|
||||
{!events.length && (
|
||||
<EmptyState
|
||||
title="给下一场相遇留个位置"
|
||||
description="收藏感兴趣的活动后,可以在「我的计划」里找到它们。"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<section className="social-panel social-event-guide">
|
||||
<h2>第一次参加?轻松一点就好。</h2>
|
||||
<div>
|
||||
<p>
|
||||
<span>01</span>
|
||||
<strong>选一个话题</strong>看看标题,想一个你真的好奇的问题。
|
||||
</p>
|
||||
<p>
|
||||
<span>02</span>
|
||||
<strong>先在文字区打招呼</strong>说说你在哪里,正在做什么。
|
||||
</p>
|
||||
<p>
|
||||
<span>03</span>
|
||||
<strong>准备好了再开麦</strong>视频和麦克风由你自己决定。
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
@ -1,85 +1,3 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import SiteShell from "./SiteShell";
|
||||
import { socialApi } from "@social/lib/api";
|
||||
import { loadJson, saveJson, uid } from "@social/lib/storage";
|
||||
|
||||
type FeedbackItem = {
|
||||
id: string;
|
||||
kind: "反馈" | "建议";
|
||||
text: string;
|
||||
contact: string;
|
||||
at: string;
|
||||
};
|
||||
|
||||
export default function FeedbackClient() {
|
||||
const [kind, setKind] = useState<"反馈" | "建议">("建议");
|
||||
const [text, setText] = useState("");
|
||||
const [contact, setContact] = useState("");
|
||||
const [ok, setOk] = useState("");
|
||||
|
||||
const submit = async () => {
|
||||
if (!text.trim()) return;
|
||||
const payload = { kind, text: text.trim(), contact: contact.trim() };
|
||||
try {
|
||||
await socialApi.postFeedback(payload);
|
||||
setOk("已同步到游民社区独立库,感谢反馈。");
|
||||
} catch {
|
||||
const list = loadJson<FeedbackItem[]>("feedback", []);
|
||||
const item: FeedbackItem = {
|
||||
id: uid("fb"),
|
||||
kind,
|
||||
text: payload.text,
|
||||
contact: payload.contact,
|
||||
at: new Date().toISOString(),
|
||||
};
|
||||
saveJson("feedback", [item, ...list]);
|
||||
setOk("后端暂不可用,已先存本机。");
|
||||
}
|
||||
setText("");
|
||||
};
|
||||
|
||||
return (
|
||||
<SiteShell title="反馈">
|
||||
<section className="social-hero">
|
||||
<div className="social-hero-tag">远程团队</div>
|
||||
<h1>
|
||||
反馈 / 建议
|
||||
<br />
|
||||
<span>把槽点变成迭代清单</span>
|
||||
</h1>
|
||||
<p>写入独立 social 库,不影响现网其它业务表。</p>
|
||||
</section>
|
||||
|
||||
<section className="social-panel">
|
||||
<div className="social-form">
|
||||
<label>
|
||||
类型
|
||||
<select value={kind} onChange={(e) => setKind(e.target.value as "反馈" | "建议")}>
|
||||
<option value="建议">建议</option>
|
||||
<option value="反馈">反馈</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
内容
|
||||
<textarea
|
||||
rows={5}
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
placeholder="例如:希望 Coffeechat 支持按城市筛选…"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
联系方式(可选)
|
||||
<input value={contact} onChange={(e) => setContact(e.target.value)} />
|
||||
</label>
|
||||
<button type="button" className="social-btn primary" onClick={() => void submit()}>
|
||||
提交
|
||||
</button>
|
||||
{ok ? <p className="social-muted">{ok}</p> : null}
|
||||
</div>
|
||||
</section>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
export { CommunityFeedback as default } from "./CommunityWelcome";
|
||||
|
||||
@ -2,16 +2,20 @@
|
||||
|
||||
/** Dense CSS-only floating emoji field — obvious motion, no framer. */
|
||||
const EMOJIS = [
|
||||
{ e: "☕", x: "6%", y: "18%", delay: "0s", dur: "5.5s", size: "2.2rem" },
|
||||
{ e: "🌏", x: "88%", y: "22%", delay: "0.4s", dur: "6.2s", size: "2.4rem" },
|
||||
{ e: "💬", x: "78%", y: "58%", delay: "0.9s", dur: "5.2s", size: "1.9rem" },
|
||||
{ e: "🎒", x: "12%", y: "62%", delay: "1.3s", dur: "6.8s", size: "2rem" },
|
||||
{ e: "✨", x: "48%", y: "12%", delay: "0.2s", dur: "4.8s", size: "1.7rem" },
|
||||
{ e: "🤝", x: "58%", y: "70%", delay: "1.7s", dur: "5.9s", size: "2rem" },
|
||||
{ e: "🚀", x: "28%", y: "38%", delay: "0.7s", dur: "6.4s", size: "1.8rem" },
|
||||
{ e: "💚", x: "70%", y: "34%", delay: "1.1s", dur: "5.6s", size: "1.6rem" },
|
||||
{ e: "📡", x: "38%", y: "78%", delay: "1.5s", dur: "7s", size: "1.9rem" },
|
||||
{ e: "🔥", x: "92%", y: "72%", delay: "0.5s", dur: "5.1s", size: "1.8rem" },
|
||||
{ e: "☕", x: "5%", y: "16%", delay: "0s", dur: "4.8s", size: "2.4rem" },
|
||||
{ e: "🌏", x: "90%", y: "18%", delay: "0.35s", dur: "5.4s", size: "2.6rem" },
|
||||
{ e: "💬", x: "80%", y: "55%", delay: "0.7s", dur: "4.6s", size: "2.1rem" },
|
||||
{ e: "🎒", x: "10%", y: "58%", delay: "1.1s", dur: "5.8s", size: "2.2rem" },
|
||||
{ e: "✨", x: "46%", y: "8%", delay: "0.15s", dur: "4.2s", size: "1.9rem" },
|
||||
{ e: "🤝", x: "60%", y: "72%", delay: "1.4s", dur: "5.2s", size: "2.15rem" },
|
||||
{ e: "🚀", x: "26%", y: "36%", delay: "0.55s", dur: "5.6s", size: "2rem" },
|
||||
{ e: "💚", x: "72%", y: "30%", delay: "0.95s", dur: "4.9s", size: "1.75rem" },
|
||||
{ e: "📡", x: "36%", y: "78%", delay: "1.25s", dur: "6s", size: "2.05rem" },
|
||||
{ e: "🔥", x: "94%", y: "68%", delay: "0.4s", dur: "4.5s", size: "2rem" },
|
||||
{ e: "🌈", x: "18%", y: "28%", delay: "1.6s", dur: "5.3s", size: "1.85rem" },
|
||||
{ e: "🎯", x: "54%", y: "48%", delay: "0.85s", dur: "5.1s", size: "1.7rem" },
|
||||
{ e: "💫", x: "68%", y: "12%", delay: "1.8s", dur: "4.7s", size: "1.8rem" },
|
||||
{ e: "🌊", x: "42%", y: "62%", delay: "0.25s", dur: "5.9s", size: "1.95rem" },
|
||||
];
|
||||
|
||||
export default function FloatingEmojiField() {
|
||||
|
||||
@ -1,7 +1,24 @@
|
||||
"use client";
|
||||
|
||||
/** Endless emoji marquee between sections — CSS only. */
|
||||
const ROW = ["☕", "🌏", "💬", "🎒", "✨", "🤝", "📡", "🚀", "💚", "🎯", "🔥", "🌈"];
|
||||
const ROW = [
|
||||
"☕",
|
||||
"🌏",
|
||||
"💬",
|
||||
"🎒",
|
||||
"✨",
|
||||
"🤝",
|
||||
"📡",
|
||||
"🚀",
|
||||
"💚",
|
||||
"🎯",
|
||||
"🔥",
|
||||
"🌈",
|
||||
"💫",
|
||||
"🌊",
|
||||
"👋",
|
||||
"🎤",
|
||||
];
|
||||
|
||||
export default function FxBelt() {
|
||||
const line = [...ROW, ...ROW, ...ROW].join(" ");
|
||||
|
||||
@ -1,23 +1,24 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useState, type PointerEvent } from "react";
|
||||
import Link from "next/link";
|
||||
import SiteShell from "./SiteShell";
|
||||
import JoinPayModal from "./JoinPayModal";
|
||||
import AttractiveRoster from "./AttractiveRoster";
|
||||
import ParticleCanvas from "./ParticleCanvas";
|
||||
import FloatingEmojiField from "./FloatingEmojiField";
|
||||
import SectionSpark from "./SectionSpark";
|
||||
import WorldConnections from "./WorldConnections";
|
||||
import ConnectionHero, { ConnectionWays } from "./ConnectionHero";
|
||||
import FxBelt from "./FxBelt";
|
||||
import { SEED_CAFES, SEED_GIGS, SEED_MEETUPS, TEAM_KIND_LABEL } from "@social/lib/seed";
|
||||
import SectionSpark from "./SectionSpark";
|
||||
import { ArrowUpRight, Coffee, Radio, Sparkles } from "lucide-react";
|
||||
import {
|
||||
SEED_CAFES,
|
||||
SEED_GIGS,
|
||||
SEED_MEETUPS,
|
||||
TEAM_KIND_LABEL,
|
||||
} from "@social/lib/seed";
|
||||
import { socialPath } from "@social/lib/socialPath";
|
||||
import { useRemoteConfig } from "~/lib/use-remote-config";
|
||||
|
||||
const PHRASES = [
|
||||
"加群打个招呼,线下见面就不陌生。",
|
||||
"清迈、大理、曼谷——下一场咖啡局也许有你。",
|
||||
"Meetup 暖场、Coffeechat 深聊、远程一起做事。",
|
||||
];
|
||||
import { resolveSocialLandingCopy } from "@social/lib/landing";
|
||||
|
||||
const DEFAULT_PROMO =
|
||||
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4";
|
||||
@ -29,7 +30,6 @@ const PATH = [
|
||||
{ href: "#team", label: "远程组队", emoji: "🚀" },
|
||||
] as const;
|
||||
|
||||
const CAFE_EMOJI = ["☕", "🌿", "🌊", "🪵"] as const;
|
||||
const ROLE_EMOJI: Record<string, string> = {
|
||||
volunteer: "🙋",
|
||||
parttime: "📝",
|
||||
@ -39,49 +39,18 @@ const ROLE_EMOJI: Record<string, string> = {
|
||||
export default function HomeClient() {
|
||||
const { config } = useRemoteConfig();
|
||||
const [joinOpen, setJoinOpen] = useState(false);
|
||||
const [promoUrl, setPromoUrl] = useState(DEFAULT_PROMO);
|
||||
|
||||
useEffect(() => {
|
||||
const next =
|
||||
(config.modules?.social as { promoVideoUrl?: string } | undefined)?.promoVideoUrl?.trim() ||
|
||||
DEFAULT_PROMO;
|
||||
setPromoUrl(next);
|
||||
}, [config]);
|
||||
|
||||
useEffect(() => {
|
||||
const el = document.getElementById("social-typewriter");
|
||||
if (!el) return;
|
||||
let phraseIdx = 0;
|
||||
let charIdx = 0;
|
||||
let deleting = false;
|
||||
let timer: ReturnType<typeof setTimeout>;
|
||||
|
||||
const type = () => {
|
||||
const current = PHRASES[phraseIdx];
|
||||
if (!deleting) {
|
||||
el.textContent = current.substring(0, charIdx + 1);
|
||||
charIdx++;
|
||||
if (charIdx === current.length) {
|
||||
deleting = true;
|
||||
timer = setTimeout(type, 2500);
|
||||
return;
|
||||
}
|
||||
timer = setTimeout(type, 60);
|
||||
} else {
|
||||
el.textContent = current.substring(0, charIdx - 1);
|
||||
charIdx--;
|
||||
if (charIdx === 0) {
|
||||
deleting = false;
|
||||
phraseIdx = (phraseIdx + 1) % PHRASES.length;
|
||||
}
|
||||
timer = setTimeout(type, 30);
|
||||
}
|
||||
};
|
||||
timer = setTimeout(type, 400);
|
||||
return () => clearTimeout(timer);
|
||||
}, []);
|
||||
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);
|
||||
|
||||
useEffect(() => {
|
||||
const root = document.querySelector(".social-home");
|
||||
if (!root) return;
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) =>
|
||||
entries.forEach((e) => {
|
||||
@ -93,262 +62,347 @@ export default function HomeClient() {
|
||||
{ threshold: 0.06, rootMargin: "0px 0px -24px 0px" },
|
||||
);
|
||||
const scan = () => {
|
||||
document.querySelectorAll(".reveal:not(.visible)").forEach((el) => observer.observe(el));
|
||||
root
|
||||
.querySelectorAll(".reveal:not(.visible)")
|
||||
.forEach((el) => observer.observe(el));
|
||||
};
|
||||
scan();
|
||||
root.setAttribute("data-home-motion", "ready");
|
||||
const t = window.setTimeout(scan, 400);
|
||||
return () => {
|
||||
window.clearTimeout(t);
|
||||
observer.disconnect();
|
||||
root.removeAttribute("data-home-motion");
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const root = document.querySelector(".social-home");
|
||||
if (!root) return;
|
||||
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 () => observer.disconnect();
|
||||
}, []);
|
||||
|
||||
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">
|
||||
<ParticleCanvas />
|
||||
<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)}>
|
||||
<section className="hero social-hero-fx" id="hero">
|
||||
<div className="hero-bg-shapes" aria-hidden>
|
||||
<div className="shape shape-1" />
|
||||
<div className="shape shape-2" />
|
||||
<div className="shape shape-3" />
|
||||
</div>
|
||||
<FloatingEmojiField />
|
||||
<div className="connection-scroll-progress" aria-hidden="true" />
|
||||
<main id="social-main">
|
||||
<ConnectionHero
|
||||
onJoin={() => setJoinOpen(true)}
|
||||
promoUrl={promoUrl}
|
||||
copy={landingCopy}
|
||||
/>
|
||||
<ConnectionWays copy={landingCopy} />
|
||||
<WorldConnections />
|
||||
|
||||
<div className="hero-inner">
|
||||
<div className="hero-top">
|
||||
<div className="hero-content">
|
||||
<div className="hero-badge reveal">
|
||||
<span className="badge-dot" />
|
||||
nomadro · 数字游民社交
|
||||
</div>
|
||||
<h1 className="hero-title reveal">
|
||||
游民社区
|
||||
<br />
|
||||
<span className="gradient-text">认识同类,线下见面</span>
|
||||
</h1>
|
||||
<p className="hero-subtitle reveal">
|
||||
<span id="social-typewriter" />
|
||||
<span className="typewriter-cursor">|</span>
|
||||
</p>
|
||||
<div className="hero-actions reveal">
|
||||
<button type="button" className="btn btn-primary social-btn-pulse" onClick={() => setJoinOpen(true)}>
|
||||
<span>加群</span>
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M5 12h14M12 5l7 7-7 7" />
|
||||
</svg>
|
||||
</button>
|
||||
<a href="#people" className="btn btn-ghost">
|
||||
看看谁在线
|
||||
<nav className="social-path" aria-label="本页导航">
|
||||
<div className="container">
|
||||
<div className="social-path-track reveal">
|
||||
{PATH.map((p) => (
|
||||
<a
|
||||
key={p.href}
|
||||
href={p.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>
|
||||
|
||||
<div className="hero-visual reveal">
|
||||
<div className="social-promo social-promo-glow">
|
||||
<video
|
||||
className="social-promo-video"
|
||||
src={promoUrl}
|
||||
controls
|
||||
playsInline
|
||||
preload="metadata"
|
||||
aria-label="游民社区宣传片"
|
||||
/>
|
||||
<div className="social-promo-badge">
|
||||
<span className="social-promo-live" aria-hidden />
|
||||
宣传片
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</nav>
|
||||
|
||||
<nav className="social-path" aria-label="本页导航">
|
||||
<div className="container">
|
||||
<div className="social-path-track reveal">
|
||||
{PATH.map((p) => (
|
||||
<a key={p.href} href={p.href} className="social-path-link">
|
||||
<span className="social-path-emoji" aria-hidden>
|
||||
{p.emoji}
|
||||
<AttractiveRoster onJoin={() => setJoinOpen(true)} />
|
||||
|
||||
<FxBelt />
|
||||
|
||||
<section
|
||||
className="section section-compact social-section-alt"
|
||||
id="meetup"
|
||||
aria-label="Meetup"
|
||||
>
|
||||
<div className="container">
|
||||
<div className="section-header reveal">
|
||||
<SectionSpark label="meetup" />
|
||||
<span className="section-tag">
|
||||
<span>02 / MEETUP</span>
|
||||
<span>让想法在对话中发生</span>
|
||||
</span>
|
||||
<h2>
|
||||
<span className="social-title-emoji" aria-hidden>
|
||||
📡
|
||||
</span>
|
||||
{p.label}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<AttractiveRoster onJoin={() => setJoinOpen(true)} />
|
||||
|
||||
<FxBelt />
|
||||
|
||||
<section className="section section-compact social-section-alt" id="meetup" aria-label="Meetup">
|
||||
<div className="container">
|
||||
<div className="section-header reveal">
|
||||
<SectionSpark label="meetup" />
|
||||
<span className="section-tag">MEETUP</span>
|
||||
<h2>
|
||||
<span className="social-title-emoji" aria-hidden>
|
||||
📡
|
||||
</span>
|
||||
今晚有人在等你进房
|
||||
</h2>
|
||||
<p>本周 {SEED_MEETUPS.length} 场 · 可只听不说 · 进房就能搭话</p>
|
||||
</div>
|
||||
<div className="social-panel-grid social-panel-grid-2">
|
||||
{SEED_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` }}
|
||||
隔着屏幕,也能聊到同频
|
||||
</h2>
|
||||
<p>
|
||||
{SEED_MEETUPS.length} 场活动预览 ·
|
||||
可以先听听,再慢慢打开话匣子
|
||||
</p>
|
||||
</div>
|
||||
<div className="social-panel-grid social-panel-grid-2">
|
||||
{SEED_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" aria-hidden="true">
|
||||
<span className="connection-meetup-number">0{i + 1}</span>
|
||||
<div className="connection-audio-bars">
|
||||
{Array.from({ length: 18 }, (_, n) => (
|
||||
<i
|
||||
key={n}
|
||||
style={{
|
||||
height: `${12 + ((n * 17 + i * 13) % 55)}px`,
|
||||
animationDelay: `${n * -0.15}s`,
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<Radio size={26} strokeWidth={1.2} />
|
||||
</div>
|
||||
<div className="social-panel-meta">
|
||||
<span>{m.city === "Online" ? "线上" : m.city}</span>
|
||||
<time>
|
||||
{m.date} · {m.time}
|
||||
</time>
|
||||
</div>
|
||||
<h3>{m.title}</h3>
|
||||
<p>文字暖场 → MiroTalk 开麦 → 认识新朋友</p>
|
||||
<Link
|
||||
className="btn btn-primary btn-sm"
|
||||
href={socialPath(`/meetup/${m.id}`)}
|
||||
>
|
||||
进房
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
aria-hidden
|
||||
>
|
||||
<path d="M5 12h14M12 5l7 7-7 7" />
|
||||
</svg>
|
||||
</Link>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
<div className="social-section-actions reveal">
|
||||
<Link href={socialPath("/meetup")} className="btn btn-ghost">
|
||||
全部 Meetup
|
||||
</Link>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost"
|
||||
onClick={() => setJoinOpen(true)}
|
||||
>
|
||||
<div className="social-panel-ico" aria-hidden>
|
||||
<svg viewBox="0 0 48 48" width="40" height="40">
|
||||
<circle cx="24" cy="24" r="22" fill="none" stroke="currentColor" strokeOpacity="0.25" strokeWidth="2" />
|
||||
<circle cx="24" cy="24" r="14" fill="none" stroke="currentColor" strokeOpacity="0.45" strokeWidth="2" className="social-ring-spin" />
|
||||
<text x="24" y="28" textAnchor="middle" fontSize="16">
|
||||
📹
|
||||
</text>
|
||||
</svg>
|
||||
</div>
|
||||
<div className="social-panel-meta">
|
||||
<span>{m.city === "Online" ? "线上" : m.city}</span>
|
||||
<time>
|
||||
{m.date} · {m.time}
|
||||
</time>
|
||||
</div>
|
||||
<h3>{m.title}</h3>
|
||||
<p>文字暖场 → MiroTalk 开麦 → 认识新朋友</p>
|
||||
<Link className="btn btn-primary btn-sm" href={socialPath(`/meetup/${m.id}`)}>
|
||||
进房
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden>
|
||||
<path d="M5 12h14M12 5l7 7-7 7" />
|
||||
</svg>
|
||||
</Link>
|
||||
</article>
|
||||
))}
|
||||
加群占座
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="social-section-actions reveal">
|
||||
<Link href={socialPath("/meetup")} className="btn btn-ghost">
|
||||
全部 Meetup
|
||||
</Link>
|
||||
<button type="button" className="btn btn-ghost" onClick={() => setJoinOpen(true)}>
|
||||
加群占座
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<FxBelt />
|
||||
<FxBelt />
|
||||
|
||||
<section className="section section-compact" id="coffeechat" aria-label="Coffeechat">
|
||||
<div className="container">
|
||||
<div className="section-header reveal">
|
||||
<SectionSpark label="coffee" />
|
||||
<span className="section-tag">COFFEECHAT</span>
|
||||
<h2>
|
||||
<span className="social-title-emoji" aria-hidden>
|
||||
☕
|
||||
<section
|
||||
className="section section-compact"
|
||||
id="coffeechat"
|
||||
aria-label="Coffeechat"
|
||||
>
|
||||
<div className="container">
|
||||
<div className="section-header reveal">
|
||||
<SectionSpark label="coffee" />
|
||||
<span className="section-tag">
|
||||
<span>03 / COFFEECHAT</span>
|
||||
<span>把线上默契,带到线下</span>
|
||||
</span>
|
||||
咖啡馆里把网友变朋友
|
||||
</h2>
|
||||
<p>精选合作店 · 插座够 · 适合 1v1 / 小局</p>
|
||||
</div>
|
||||
<div className="social-panel-grid social-panel-grid-4">
|
||||
{SEED_CAFES.map((c, i) => (
|
||||
<article
|
||||
key={c.id}
|
||||
className="social-panel social-panel-fx reveal"
|
||||
style={{ ["--stagger" as string]: `${i * 70}ms` }}
|
||||
<h2>
|
||||
<span className="social-title-emoji" aria-hidden>
|
||||
☕
|
||||
</span>
|
||||
咖啡馆里把网友变朋友
|
||||
</h2>
|
||||
<p>精选合作店 · 插座够 · 适合 1v1 / 小局</p>
|
||||
</div>
|
||||
<div className="social-panel-grid social-panel-grid-4">
|
||||
{SEED_CAFES.map((c, i) => (
|
||||
<article
|
||||
key={c.id}
|
||||
className={`social-panel social-panel-fx connection-cafe connection-cafe-${i} reveal`}
|
||||
style={{ ["--stagger" as string]: `${i * 70}ms` }}
|
||||
>
|
||||
<div
|
||||
className="social-panel-ico social-panel-ico-bounce"
|
||||
aria-hidden
|
||||
>
|
||||
<Coffee size={27} strokeWidth={1.3} />
|
||||
</div>
|
||||
<div className="social-panel-meta">
|
||||
<span>{c.city}</span>
|
||||
{c.partners ? (
|
||||
<span className="is-warm">合作店</span>
|
||||
) : null}
|
||||
</div>
|
||||
<h3>{c.name}</h3>
|
||||
<p>{c.vibe}</p>
|
||||
<div className="social-panel-foot">
|
||||
<span>⭐ {c.rating}</span>
|
||||
<span>📶 {c.wifiMbps}M</span>
|
||||
</div>
|
||||
<Link
|
||||
className="btn btn-primary btn-sm"
|
||||
href={socialPath("/coffeechat")}
|
||||
>
|
||||
约见
|
||||
</Link>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
<div className="social-section-actions reveal">
|
||||
<Link
|
||||
href={socialPath("/coffeechat")}
|
||||
className="btn btn-ghost"
|
||||
>
|
||||
<div className="social-panel-ico social-panel-ico-bounce" aria-hidden>
|
||||
{CAFE_EMOJI[i % CAFE_EMOJI.length]}
|
||||
</div>
|
||||
<div className="social-panel-meta">
|
||||
<span>{c.city}</span>
|
||||
{c.partners ? <span className="is-warm">合作店</span> : null}
|
||||
</div>
|
||||
<h3>{c.name}</h3>
|
||||
<p>{c.vibe}</p>
|
||||
<div className="social-panel-foot">
|
||||
<span>⭐ {c.rating}</span>
|
||||
<span>📶 {c.wifiMbps}M</span>
|
||||
</div>
|
||||
<Link className="btn btn-primary btn-sm" href={socialPath("/coffeechat")}>
|
||||
约见
|
||||
</Link>
|
||||
</article>
|
||||
))}
|
||||
全部咖啡馆
|
||||
</Link>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost"
|
||||
onClick={() => setJoinOpen(true)}
|
||||
>
|
||||
加群找同城
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="social-section-actions reveal">
|
||||
<Link href={socialPath("/coffeechat")} className="btn btn-ghost">
|
||||
全部咖啡馆
|
||||
</Link>
|
||||
<button type="button" className="btn btn-ghost" onClick={() => setJoinOpen(true)}>
|
||||
加群找同城
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<FxBelt />
|
||||
<FxBelt />
|
||||
|
||||
<section className="section section-compact social-section-alt" id="team" aria-label="远程团队">
|
||||
<div className="container">
|
||||
<div className="section-header reveal">
|
||||
<SectionSpark label="team" />
|
||||
<span className="section-tag">TEAM</span>
|
||||
<h2>
|
||||
<span className="social-title-emoji" aria-hidden>
|
||||
🚀
|
||||
<section
|
||||
className="section section-compact social-section-alt"
|
||||
id="team"
|
||||
aria-label="远程团队"
|
||||
>
|
||||
<div className="container">
|
||||
<div className="section-header reveal">
|
||||
<SectionSpark label="team" />
|
||||
<span className="section-tag">
|
||||
<span>04 / CO-CREATE</span>
|
||||
<span>好的伙伴,让自由走得更远</span>
|
||||
</span>
|
||||
找靠谱搭档一起干
|
||||
</h2>
|
||||
<p>志愿 / 兼职 / 全职 · 先聊人再投 · 群里可问内推</p>
|
||||
</div>
|
||||
<div className="social-panel-grid social-panel-grid-3">
|
||||
{SEED_GIGS.slice(0, 6).map((g, i) => (
|
||||
<article
|
||||
key={g.id}
|
||||
className="social-panel social-panel-fx reveal"
|
||||
style={{ ["--stagger" as string]: `${i * 60}ms` }}
|
||||
<h2>
|
||||
<span className="social-title-emoji" aria-hidden>
|
||||
🚀
|
||||
</span>
|
||||
有些可能,适合一起实现
|
||||
</h2>
|
||||
<p>志愿 / 兼职 / 全职 · 先聊人再投 · 群里可问内推</p>
|
||||
</div>
|
||||
<div className="social-panel-grid social-panel-grid-3">
|
||||
{SEED_GIGS.slice(0, 6).map((g, i) => (
|
||||
<article
|
||||
key={g.id}
|
||||
className="social-panel social-panel-fx connection-team reveal"
|
||||
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
|
||||
className="btn btn-primary btn-sm"
|
||||
href={socialPath("/team")}
|
||||
>
|
||||
聊聊
|
||||
</Link>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
<div className="social-section-actions reveal">
|
||||
<Link href={socialPath("/team")} className="btn btn-ghost">
|
||||
全部岗位
|
||||
</Link>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost"
|
||||
onClick={() => setJoinOpen(true)}
|
||||
>
|
||||
<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 className="btn btn-primary btn-sm" href={socialPath("/team")}>
|
||||
聊聊
|
||||
</Link>
|
||||
</article>
|
||||
))}
|
||||
加群问内推
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="social-section-actions reveal">
|
||||
<Link href={socialPath("/team")} className="btn btn-ghost">
|
||||
全部岗位
|
||||
</Link>
|
||||
<button type="button" className="btn btn-ghost" onClick={() => setJoinOpen(true)}>
|
||||
加群问内推
|
||||
</button>
|
||||
</section>
|
||||
|
||||
<section
|
||||
className="connection-invite container"
|
||||
aria-label="加入社区"
|
||||
>
|
||||
<div className="connection-invite-orbit" aria-hidden="true">
|
||||
<span />
|
||||
<span />
|
||||
<Sparkles size={52} strokeWidth={1} />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<div>
|
||||
<span className="connection-eyebrow">YOUR NEXT CHAPTER</span>
|
||||
<h2>{landingCopy.socialInviteTitle}</h2>
|
||||
<p>{landingCopy.socialInviteLead}</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="btn connection-join"
|
||||
onClick={() => setJoinOpen(true)}
|
||||
>
|
||||
加入游民社区 <ArrowUpRight size={19} />
|
||||
</button>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<footer className="footer">
|
||||
<div className="container">
|
||||
@ -362,7 +416,11 @@ export default function HomeClient() {
|
||||
</div>
|
||||
<div className="footer-links">
|
||||
<h4>连接</h4>
|
||||
<button type="button" className="social-footer-link" onClick={() => setJoinOpen(true)}>
|
||||
<button
|
||||
type="button"
|
||||
className="social-footer-link"
|
||||
onClick={() => setJoinOpen(true)}
|
||||
>
|
||||
加群
|
||||
</button>
|
||||
<Link href={socialPath("/chat")}>聊天室</Link>
|
||||
@ -384,7 +442,9 @@ export default function HomeClient() {
|
||||
</div>
|
||||
</div>
|
||||
<div className="footer-bottom">
|
||||
<p suppressHydrationWarning>© {new Date().getFullYear()} nomadro · 游民社区</p>
|
||||
<p suppressHydrationWarning>
|
||||
© {new Date().getFullYear()} nomadro · 游民社区
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
@ -1,54 +1,3 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { WechatOaModal } from "~/components/social-follow";
|
||||
import SiteShell from "./SiteShell";
|
||||
import { socialPath } from "@social/lib/socialPath";
|
||||
|
||||
export default function JoinClient() {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<SiteShell title="加群">
|
||||
<section className="social-hero">
|
||||
<div className="social-hero-tag">线上社区</div>
|
||||
<h1>
|
||||
加入游民社区
|
||||
<br />
|
||||
<span>找到同频旅伴</span>
|
||||
</h1>
|
||||
<p>个人主体小程序不能嵌 web-view;Web 端用公众号 / 抖音群引导进群,再回聊天室继续聊。</p>
|
||||
</section>
|
||||
|
||||
<div className="social-grid">
|
||||
<button type="button" className="social-card social-card-btn" onClick={() => setOpen(true)}>
|
||||
<div className="social-card-top">
|
||||
<span className="social-card-ico">🚩</span>
|
||||
<span className="social-badge live">开放</span>
|
||||
</div>
|
||||
<strong>打开加群引导</strong>
|
||||
<p>按后台开关展示公众号或抖音群二维码</p>
|
||||
</button>
|
||||
<Link href={socialPath("/chat")} className="social-card">
|
||||
<div className="social-card-top">
|
||||
<span className="social-card-ico">💬</span>
|
||||
<span className="social-badge live">下一步</span>
|
||||
</div>
|
||||
<strong>进入实时聊天室</strong>
|
||||
<p>加群后也可先在站内频道报到</p>
|
||||
</Link>
|
||||
<Link href={socialPath("/roster")} className="social-card">
|
||||
<div className="social-card-top">
|
||||
<span className="social-card-ico">📇</span>
|
||||
<span className="social-badge">推荐</span>
|
||||
</div>
|
||||
<strong>完善职业花名册</strong>
|
||||
<p>填写资料,方便同城 / 同业匹配</p>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<WechatOaModal open={open} onClose={() => setOpen(false)} />
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
export { CommunityJoin as default } from "./CommunityWelcome";
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useId, useState } from "react";
|
||||
import { useEffect, useId, useRef, useState } from "react";
|
||||
import { isWeChat } from "@nomadro/pay";
|
||||
import { ArrowUpRight, LockKeyhole, Sparkles, X } from "lucide-react";
|
||||
|
||||
type Props = {
|
||||
open: boolean;
|
||||
@ -15,42 +16,53 @@ const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
* PC/H5 → zpay;微信内 H5 → xpay(xorpay);小程序 WebView 提示走虚拟支付
|
||||
*/
|
||||
export default function JoinPayModal({ open, onClose }: Props) {
|
||||
return open ? <JoinPaySheet onClose={onClose} /> : null;
|
||||
}
|
||||
|
||||
function JoinPaySheet({ onClose }: Pick<Props, "onClose">) {
|
||||
const titleId = useId();
|
||||
const [email, setEmail] = useState("");
|
||||
const descriptionId = useId();
|
||||
const errorId = useId();
|
||||
const dialogRef = useRef<HTMLDialogElement>(null);
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const [email, setEmail] = useState(() => {
|
||||
try {
|
||||
return localStorage.getItem("userEmail") || "";
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [err, setErr] = useState("");
|
||||
const [channelHint, setChannelHint] = useState("浏览器将使用 z-pay。");
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
setErr("");
|
||||
try {
|
||||
const saved = localStorage.getItem("userEmail") || "";
|
||||
if (saved) setEmail(saved);
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
|
||||
const [channelHint] = useState(() => {
|
||||
if (typeof navigator === "undefined") return "确认邮箱后,前往安全支付。";
|
||||
const inMiniProgram =
|
||||
/miniProgram/i.test(navigator.userAgent) ||
|
||||
(window as unknown as { __wxjs_environment?: string }).__wxjs_environment ===
|
||||
"miniprogram";
|
||||
setChannelHint(
|
||||
inMiniProgram
|
||||
? "将进入小程序虚拟支付。"
|
||||
: isWeChat()
|
||||
? "微信内将使用 x-pay。"
|
||||
: "浏览器将使用 z-pay。",
|
||||
);
|
||||
(window as unknown as { __wxjs_environment?: string })
|
||||
.__wxjs_environment === "miniprogram";
|
||||
return inMiniProgram
|
||||
? "将前往小程序支付入口。"
|
||||
: isWeChat()
|
||||
? "将在微信内完成安全支付。"
|
||||
: "确认邮箱后,前往安全支付。";
|
||||
});
|
||||
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape" && !busy) onClose();
|
||||
useEffect(() => {
|
||||
const dialog = dialogRef.current;
|
||||
const opener = document.activeElement as HTMLElement | null;
|
||||
const previousOverflow = document.body.style.overflow;
|
||||
dialog?.showModal();
|
||||
inputRef.current?.focus();
|
||||
document.body.style.overflow = "hidden";
|
||||
return () => {
|
||||
dialog?.close();
|
||||
document.body.style.overflow = previousOverflow;
|
||||
opener?.focus();
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, [open, onClose, busy]);
|
||||
}, []);
|
||||
|
||||
const submit = async () => {
|
||||
if (busy) return;
|
||||
const value = email.trim().toLowerCase();
|
||||
if (!EMAIL_RE.test(value)) {
|
||||
setErr("请输入有效邮箱");
|
||||
@ -64,8 +76,8 @@ export default function JoinPayModal({ open, onClose }: Props) {
|
||||
|
||||
const inMiniProgram =
|
||||
/miniProgram/i.test(navigator.userAgent) ||
|
||||
(window as unknown as { __wxjs_environment?: string }).__wxjs_environment ===
|
||||
"miniprogram";
|
||||
(window as unknown as { __wxjs_environment?: string })
|
||||
.__wxjs_environment === "miniprogram";
|
||||
|
||||
if (inMiniProgram) {
|
||||
window.location.href = "/vip";
|
||||
@ -82,24 +94,25 @@ export default function JoinPayModal({ open, onClose }: Props) {
|
||||
}
|
||||
};
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
className="social-join-overlay"
|
||||
role="presentation"
|
||||
<dialog
|
||||
ref={dialogRef}
|
||||
className="social-join-overlay social-join-dialog"
|
||||
aria-labelledby={titleId}
|
||||
aria-describedby={descriptionId}
|
||||
onCancel={(event) => {
|
||||
event.preventDefault();
|
||||
if (!busy) onClose();
|
||||
}}
|
||||
onClick={(e) => {
|
||||
if (e.target === e.currentTarget && !busy) onClose();
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="social-join-sheet"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby={titleId}
|
||||
>
|
||||
<div className="social-join-sheet">
|
||||
<header className="social-join-sheet-head">
|
||||
<h2 id={titleId}>加群</h2>
|
||||
<span className="social-join-brand">
|
||||
<Sparkles size={17} /> NOMADRO SOCIAL
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
className="social-join-close"
|
||||
@ -107,22 +120,29 @@ export default function JoinPayModal({ open, onClose }: Props) {
|
||||
disabled={busy}
|
||||
onClick={onClose}
|
||||
>
|
||||
×
|
||||
<X size={18} />
|
||||
</button>
|
||||
</header>
|
||||
<p className="social-muted">
|
||||
加入后可打招呼、约 Coffeechat、进 Meetup。{channelHint}
|
||||
<h2 id={titleId} className="social-join-title">
|
||||
加群,遇见你的同类。
|
||||
</h2>
|
||||
<p id={descriptionId} className="social-muted">
|
||||
一起聊天、喝咖啡、做点有趣的事。
|
||||
<br />
|
||||
{channelHint}
|
||||
</p>
|
||||
|
||||
<label className="social-join-field">
|
||||
邮箱
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="email"
|
||||
inputMode="email"
|
||||
autoComplete="email"
|
||||
autoFocus
|
||||
placeholder="you@example.com"
|
||||
value={email}
|
||||
aria-invalid={Boolean(err)}
|
||||
aria-describedby={err ? errorId : undefined}
|
||||
disabled={busy}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
@ -130,16 +150,24 @@ export default function JoinPayModal({ open, onClose }: Props) {
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
{err ? <p className="social-join-err">{err}</p> : null}
|
||||
{err ? (
|
||||
<p id={errorId} className="social-join-err" role="alert">
|
||||
{err}
|
||||
</p>
|
||||
) : null}
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary social-join-submit"
|
||||
disabled={busy}
|
||||
onClick={() => void submit()}
|
||||
>
|
||||
{busy ? "正在拉起支付…" : "确认并支付"}
|
||||
{busy ? "正在前往支付…" : "确认并支付"}
|
||||
<ArrowUpRight size={17} />
|
||||
</button>
|
||||
<p className="social-join-privacy">
|
||||
<LockKeyhole size={11} /> 邮箱用于账号识别,请填写常用邮箱
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</dialog>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,43 +1,3 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import SiteShell from "./SiteShell";
|
||||
import { SEED_MEETUPS } from "@social/lib/seed";
|
||||
import { socialPath } from "@social/lib/socialPath";
|
||||
|
||||
export default function MeetupClient() {
|
||||
return (
|
||||
<SiteShell title="Meetup">
|
||||
<section className="social-hero">
|
||||
<div className="social-hero-tag">MEETUP</div>
|
||||
<h1>
|
||||
Meetup
|
||||
<br />
|
||||
<span>视频房 + 文字频道</span>
|
||||
</h1>
|
||||
<p>先进房暖场,再开麦认识人。可分屏切换视频与聊天。</p>
|
||||
</section>
|
||||
|
||||
<div className="social-list">
|
||||
{SEED_MEETUPS.map((m) => (
|
||||
<article key={m.id} className="social-list-item social-list-stack">
|
||||
<div>
|
||||
<strong>{m.title}</strong>
|
||||
<p>
|
||||
{m.date} {m.time} · {m.city} · {m.mode}
|
||||
</p>
|
||||
</div>
|
||||
<div className="social-actions">
|
||||
<Link className="social-btn primary" href={socialPath(`/meetup/${m.id}`)}>
|
||||
进入活动
|
||||
</Link>
|
||||
<Link className="social-btn" href={socialPath(`/chat/${m.channelId}`)}>
|
||||
仅文字频道
|
||||
</Link>
|
||||
</div>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
export { default } from "./EventDirectory";
|
||||
|
||||
@ -1,320 +1,3 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { socialApi } from "@social/lib/api";
|
||||
import { MIROTALK_URL, SEED_CHANNELS, SEED_MEETUPS, SEED_MESSAGES } from "@social/lib/seed";
|
||||
import { loadJson, saveJson } from "@social/lib/storage";
|
||||
import type { SocialChatMessage } from "@social/lib/types";
|
||||
import { socialPath } from "@social/lib/socialPath";
|
||||
|
||||
type Layout = "split" | "video" | "chat";
|
||||
|
||||
/** Origins allowed by MiroTalk ALLOWED_EMBED_ORIGINS (82 本机 mirotalk.nomadro.cn). */
|
||||
const EMBED_OK = new Set([
|
||||
"https://nomadro.cn",
|
||||
"https://www.nomadro.cn",
|
||||
"https://nomadweb.nomadro.com",
|
||||
"https://social.nomadro.cn",
|
||||
"http://localhost:3000",
|
||||
"http://127.0.0.1:3000",
|
||||
"http://localhost:3001",
|
||||
"http://127.0.0.1:3001",
|
||||
]);
|
||||
|
||||
function joinUrl(room: string, name: string) {
|
||||
// notify=0: never open MiroTalk "Share the room" popup
|
||||
// chat=0: use portal side chat; keep A/V on for the live room
|
||||
const q = new URLSearchParams({
|
||||
room,
|
||||
name,
|
||||
notify: "0",
|
||||
chat: "0",
|
||||
audio: "1",
|
||||
video: "1",
|
||||
});
|
||||
return `${MIROTALK_URL.replace(/\/$/, "")}/join?${q.toString()}`;
|
||||
}
|
||||
|
||||
function canEmbedHere() {
|
||||
if (typeof window === "undefined") return true;
|
||||
return EMBED_OK.has(window.location.origin);
|
||||
}
|
||||
|
||||
function warmMirotalkOrigin() {
|
||||
try {
|
||||
const origin = new URL(MIROTALK_URL).origin;
|
||||
for (const rel of ["dns-prefetch", "preconnect"] as const) {
|
||||
if (document.querySelector(`link[rel="${rel}"][href="${origin}"]`)) continue;
|
||||
const link = document.createElement("link");
|
||||
link.rel = rel;
|
||||
link.href = origin;
|
||||
if (rel === "preconnect") link.crossOrigin = "anonymous";
|
||||
document.head.appendChild(link);
|
||||
}
|
||||
// Warm HTML/JS edge cache (no media) so first iframe paint is faster
|
||||
void fetch(`${origin}/js/nomadro-speed.js`, {
|
||||
mode: "no-cors",
|
||||
credentials: "omit",
|
||||
cache: "force-cache",
|
||||
}).catch(() => undefined);
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
export default function MeetupLiveClient({ meetupId }: { meetupId: string }) {
|
||||
const meetup = SEED_MEETUPS.find((m) => m.id === meetupId) || SEED_MEETUPS[0];
|
||||
const channel =
|
||||
SEED_CHANNELS.find((c) => c.id === meetup.channelId) || SEED_CHANNELS[0];
|
||||
const storageKey = `chat:${channel.id}`;
|
||||
const seedForRoom = useMemo(
|
||||
() => SEED_MESSAGES.filter((m) => m.channelId === channel.id),
|
||||
[channel.id],
|
||||
);
|
||||
|
||||
const [layout, setLayout] = useState<Layout>("split");
|
||||
const [nick, setNick] = useState("游民");
|
||||
/** Frozen at auto-join so nick edits don't remount the iframe. */
|
||||
const [joinName, setJoinName] = useState("");
|
||||
const [text, setText] = useState("");
|
||||
const [messages, setMessages] = useState<SocialChatMessage[]>([]);
|
||||
const [videoReady, setVideoReady] = useState(false);
|
||||
const [embedBlocked, setEmbedBlocked] = useState(false);
|
||||
const [iframeLoading, setIframeLoading] = useState(true);
|
||||
const bottomRef = useRef<HTMLDivElement>(null);
|
||||
const videoSrc = useMemo(
|
||||
() => joinUrl(meetup.mirotalkRoom, joinName || "游民"),
|
||||
[meetup.mirotalkRoom, joinName],
|
||||
);
|
||||
const preferEmbed = canEmbedHere() && !embedBlocked;
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
try {
|
||||
const res = await socialApi.listMessages(channel.id);
|
||||
const items = (res.items || []).map((m) => ({
|
||||
id: m.id,
|
||||
channelId: m.channelId,
|
||||
author: m.author,
|
||||
text: m.text,
|
||||
at: m.at,
|
||||
}));
|
||||
setMessages(items.length ? items : loadJson(storageKey, seedForRoom));
|
||||
if (items.length) saveJson(storageKey, items);
|
||||
} catch {
|
||||
setMessages(loadJson(storageKey, seedForRoom));
|
||||
}
|
||||
}, [channel.id, seedForRoom, storageKey]);
|
||||
|
||||
// Instant join: hydrate nick → start iframe immediately (no "开始视频" gate)
|
||||
useEffect(() => {
|
||||
warmMirotalkOrigin();
|
||||
const name = (loadJson("nick", "游民") || "游民").trim() || "游民";
|
||||
setNick(name);
|
||||
setJoinName(name);
|
||||
if (canEmbedHere()) {
|
||||
setIframeLoading(true);
|
||||
setVideoReady(true);
|
||||
}
|
||||
void refresh();
|
||||
const id = window.setInterval(() => void refresh(), 4000);
|
||||
return () => clearInterval(id);
|
||||
}, [refresh]);
|
||||
|
||||
useEffect(() => {
|
||||
bottomRef.current?.scrollIntoView({ behavior: "smooth" });
|
||||
}, [messages]);
|
||||
|
||||
const send = async () => {
|
||||
const body = text.trim();
|
||||
if (!body) return;
|
||||
const author = nick.trim() || "游民";
|
||||
try {
|
||||
await socialApi.sendMessage(channel.id, author, body);
|
||||
saveJson("nick", author);
|
||||
setText("");
|
||||
await refresh();
|
||||
} catch {
|
||||
const next: SocialChatMessage = {
|
||||
id: `local_${Date.now()}`,
|
||||
channelId: channel.id,
|
||||
author,
|
||||
text: body,
|
||||
at: new Date().toISOString(),
|
||||
mine: true,
|
||||
};
|
||||
const merged = [...messages, next];
|
||||
setMessages(merged);
|
||||
saveJson(storageKey, merged);
|
||||
saveJson("nick", author);
|
||||
setText("");
|
||||
}
|
||||
};
|
||||
|
||||
const startVideo = (forceReload = false) => {
|
||||
const name = nick.trim() || "游民";
|
||||
saveJson("nick", name);
|
||||
setJoinName(name);
|
||||
if (!preferEmbed) {
|
||||
window.location.assign(joinUrl(meetup.mirotalkRoom, name));
|
||||
return;
|
||||
}
|
||||
setIframeLoading(true);
|
||||
if (forceReload && videoReady) {
|
||||
// remount iframe with new name only when user asks
|
||||
setVideoReady(false);
|
||||
window.requestAnimationFrame(() => setVideoReady(true));
|
||||
} else {
|
||||
setVideoReady(true);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="social-root social-live-root">
|
||||
<header className="social-live-bar">
|
||||
<div className="social-live-bar-main">
|
||||
<Link href={socialPath("/meetup")} className="social-nav-back">
|
||||
← 活动列表
|
||||
</Link>
|
||||
<div>
|
||||
<strong>{meetup.title}</strong>
|
||||
<p className="social-muted">
|
||||
{meetup.date} {meetup.time} · {channel.name}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="social-live-bar-tools">
|
||||
<label className="social-live-nick">
|
||||
<span className="social-muted">昵称</span>
|
||||
<input
|
||||
value={nick}
|
||||
onChange={(e) => setNick(e.target.value)}
|
||||
onBlur={() => saveJson("nick", nick.trim() || "游民")}
|
||||
maxLength={24}
|
||||
aria-label="显示名"
|
||||
/>
|
||||
</label>
|
||||
{videoReady && preferEmbed && nick.trim() && nick.trim() !== joinName ? (
|
||||
<button
|
||||
type="button"
|
||||
className="social-btn"
|
||||
onClick={() => startVideo(true)}
|
||||
title="用新昵称重进视频"
|
||||
>
|
||||
重进
|
||||
</button>
|
||||
) : null}
|
||||
<div className="social-live-tabs" role="tablist" aria-label="布局">
|
||||
{(["split", "video", "chat"] as const).map((m) => (
|
||||
<button
|
||||
key={m}
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={layout === m}
|
||||
className={`social-live-tab${layout === m ? " active" : ""}`}
|
||||
onClick={() => setLayout(m)}
|
||||
>
|
||||
{m === "split" ? "分屏" : m === "video" ? "视频" : "文字"}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className={`social-live-stage layout-${layout}`}>
|
||||
{(layout === "split" || layout === "video") && (
|
||||
<section className="social-live-video" aria-label="视频房间">
|
||||
{!videoReady ? (
|
||||
<div className="social-live-gate">
|
||||
<h2>进入视频房间</h2>
|
||||
<p>
|
||||
{preferEmbed
|
||||
? "正在准备极速进房…"
|
||||
: "当前域名未在视频 CSP 白名单,将在本页跳转进入(不新开标签)。"}
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
className="social-btn primary"
|
||||
onClick={() => startVideo()}
|
||||
>
|
||||
立即进入
|
||||
</button>
|
||||
</div>
|
||||
) : preferEmbed ? (
|
||||
<div className="social-live-frame-wrap">
|
||||
{iframeLoading && (
|
||||
<div className="social-live-iframe-overlay social-live-iframe-overlay--thin" aria-live="polite">
|
||||
<div className="social-live-iframe-mark" aria-hidden>
|
||||
N
|
||||
</div>
|
||||
<p>接通中…</p>
|
||||
</div>
|
||||
)}
|
||||
<iframe
|
||||
title={`${meetup.title} video`}
|
||||
src={videoSrc}
|
||||
className="social-live-iframe"
|
||||
allow="camera; microphone; display-capture; autoplay; fullscreen; clipboard-write"
|
||||
referrerPolicy="no-referrer-when-downgrade"
|
||||
loading="eager"
|
||||
onLoad={() => setIframeLoading(false)}
|
||||
onError={() => {
|
||||
setEmbedBlocked(true);
|
||||
setIframeLoading(false);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="social-live-gate">
|
||||
<h2>本页跳转进房</h2>
|
||||
<p>不新开标签;浏览器返回即可回到游民社区。</p>
|
||||
<button
|
||||
type="button"
|
||||
className="social-btn primary"
|
||||
onClick={() => window.location.assign(videoSrc)}
|
||||
>
|
||||
立即进入
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
)}
|
||||
|
||||
{(layout === "split" || layout === "chat") && (
|
||||
<section className="social-live-chat" aria-label="文字频道">
|
||||
<div className="social-live-chat-head">
|
||||
<strong>{channel.name}</strong>
|
||||
<span className="social-muted">{channel.topic}</span>
|
||||
</div>
|
||||
<div className="social-chat-thread social-live-thread">
|
||||
{messages.map((m) => (
|
||||
<div key={m.id} className={`social-bubble${m.mine ? " mine" : ""}`}>
|
||||
<header>
|
||||
{m.author}
|
||||
<time>{new Date(m.at).toLocaleTimeString()}</time>
|
||||
</header>
|
||||
<p>{m.text}</p>
|
||||
</div>
|
||||
))}
|
||||
<div ref={bottomRef} />
|
||||
</div>
|
||||
<div className="social-compose">
|
||||
<input
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") void send();
|
||||
}}
|
||||
placeholder="发到活动文字频道…"
|
||||
aria-label="消息内容"
|
||||
/>
|
||||
<button type="button" onClick={() => void send()}>
|
||||
发送
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export { default } from "./MeetupRoom";
|
||||
|
||||
257
src/modules/social/components/MeetupRoom.tsx
Normal file
257
src/modules/social/components/MeetupRoom.tsx
Normal file
@ -0,0 +1,257 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import {
|
||||
ArrowLeft,
|
||||
ArrowUpRight,
|
||||
Camera,
|
||||
CameraOff,
|
||||
Columns2,
|
||||
ExternalLink,
|
||||
Maximize2,
|
||||
MessageCircle,
|
||||
Mic,
|
||||
MicOff,
|
||||
Radio,
|
||||
RefreshCw,
|
||||
Video,
|
||||
} from "lucide-react";
|
||||
import SiteShell from "./SiteShell";
|
||||
import { Conversation } from "./ChatWorkspace";
|
||||
import { EmptyState, ShareButton } from "./SocialUI";
|
||||
import { MIROTALK_URL, SEED_MEETUPS } from "@social/lib/seed";
|
||||
import { socialPath } from "@social/lib/socialPath";
|
||||
import { useLocalState } from "@social/lib/useLocalState";
|
||||
|
||||
type Settings = { name: string; audio: boolean; video: boolean };
|
||||
function videoUrl(room: string, settings: Settings) {
|
||||
const query = new URLSearchParams({
|
||||
room,
|
||||
name: settings.name,
|
||||
notify: "0",
|
||||
chat: "0",
|
||||
audio: settings.audio ? "1" : "0",
|
||||
video: settings.video ? "1" : "0",
|
||||
});
|
||||
return `${MIROTALK_URL.replace(/\/$/, "")}/join?${query}`;
|
||||
}
|
||||
export default function MeetupRoom({ meetupId }: { meetupId: string }) {
|
||||
const meetup = SEED_MEETUPS.find((item) => item.id === meetupId);
|
||||
const [nick, setNick] = useLocalState("nick", "游民");
|
||||
const [audio, setAudio] = useState(false);
|
||||
const [video, setVideo] = useState(false);
|
||||
const [joined, setJoined] = useState<Settings | null>(null);
|
||||
const [layout, setLayout] = useState<"split" | "video" | "chat">("split");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [slow, setSlow] = useState(false);
|
||||
const [reload, setReload] = useState(0);
|
||||
const [fullscreenError, setFullscreenError] = useState("");
|
||||
const stage = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
if (!loading) return;
|
||||
const timer = setTimeout(() => setSlow(true), 15000);
|
||||
return () => clearTimeout(timer);
|
||||
}, [loading, reload]);
|
||||
const start = () => {
|
||||
setJoined({ name: nick.trim() || "游民", audio, video });
|
||||
setLoading(true);
|
||||
setSlow(false);
|
||||
};
|
||||
const leave = () => {
|
||||
setJoined(null);
|
||||
setLoading(false);
|
||||
setSlow(false);
|
||||
};
|
||||
if (!meetup)
|
||||
return (
|
||||
<SiteShell title="活动空间">
|
||||
<EmptyState
|
||||
title="没有找到这场活动"
|
||||
description="回到活动广场,看看其他相遇的可能。"
|
||||
>
|
||||
<Link className="social-btn primary" href={socialPath("/meetup")}>
|
||||
返回活动广场
|
||||
</Link>
|
||||
</EmptyState>
|
||||
</SiteShell>
|
||||
);
|
||||
const href = videoUrl(
|
||||
meetup.mirotalkRoom,
|
||||
joined || { name: nick.trim() || "游民", audio, video },
|
||||
);
|
||||
return (
|
||||
<SiteShell title="活动空间">
|
||||
<div className="social-room-heading">
|
||||
<Link href={socialPath("/meetup")}>
|
||||
<ArrowLeft size={14} />
|
||||
所有活动
|
||||
</Link>
|
||||
<ShareButton
|
||||
path={`/social/meetup/${meetup.id}`}
|
||||
title={meetup.title}
|
||||
/>
|
||||
</div>
|
||||
<header className="social-meetup-heading">
|
||||
<span className="social-page-kicker">
|
||||
<Radio size={13} />
|
||||
MEETUP SPACE
|
||||
</span>
|
||||
<h1>{meetup.title}</h1>
|
||||
<p>
|
||||
{meetup.date} · {meetup.time} 北京时间 · 活动预览
|
||||
</p>
|
||||
</header>
|
||||
<div className="social-live-toolbar">
|
||||
<div className="social-filters" aria-label="活动布局">
|
||||
{[
|
||||
{ key: "split" as const, label: "分屏", icon: Columns2 },
|
||||
{ key: "video" as const, label: "视频", icon: Video },
|
||||
{ key: "chat" as const, label: "聊天", icon: MessageCircle },
|
||||
].map((item) => (
|
||||
<button
|
||||
key={item.key}
|
||||
type="button"
|
||||
className={layout === item.key ? "active" : ""}
|
||||
aria-pressed={layout === item.key}
|
||||
onClick={() => setLayout(item.key)}
|
||||
>
|
||||
<item.icon size={14} />
|
||||
{item.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="social-save"
|
||||
onClick={async () => {
|
||||
try {
|
||||
if (document.fullscreenElement) await document.exitFullscreen();
|
||||
else await stage.current?.requestFullscreen();
|
||||
} catch {
|
||||
setFullscreenError("当前浏览器不支持全屏,可切换到视频布局。");
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Maximize2 size={14} />
|
||||
全屏空间
|
||||
</button>
|
||||
</div>
|
||||
{fullscreenError && (
|
||||
<p className="social-status" role="status">
|
||||
{fullscreenError}
|
||||
</p>
|
||||
)}
|
||||
<div ref={stage} className={`social-meetup-room layout-${layout}`}>
|
||||
<section
|
||||
className="social-meetup-video"
|
||||
hidden={layout === "chat"}
|
||||
aria-label="活动视频区"
|
||||
>
|
||||
{!joined ? (
|
||||
<div className="social-prejoin">
|
||||
<div className="social-prejoin-radar" aria-hidden="true">
|
||||
<i />
|
||||
<i />
|
||||
<i />
|
||||
<Video size={34} strokeWidth={1.2} />
|
||||
</div>
|
||||
<span className="social-page-kicker">READY WHEN YOU ARE</span>
|
||||
<h2>准备好了,再打开自己。</h2>
|
||||
<p>
|
||||
先在右侧打个招呼。进入视频前,可以选择是否开启麦克风和摄像头。
|
||||
</p>
|
||||
<label>
|
||||
大家怎么称呼你?
|
||||
<input
|
||||
aria-label="活动昵称"
|
||||
maxLength={24}
|
||||
value={nick}
|
||||
onChange={(event) => setNick(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<div className="social-prejoin-devices">
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={audio}
|
||||
onClick={() => setAudio(!audio)}
|
||||
>
|
||||
{audio ? <Mic size={20} /> : <MicOff size={20} />}麦克风
|
||||
{audio ? "开" : "关"}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={video}
|
||||
onClick={() => setVideo(!video)}
|
||||
>
|
||||
{video ? <Camera size={20} /> : <CameraOff size={20} />}摄像头
|
||||
{video ? "开" : "关"}
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="social-btn primary"
|
||||
onClick={start}
|
||||
>
|
||||
进入视频房间 <ArrowUpRight size={15} />
|
||||
</button>
|
||||
<p className="social-prejoin-note">
|
||||
视频由 MiroTalk 提供 · 进入后按浏览器提示授权
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="social-video-frame">
|
||||
{loading && (
|
||||
<div className="social-video-loading" role="status">
|
||||
<span className="social-loading-orbit" />
|
||||
正在连接视频空间…
|
||||
{slow && (
|
||||
<p>连接需要一点时间,可以先用文字聊天或在新窗口打开。</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<iframe
|
||||
key={reload}
|
||||
src={href}
|
||||
title={`${meetup.title} 视频房间`}
|
||||
allow="camera; microphone; fullscreen; display-capture; autoplay"
|
||||
allowFullScreen
|
||||
referrerPolicy="strict-origin-when-cross-origin"
|
||||
onLoad={() => setLoading(false)}
|
||||
/>
|
||||
<div className="social-video-actions">
|
||||
<button
|
||||
type="button"
|
||||
className="social-save"
|
||||
onClick={() => {
|
||||
setLoading(true);
|
||||
setSlow(false);
|
||||
setReload((value) => value + 1);
|
||||
}}
|
||||
>
|
||||
<RefreshCw size={13} />
|
||||
重新连接
|
||||
</button>
|
||||
<a
|
||||
href={href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="social-save"
|
||||
>
|
||||
<ExternalLink size={13} />
|
||||
新窗口
|
||||
</a>
|
||||
<button type="button" className="social-save" onClick={leave}>
|
||||
离开视频
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
<div className="social-meetup-chat" hidden={layout === "video"}>
|
||||
<Conversation channelId={meetup.channelId} compact />
|
||||
</div>
|
||||
</div>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
@ -44,8 +44,12 @@ export default function ParticleCanvas() {
|
||||
|
||||
const create = () => {
|
||||
const w = window.innerWidth;
|
||||
const dense = document.querySelector(".social-fx") != null;
|
||||
const count = Math.min(Math.floor(w / (dense ? 14 : 40)), dense ? 90 : 28);
|
||||
const dense =
|
||||
document.querySelector(".social-fx:not(.social-home)") != null;
|
||||
const count = Math.min(
|
||||
Math.floor(w / (dense ? 14 : 40)),
|
||||
dense ? 90 : 28,
|
||||
);
|
||||
particles = Array.from({ length: count }, () => ({
|
||||
x: Math.random() * w,
|
||||
y: Math.random() * window.innerHeight,
|
||||
@ -53,7 +57,7 @@ export default function ParticleCanvas() {
|
||||
speedX: (Math.random() - 0.5) * (dense ? 0.45 : 0.22),
|
||||
speedY: (Math.random() - 0.5) * (dense ? 0.45 : 0.22),
|
||||
opacity: Math.random() * (dense ? 0.55 : 0.35) + (dense ? 0.18 : 0.08),
|
||||
hue: [0, 45, 170, 280][Math.floor(Math.random() * 4)],
|
||||
hue: [0, 45, 170][Math.floor(Math.random() * 3)],
|
||||
}));
|
||||
};
|
||||
|
||||
|
||||
194
src/modules/social/components/PeopleClient.tsx
Normal file
194
src/modules/social/components/PeopleClient.tsx
Normal file
@ -0,0 +1,194 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { ArrowUpRight, MapPin, MessageCircle, Sparkles } from "lucide-react";
|
||||
import SiteShell from "./SiteShell";
|
||||
import SocialAvatar from "./SocialAvatar";
|
||||
import {
|
||||
BookmarkButton,
|
||||
EmptyState,
|
||||
PageIntro,
|
||||
SearchField,
|
||||
ShareButton,
|
||||
SocialDialog,
|
||||
} from "./SocialUI";
|
||||
import { MOCK_ROSTER, type SocialRosterMember } from "@social/lib/rosterMock";
|
||||
import { socialPath } from "@social/lib/socialPath";
|
||||
import { useLocalState } from "@social/lib/useLocalState";
|
||||
|
||||
export default function PeopleClient() {
|
||||
const params = useSearchParams();
|
||||
const [query, setQuery] = useState(params.get("city") || "");
|
||||
const [filter, setFilter] = useState("all");
|
||||
const [active, setActive] = useState<SocialRosterMember | null>(null);
|
||||
const [saved] = useLocalState<string[]>("saved-people", []);
|
||||
const list = useMemo(
|
||||
() =>
|
||||
MOCK_ROSTER.filter((person) => {
|
||||
const haystack =
|
||||
`${person.name} ${person.city} ${person.title} ${person.tags.join(" ")} ${person.lookingFor}`.toLowerCase();
|
||||
return (
|
||||
haystack.includes(query.toLowerCase().trim()) &&
|
||||
(filter !== "saved" || saved.includes(person.id)) &&
|
||||
(filter !== "online" || person.online)
|
||||
);
|
||||
}),
|
||||
[query, filter, saved],
|
||||
);
|
||||
return (
|
||||
<SiteShell title="发现同类">
|
||||
<PageIntro
|
||||
eyebrow="PEOPLE WITHOUT BORDERS"
|
||||
title="你的下一位朋友,"
|
||||
accent="可能就在下一座城。"
|
||||
description="按城市、技能或兴趣发现同类。先看看彼此的热爱,再让一句你好有一个自然的开始。"
|
||||
/>
|
||||
<div className="social-toolbar">
|
||||
<SearchField
|
||||
value={query}
|
||||
onChange={setQuery}
|
||||
label="搜索游民"
|
||||
placeholder="城市、名字、技能、兴趣…"
|
||||
/>
|
||||
<div className="social-filters" aria-label="成员筛选">
|
||||
{[
|
||||
{ id: "all", title: "所有游民" },
|
||||
{ id: "online", title: "演示在线" },
|
||||
{ id: "saved", title: "我收藏的人" },
|
||||
].map((f) => (
|
||||
<button
|
||||
key={f.id}
|
||||
className={filter === f.id ? "active" : ""}
|
||||
aria-pressed={filter === f.id}
|
||||
onClick={() => setFilter(f.id)}
|
||||
>
|
||||
{f.title}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div className="social-section-label">
|
||||
相遇,不必靠运气{" "}
|
||||
<span>{list.length} 位成员展示 · 演示资料与在线状态</span>
|
||||
</div>
|
||||
<div className="social-member-grid">
|
||||
{list.map((person) => (
|
||||
<article key={person.id} className="social-member-card">
|
||||
<div className="social-member-head">
|
||||
<SocialAvatar src={person.avatar} size={51} lazy />
|
||||
<div>
|
||||
<h2>{person.name}</h2>
|
||||
<p>{person.title}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="social-member-city">
|
||||
<MapPin size={13} />
|
||||
{person.city}
|
||||
</div>
|
||||
<p>{person.lookingFor}</p>
|
||||
<div className="social-tags">
|
||||
{person.tags.map((tag) => (
|
||||
<span key={tag}>{tag}</span>
|
||||
))}
|
||||
</div>
|
||||
<div className="social-card-actions">
|
||||
<BookmarkButton
|
||||
id={person.id}
|
||||
collection="saved-people"
|
||||
label="想认识"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="social-save"
|
||||
onClick={() => setActive(person)}
|
||||
>
|
||||
查看名片 <ArrowUpRight size={14} />
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
))}
|
||||
{!list.length && (
|
||||
<EmptyState
|
||||
title="同频的人,值得再找找"
|
||||
description="试试「设计」「清迈」「出海」,或者清空筛选看看其他成员。"
|
||||
>
|
||||
<button
|
||||
className="social-btn"
|
||||
onClick={() => {
|
||||
setQuery("");
|
||||
setFilter("all");
|
||||
}}
|
||||
>
|
||||
重置筛选
|
||||
</button>
|
||||
</EmptyState>
|
||||
)}
|
||||
</div>
|
||||
<section className="social-panel social-discover-cta">
|
||||
<Sparkles size={24} />
|
||||
<div>
|
||||
<h2>让别人也能认识你。</h2>
|
||||
<p className="social-muted">
|
||||
用一张游民名片,介绍你的城市、技能与好奇心。
|
||||
</p>
|
||||
</div>
|
||||
<Link className="social-btn primary" href={socialPath("/roster")}>
|
||||
创建我的名片 <ArrowUpRight size={15} />
|
||||
</Link>
|
||||
</section>
|
||||
{active && (
|
||||
<SocialDialog
|
||||
title={`${active.name} 的游民名片`}
|
||||
onClose={() => setActive(null)}
|
||||
>
|
||||
<div className="social-member-profile">
|
||||
<SocialAvatar src={active.avatar} size={74} />
|
||||
<div>
|
||||
<strong>{active.name}</strong>
|
||||
<p>{active.title}</p>
|
||||
<span className="social-member-city">
|
||||
<MapPin size={12} />
|
||||
{active.city}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="social-tags">
|
||||
{active.tags.map((tag) => (
|
||||
<span key={tag}>{tag}</span>
|
||||
))}
|
||||
</div>
|
||||
<p>{active.bio}</p>
|
||||
<p>
|
||||
<strong>想认识:</strong>
|
||||
{active.lookingFor}
|
||||
</p>
|
||||
<div className="social-status">
|
||||
这是演示成员资料。可以带着一个破冰话题进入公开频道,认识真正参与聊天的人。
|
||||
</div>
|
||||
<div className="social-actions">
|
||||
<Link
|
||||
className="social-btn primary"
|
||||
href={socialPath(
|
||||
`/chat/general?intro=${encodeURIComponent(`大家好,我对${active.tags[0]}很感兴趣,有同样兴趣的朋友吗?`)}`,
|
||||
)}
|
||||
>
|
||||
<MessageCircle size={15} />
|
||||
去公开频道聊聊
|
||||
</Link>
|
||||
<BookmarkButton
|
||||
id={active.id}
|
||||
collection="saved-people"
|
||||
label="想认识"
|
||||
/>
|
||||
<ShareButton
|
||||
path={`/social/people?city=${encodeURIComponent(active.city.split("·")[0].trim())}`}
|
||||
title={`在 ${active.city} 发现同类`}
|
||||
/>
|
||||
</div>
|
||||
</SocialDialog>
|
||||
)}
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
263
src/modules/social/components/ProfileStudio.tsx
Normal file
263
src/modules/social/components/ProfileStudio.tsx
Normal file
@ -0,0 +1,263 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState, type FormEvent } from "react";
|
||||
import Link from "next/link";
|
||||
import { ArrowUpRight, Check, Globe2, MapPin, Sparkles } from "lucide-react";
|
||||
import SiteShell from "./SiteShell";
|
||||
import { PageIntro } from "./SocialUI";
|
||||
import { socialApi } from "@social/lib/api";
|
||||
import { useLocalState } from "@social/lib/useLocalState";
|
||||
import { loadJson } from "@social/lib/storage";
|
||||
import type { SocialRosterProfile } from "@social/lib/types";
|
||||
|
||||
const EMPTY: SocialRosterProfile = {
|
||||
name: "",
|
||||
title: "",
|
||||
city: "",
|
||||
phone: "",
|
||||
linktree: "",
|
||||
skills: "",
|
||||
bio: "",
|
||||
};
|
||||
const FIELDS = [
|
||||
{
|
||||
key: "name",
|
||||
label: "怎么称呼你",
|
||||
placeholder: "一个让人记得住的名字",
|
||||
required: true,
|
||||
max: 40,
|
||||
},
|
||||
{
|
||||
key: "title",
|
||||
label: "你正在做什么",
|
||||
placeholder: "独立开发者 / 设计师 / 自由撰稿人…",
|
||||
max: 80,
|
||||
},
|
||||
{
|
||||
key: "city",
|
||||
label: "此刻在哪座城市",
|
||||
placeholder: "清迈、里斯本,或者正在路上",
|
||||
max: 80,
|
||||
},
|
||||
{
|
||||
key: "skills",
|
||||
label: "擅长什么,喜欢什么",
|
||||
placeholder: "设计, 摄影, 冲浪, 开源项目…",
|
||||
max: 200,
|
||||
},
|
||||
{
|
||||
key: "linktree",
|
||||
label: "让别人更了解你的链接(选填)",
|
||||
placeholder: "https://你的作品集或社交主页",
|
||||
max: 400,
|
||||
},
|
||||
{
|
||||
key: "phone",
|
||||
label: "联系方式(选填)",
|
||||
placeholder: "仅在你愿意提供时填写",
|
||||
max: 80,
|
||||
},
|
||||
] as const;
|
||||
|
||||
export default function ProfileStudio() {
|
||||
const [profile, setProfile] = useLocalState<SocialRosterProfile>(
|
||||
"roster",
|
||||
EMPTY,
|
||||
);
|
||||
const [, setNick] = useLocalState("nick", "游民");
|
||||
const [sync, setSync] = useLocalState("roster-sync", "draft");
|
||||
const [status, setStatus] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const edited = useRef(false),
|
||||
lock = useRef(false);
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
void socialApi
|
||||
.getRoster()
|
||||
.then((response) => {
|
||||
if (!active || edited.current) return;
|
||||
// An unsent local edit takes precedence over an older server profile.
|
||||
if (
|
||||
response.item &&
|
||||
!loadJson<SocialRosterProfile>("roster", EMPTY).updatedAt
|
||||
) {
|
||||
const next = { ...EMPTY };
|
||||
for (const key of Object.keys(EMPTY) as (keyof typeof EMPTY)[])
|
||||
next[key] = response.item[key] || "";
|
||||
setProfile(next);
|
||||
setSync("synced");
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
if (active) setStatus("你可以继续编辑。资料草稿会保存在当前设备。 ");
|
||||
});
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
// Only load once: later fetches must never overwrite edits.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
const update = (key: keyof SocialRosterProfile, value: string) => {
|
||||
edited.current = true;
|
||||
setSync("draft");
|
||||
setProfile((current) => ({
|
||||
...current,
|
||||
[key]: value,
|
||||
updatedAt: new Date().toISOString(),
|
||||
}));
|
||||
setStatus("");
|
||||
};
|
||||
const complete = [
|
||||
profile.name,
|
||||
profile.title,
|
||||
profile.city,
|
||||
profile.skills,
|
||||
profile.bio,
|
||||
].filter((value) => value.trim()).length;
|
||||
const submit = async (event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
if (lock.current || !profile.name.trim()) return;
|
||||
if (profile.linktree && !/^https?:\/\//i.test(profile.linktree)) {
|
||||
setStatus("作品链接请以 https:// 或 http:// 开头。");
|
||||
return;
|
||||
}
|
||||
lock.current = true;
|
||||
setBusy(true);
|
||||
const snapshot = { ...profile };
|
||||
const payload = { ...snapshot, name: snapshot.name.trim() };
|
||||
setNick(payload.name);
|
||||
try {
|
||||
await socialApi.saveRoster(payload);
|
||||
setSync("synced");
|
||||
setStatus("名片资料已同步。你可以去公开频道做个自我介绍。");
|
||||
} catch {
|
||||
setSync("draft");
|
||||
setStatus("资料已存本机,尚未同步。联网后再次点击保存即可重试。");
|
||||
} finally {
|
||||
lock.current = false;
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<SiteShell title="我的游民名片">
|
||||
<PageIntro
|
||||
eyebrow="YOU ARE MORE THAN A JOB TITLE"
|
||||
title="给下一次相遇,"
|
||||
accent="一个认识你的理由。"
|
||||
description="一张有温度的名片,从你正在做的事、喜欢的城市和想遇见的人开始。"
|
||||
/>
|
||||
<div className="social-profile-studio">
|
||||
<section className="social-panel">
|
||||
<div className="social-section-label">
|
||||
编辑你的名片{" "}
|
||||
<span>{sync === "synced" ? "已同步" : "本机草稿"}</span>
|
||||
</div>
|
||||
<form
|
||||
className="social-form"
|
||||
onSubmit={(event) => void submit(event)}
|
||||
aria-busy={busy}
|
||||
>
|
||||
<fieldset
|
||||
disabled={busy}
|
||||
className="social-form-grid social-fieldset"
|
||||
>
|
||||
{FIELDS.map((field) => (
|
||||
<label key={field.key}>
|
||||
{field.label}
|
||||
<input
|
||||
required={"required" in field && field.required}
|
||||
type={field.key === "linktree" ? "url" : "text"}
|
||||
value={profile[field.key]}
|
||||
maxLength={field.max}
|
||||
placeholder={field.placeholder}
|
||||
onChange={(event) => update(field.key, event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
<label className="full">
|
||||
一段有意思的自我介绍
|
||||
<textarea
|
||||
rows={4}
|
||||
maxLength={600}
|
||||
value={profile.bio}
|
||||
onChange={(event) => update("bio", event.target.value)}
|
||||
placeholder="最近在研究什么?想找人一起做什么?你会如何介绍现在的生活?"
|
||||
/>
|
||||
<small>{profile.bio.length}/600</small>
|
||||
</label>
|
||||
</fieldset>
|
||||
<p className="social-muted">
|
||||
联系方式为选填。提交前请确认你愿意将填写的资料交给社区保存。
|
||||
</p>
|
||||
<button
|
||||
type="submit"
|
||||
className="social-btn primary"
|
||||
disabled={busy || !profile.name.trim()}
|
||||
>
|
||||
<Check size={15} />
|
||||
{busy ? "正在同步…" : "保存并同步名片"}
|
||||
</button>
|
||||
{status && (
|
||||
<p
|
||||
className={`social-status${sync !== "synced" ? " warn" : ""}`}
|
||||
role="status"
|
||||
>
|
||||
{status}
|
||||
</p>
|
||||
)}
|
||||
</form>
|
||||
</section>
|
||||
<section className="social-profile-preview">
|
||||
<div className="social-section-label">
|
||||
<span>YOUR NEXT CHAPTER</span>
|
||||
<Sparkles size={16} />
|
||||
</div>
|
||||
<div className="social-profile-passport">
|
||||
<div className="social-passport-pattern" aria-hidden="true">
|
||||
<Globe2 size={170} strokeWidth={0.5} />
|
||||
</div>
|
||||
<div className="social-profile-monogram">
|
||||
{profile.name.trim().slice(0, 1) || "N"}
|
||||
</div>
|
||||
<span className="social-page-kicker">NOMAD ID / 本机预览</span>
|
||||
<h2>{profile.name.trim() || "你的名字"}</h2>
|
||||
<p>{profile.title || "让你的好奇心被看见"}</p>
|
||||
<span className="social-member-city">
|
||||
<MapPin size={13} />
|
||||
{profile.city || "世界很大,正在探索"}
|
||||
</span>
|
||||
<div className="social-tags">
|
||||
{profile.skills
|
||||
.split(/[,,、]/)
|
||||
.filter(Boolean)
|
||||
.slice(0, 8)
|
||||
.map((skill, index) => (
|
||||
<span key={index}>{skill.trim()}</span>
|
||||
))}
|
||||
</div>
|
||||
<p className="social-profile-bio">
|
||||
{profile.bio || "写下你的故事,让下一位同频的人有话可说。"}
|
||||
</p>
|
||||
<footer>
|
||||
NO BORDERS. REAL CONNECTIONS.<span>✦</span>
|
||||
</footer>
|
||||
</div>
|
||||
<div className="social-profile-progress">
|
||||
<div>
|
||||
<span>让别人更了解你</span>
|
||||
<strong>{complete}/5</strong>
|
||||
</div>
|
||||
<progress max={5} value={complete} aria-label="名片完成度" />
|
||||
<p>名字、职业、城市、兴趣和自我介绍。</p>
|
||||
</div>
|
||||
<Link
|
||||
className="social-btn"
|
||||
href={`/social/chat/general?intro=${encodeURIComponent(`大家好,我是${profile.name || "新朋友"},目前在${profile.city || "探索下一座城市"}。${profile.bio || "很高兴认识大家!"}`)}`}
|
||||
>
|
||||
带着名片,打个招呼 <ArrowUpRight size={15} />
|
||||
</Link>
|
||||
</section>
|
||||
</div>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
275
src/modules/social/components/ResourceLibrary.tsx
Normal file
275
src/modules/social/components/ResourceLibrary.tsx
Normal file
@ -0,0 +1,275 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
import {
|
||||
ArrowUpRight,
|
||||
BookOpen,
|
||||
Film,
|
||||
MessageCircle,
|
||||
Play,
|
||||
} from "lucide-react";
|
||||
import SiteShell from "./SiteShell";
|
||||
import {
|
||||
BookmarkButton,
|
||||
EmptyState,
|
||||
PageIntro,
|
||||
SearchField,
|
||||
ShareButton,
|
||||
SocialDialog,
|
||||
} from "./SocialUI";
|
||||
import { useSocialConfig } from "./SocialExperience";
|
||||
import { SEED_EBOOKS, SEED_VIDEOS } from "@social/lib/seed";
|
||||
import { useLocalState } from "@social/lib/useLocalState";
|
||||
|
||||
type Kind = "videos" | "date" | "ebook";
|
||||
const COPY = {
|
||||
videos: {
|
||||
eyebrow: "A WINDOW INTO ANOTHER LIFE",
|
||||
title: "世界那么大,",
|
||||
accent: "借一段影像,遇见另一种生活。",
|
||||
description:
|
||||
"城市切片、游民访谈与真实相遇的记录。从一个故事,找到下一次出发的灵感。",
|
||||
},
|
||||
date: {
|
||||
eyebrow: "EVERY NOMAD HAS A STORY",
|
||||
title: "陌生人的日常,",
|
||||
accent: "可能正是你的下一章。",
|
||||
description:
|
||||
"关于工作、迁徙和相遇的故事目录。看看别人的城市,也把你的好奇带进一场对话。",
|
||||
},
|
||||
ebook: {
|
||||
eyebrow: "LESS SCROLLING. MORE DISCOVERY.",
|
||||
title: "给好奇心,",
|
||||
accent: "留一页慢下来的时间。",
|
||||
description:
|
||||
"关于社区、连接和游民生活的小册目录。收藏一个主题,把阅读变成下一场有内容的聊天。",
|
||||
},
|
||||
};
|
||||
|
||||
function safeSource(value?: string) {
|
||||
if (!value) return undefined;
|
||||
try {
|
||||
const url = new URL(value, "https://nomadro.cn");
|
||||
return url.protocol === "https:" || url.protocol === "http:"
|
||||
? value
|
||||
: undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function ResourcePlayer({ source }: { source: string }) {
|
||||
const [failed, setFailed] = useState(false);
|
||||
return (
|
||||
<>
|
||||
<video
|
||||
className="social-resource-player"
|
||||
controls
|
||||
playsInline
|
||||
preload="metadata"
|
||||
src={source}
|
||||
onError={() => setFailed(true)}
|
||||
onLoadedMetadata={() => setFailed(false)}
|
||||
/>
|
||||
{failed && (
|
||||
<p role="status" className="social-status warn">
|
||||
片源暂时无法播放,请稍后重试。
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default function ResourceLibrary({ kind }: { kind: Kind }) {
|
||||
const [query, setQuery] = useState("");
|
||||
const [savedOnly, setSavedOnly] = useState(false);
|
||||
const [selected, setSelected] = useState<string | null>(null);
|
||||
const config = useSocialConfig();
|
||||
const [saved] = useLocalState<string[]>(`saved-${kind}`, []);
|
||||
const books = kind === "ebook";
|
||||
const items = books
|
||||
? SEED_EBOOKS.map((book) => ({
|
||||
...book,
|
||||
summary: book.blurb,
|
||||
city: "社区小册",
|
||||
coverEmoji: "✦",
|
||||
detail: `${book.chapters} 章 · ${book.minutes} 分钟`,
|
||||
}))
|
||||
: SEED_VIDEOS.map((video) => ({
|
||||
...video,
|
||||
detail: `${video.city} · ${video.minutes} 分钟`,
|
||||
}));
|
||||
const shown = items.filter(
|
||||
(item) =>
|
||||
(!savedOnly || saved.includes(item.id)) &&
|
||||
`${item.title} ${item.summary} ${item.city}`
|
||||
.toLowerCase()
|
||||
.includes(query.toLowerCase()),
|
||||
);
|
||||
const active = items.find((item) => item.id === selected);
|
||||
const source =
|
||||
active && safeSource(config.copy.socialVideoSources?.[active.id]);
|
||||
return (
|
||||
<SiteShell
|
||||
title={books ? "灵感书架" : kind === "date" ? "游民故事" : "影像放映室"}
|
||||
>
|
||||
<PageIntro {...COPY[kind]} />
|
||||
<div className="social-toolbar">
|
||||
<SearchField
|
||||
value={query}
|
||||
onChange={setQuery}
|
||||
placeholder={books ? "找一份想读的小册…" : "搜索城市、故事、关键词…"}
|
||||
/>
|
||||
<div className="social-filters">
|
||||
<button
|
||||
type="button"
|
||||
className={!savedOnly ? "active" : ""}
|
||||
aria-pressed={!savedOnly}
|
||||
onClick={() => setSavedOnly(false)}
|
||||
>
|
||||
全部{books ? "小册" : "故事"}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={savedOnly ? "active" : ""}
|
||||
aria-pressed={savedOnly}
|
||||
onClick={() => setSavedOnly(true)}
|
||||
>
|
||||
我的收藏 · {saved.length}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="social-section-label">
|
||||
{books ? "把灵感带走" : "遇见别人的世界"}
|
||||
<span>
|
||||
{books
|
||||
? "小册主题预览 · 完整内容以阅读书库为准"
|
||||
: "种子内容目录 · 片源发布后可播放"}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
className={`social-grid social-library-grid ${books ? "is-books" : ""}`}
|
||||
>
|
||||
{shown.map((item, index) => (
|
||||
<article
|
||||
id={item.id}
|
||||
className="social-card social-library-card"
|
||||
key={item.id}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
className={`social-library-art library-tone-${index % 3}`}
|
||||
onClick={() => setSelected(item.id)}
|
||||
aria-label={`查看${item.title}`}
|
||||
>
|
||||
<span className="social-film-grain" />
|
||||
<span className="social-library-number">
|
||||
{String(index + 1).padStart(2, "0")}
|
||||
</span>
|
||||
{books ? (
|
||||
<div className="social-book-cover">
|
||||
<small>NOMADRO FIELD NOTES</small>
|
||||
<BookOpen size={27} strokeWidth={1} />
|
||||
<strong>{item.title}</strong>
|
||||
<span>READ. CONNECT. REPEAT.</span>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<span className="social-film-orbit" />
|
||||
<span className="social-film-scene">{item.coverEmoji}</span>
|
||||
<span className="social-film-play">
|
||||
{safeSource(config.copy.socialVideoSources?.[item.id]) ? (
|
||||
<Play size={19} />
|
||||
) : (
|
||||
<Film size={19} />
|
||||
)}
|
||||
</span>
|
||||
<small>
|
||||
{safeSource(config.copy.socialVideoSources?.[item.id])
|
||||
? "播放影像"
|
||||
: "目录预览"}
|
||||
</small>
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
<div className="social-card-top">
|
||||
<span className="social-library-meta">{item.detail}</span>
|
||||
<BookmarkButton id={item.id} collection={`saved-${kind}`} />
|
||||
</div>
|
||||
<h2>{item.title}</h2>
|
||||
<p>{item.summary}</p>
|
||||
<div className="social-card-actions">
|
||||
<button
|
||||
type="button"
|
||||
className="social-btn"
|
||||
onClick={() => setSelected(item.id)}
|
||||
>
|
||||
展开{books ? "小册" : "故事"}
|
||||
<ArrowUpRight size={14} />
|
||||
</button>
|
||||
<ShareButton
|
||||
path={`/social/${kind}#${item.id}`}
|
||||
title={item.title}
|
||||
/>
|
||||
</div>
|
||||
</article>
|
||||
))}
|
||||
{!shown.length && <EmptyState />}
|
||||
</div>
|
||||
{active && (
|
||||
<SocialDialog title={active.title} onClose={() => setSelected(null)}>
|
||||
<div className="social-tags">
|
||||
<span>{active.detail}</span>
|
||||
<span>{books ? "小册目录" : source ? "影像" : "内容预览"}</span>
|
||||
</div>
|
||||
{!books && source && <ResourcePlayer key={source} source={source} />}
|
||||
<p>{active.summary}</p>
|
||||
{!books && !source && (
|
||||
<p className="social-status warn">
|
||||
这是一条内容目录,完整片源尚未发布。你可以先收藏,或围绕这个主题展开聊天。
|
||||
</p>
|
||||
)}
|
||||
{books && (
|
||||
<p>
|
||||
这里展示小册主题简介。点击下方入口浏览完整阅读书库,实际可读书目以书库内展示为准。
|
||||
</p>
|
||||
)}
|
||||
<div className="social-library-prompt">
|
||||
<span>聊聊这个话题</span>
|
||||
<strong>
|
||||
{books
|
||||
? "刚到一座新城市,你通常怎么认识新朋友?"
|
||||
: `如果下一站是${active.city},你最想和当地游民聊什么?`}
|
||||
</strong>
|
||||
</div>
|
||||
<div className="social-actions">
|
||||
{books && (
|
||||
<Link className="social-btn primary" href="/book">
|
||||
浏览阅读书库 <BookOpen size={15} />
|
||||
</Link>
|
||||
)}
|
||||
<Link
|
||||
className={`social-btn${books ? "" : " primary"}`}
|
||||
href={`/social/chat/general?intro=${encodeURIComponent(`看到「${active.title}」这个主题,想和大家聊聊:${books ? "你在新城市是怎样认识新朋友的?" : `在${active.city}生活最吸引你的是什么?`}`)}`}
|
||||
>
|
||||
<MessageCircle size={15} />
|
||||
带着话题去聊天
|
||||
</Link>
|
||||
<BookmarkButton id={active.id} collection={`saved-${kind}`} />
|
||||
</div>
|
||||
</SocialDialog>
|
||||
)}
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
|
||||
export function VideosLibrary() {
|
||||
return <ResourceLibrary kind="videos" />;
|
||||
}
|
||||
export function StoriesLibrary() {
|
||||
return <ResourceLibrary kind="date" />;
|
||||
}
|
||||
export function BooksLibrary() {
|
||||
return <ResourceLibrary kind="ebook" />;
|
||||
}
|
||||
246
src/modules/social/components/RoleBoard.tsx
Normal file
246
src/modules/social/components/RoleBoard.tsx
Normal file
@ -0,0 +1,246 @@
|
||||
"use client";
|
||||
|
||||
import { useRef, useState, type FormEvent } from "react";
|
||||
import {
|
||||
ArrowUpRight,
|
||||
BriefcaseBusiness,
|
||||
Globe2,
|
||||
HeartHandshake,
|
||||
Send,
|
||||
} from "lucide-react";
|
||||
import SiteShell from "./SiteShell";
|
||||
import {
|
||||
BookmarkButton,
|
||||
EmptyState,
|
||||
PageIntro,
|
||||
SearchField,
|
||||
SocialDialog,
|
||||
} from "./SocialUI";
|
||||
import { SEED_GIGS, TEAM_KIND_LABEL } from "@social/lib/seed";
|
||||
import { socialApi } from "@social/lib/api";
|
||||
import { useLocalState } from "@social/lib/useLocalState";
|
||||
import type { SocialGig, SocialTeamKind } from "@social/lib/types";
|
||||
|
||||
function ApplicationForm({ gig }: { gig: SocialGig }) {
|
||||
const [draft, setDraft] = useLocalState(`gig-draft:${gig.id}`, {
|
||||
name: "",
|
||||
contact: "",
|
||||
note: "",
|
||||
});
|
||||
const [delivery, setDelivery] = useLocalState(
|
||||
`gig-delivery:${gig.id}`,
|
||||
"draft",
|
||||
);
|
||||
const [status, setStatus] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const lock = useRef(false);
|
||||
const update = (key: keyof typeof draft, value: string) => {
|
||||
setDraft((current) => ({ ...current, [key]: value }));
|
||||
setDelivery("draft");
|
||||
setStatus("");
|
||||
};
|
||||
const submit = async (event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
if (
|
||||
lock.current ||
|
||||
delivery === "sent" ||
|
||||
!draft.name.trim() ||
|
||||
!draft.contact.trim()
|
||||
)
|
||||
return;
|
||||
lock.current = true;
|
||||
setBusy(true);
|
||||
try {
|
||||
await socialApi.applyGig(gig.id, {
|
||||
name: draft.name.trim(),
|
||||
contact: draft.contact.trim(),
|
||||
note: draft.note.trim(),
|
||||
});
|
||||
setDelivery("sent");
|
||||
setStatus("申请已提交到社区。具体职责、机会是否开放,请以后续沟通为准。");
|
||||
} catch {
|
||||
setDelivery("local");
|
||||
setStatus("申请已保存在当前设备,尚未提交。联网后可以重试。");
|
||||
} finally {
|
||||
lock.current = false;
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<div className="social-tags">
|
||||
<span>{TEAM_KIND_LABEL[gig.kind || "parttime"]}</span>
|
||||
<span>{gig.pay}</span>
|
||||
</div>
|
||||
<p>介绍一下你想参与的原因,附上作品或经验,让对方更容易了解你。</p>
|
||||
<form className="social-form" onSubmit={(event) => void submit(event)}>
|
||||
<fieldset disabled={busy} className="social-fieldset">
|
||||
<label>
|
||||
怎么称呼你
|
||||
<input
|
||||
required
|
||||
maxLength={64}
|
||||
value={draft.name}
|
||||
onChange={(event) => update("name", event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
联系方式
|
||||
<input
|
||||
required
|
||||
maxLength={120}
|
||||
placeholder="邮箱 / 微信 / 其他可联系的方式"
|
||||
value={draft.contact}
|
||||
onChange={(event) => update("contact", event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
你能带来什么
|
||||
<textarea
|
||||
rows={4}
|
||||
maxLength={2000}
|
||||
value={draft.note}
|
||||
onChange={(event) => update("note", event.target.value)}
|
||||
placeholder="相关经历、作品链接、可投入时间…"
|
||||
/>
|
||||
</label>
|
||||
</fieldset>
|
||||
<button
|
||||
type="submit"
|
||||
className="social-btn primary"
|
||||
disabled={busy || delivery === "sent"}
|
||||
>
|
||||
<Send size={14} />
|
||||
{busy
|
||||
? "提交中…"
|
||||
: delivery === "sent"
|
||||
? "已提交"
|
||||
: delivery === "local"
|
||||
? "重试提交"
|
||||
: "发送参与申请"}
|
||||
</button>
|
||||
{status && (
|
||||
<p
|
||||
role="status"
|
||||
className={`social-status${delivery === "local" ? " warn" : ""}`}
|
||||
>
|
||||
{status}
|
||||
</p>
|
||||
)}
|
||||
<small className="social-muted">
|
||||
草稿仅保存在本机。提交不代表录用或确认合作。
|
||||
</small>
|
||||
</form>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default function RoleBoard({
|
||||
initialKind = "all",
|
||||
}: {
|
||||
initialKind?: SocialTeamKind | "all";
|
||||
}) {
|
||||
const [kind, setKind] = useState<string>(initialKind);
|
||||
const [query, setQuery] = useState("");
|
||||
const [savedOnly, setSavedOnly] = useState(false);
|
||||
const [saved] = useLocalState<string[]>("saved-roles", []);
|
||||
const [active, setActive] = useState<SocialGig | null>(null);
|
||||
const roles = SEED_GIGS.filter(
|
||||
(gig) =>
|
||||
(kind === "all" || gig.kind === kind) &&
|
||||
(!savedOnly || saved.includes(gig.id)) &&
|
||||
`${gig.title} ${gig.role} ${gig.tags.join(" ")}`
|
||||
.toLowerCase()
|
||||
.includes(query.toLowerCase()),
|
||||
);
|
||||
return (
|
||||
<SiteShell title="远程组队">
|
||||
<PageIntro
|
||||
eyebrow="BUILD SOMETHING. TOGETHER."
|
||||
title="不只擦肩而过,"
|
||||
accent="一起做点有意思的事。"
|
||||
description="把技能变成连接。寻找远程合作、参与一次活动,或加入一个值得投入的团队。"
|
||||
/>
|
||||
<div className="social-toolbar">
|
||||
<SearchField
|
||||
value={query}
|
||||
onChange={setQuery}
|
||||
placeholder="搜索角色、技能、兴趣…"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className={`social-save${savedOnly ? " selected" : ""}`}
|
||||
aria-pressed={savedOnly}
|
||||
onClick={() => setSavedOnly(!savedOnly)}
|
||||
>
|
||||
我的收藏 · {saved.length}
|
||||
</button>
|
||||
</div>
|
||||
<div className="social-filters">
|
||||
{[["all", "全部机会"], ...Object.entries(TEAM_KIND_LABEL)].map(
|
||||
([id, label]) => (
|
||||
<button
|
||||
key={id}
|
||||
type="button"
|
||||
className={id === kind ? "active" : ""}
|
||||
aria-pressed={id === kind}
|
||||
onClick={() => setKind(id)}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
<div className="social-section-label">
|
||||
找到你的下一位队友{" "}
|
||||
<span>{roles.length} 个目录机会 · 开放情况请以沟通确认为准</span>
|
||||
</div>
|
||||
<div className="social-grid social-role-grid">
|
||||
{roles.map((gig, index) => (
|
||||
<article className="social-card social-role-card" key={gig.id}>
|
||||
<div className="social-card-top">
|
||||
<div className={`social-role-symbol tone-${index % 3}`}>
|
||||
{gig.kind === "volunteer" ? (
|
||||
<HeartHandshake size={27} />
|
||||
) : (
|
||||
<BriefcaseBusiness size={27} />
|
||||
)}
|
||||
</div>
|
||||
<BookmarkButton id={gig.id} collection="saved-roles" />
|
||||
</div>
|
||||
<span className="social-role-type">
|
||||
{TEAM_KIND_LABEL[gig.kind || "parttime"]}
|
||||
</span>
|
||||
<h2>{gig.title}</h2>
|
||||
<p>{gig.role}</p>
|
||||
<div className="social-role-meta">
|
||||
<span>
|
||||
<Globe2 size={13} />
|
||||
{gig.remote ? "可以远程" : "线下 / 混合"}
|
||||
</span>
|
||||
<span>{gig.pay}</span>
|
||||
</div>
|
||||
<div className="social-tags">
|
||||
{gig.tags.map((tag) => (
|
||||
<span key={tag}>{tag}</span>
|
||||
))}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="social-btn"
|
||||
onClick={() => setActive(gig)}
|
||||
>
|
||||
我想参与 <ArrowUpRight size={14} />
|
||||
</button>
|
||||
</article>
|
||||
))}
|
||||
{!roles.length && <EmptyState />}
|
||||
</div>
|
||||
{active && (
|
||||
<SocialDialog title={active.title} onClose={() => setActive(null)}>
|
||||
<ApplicationForm gig={active} />
|
||||
</SocialDialog>
|
||||
)}
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
@ -1,150 +1,3 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState, type FormEvent } from "react";
|
||||
import SiteShell from "./SiteShell";
|
||||
import { socialApi } from "@social/lib/api";
|
||||
import { loadJson, saveJson } from "@social/lib/storage";
|
||||
import type { SocialRosterProfile } from "@social/lib/types";
|
||||
|
||||
const EMPTY: SocialRosterProfile = {
|
||||
name: "",
|
||||
title: "",
|
||||
city: "",
|
||||
phone: "",
|
||||
linktree: "",
|
||||
skills: "",
|
||||
bio: "",
|
||||
};
|
||||
|
||||
export default function RosterClient() {
|
||||
const [form, setForm] = useState<SocialRosterProfile>(EMPTY);
|
||||
const [saved, setSaved] = useState("");
|
||||
const [online, setOnline] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
(async () => {
|
||||
const local = loadJson<SocialRosterProfile>("roster", EMPTY);
|
||||
if (!cancelled) setForm(local);
|
||||
try {
|
||||
const res = await socialApi.getRoster();
|
||||
if (cancelled) return;
|
||||
if (res.item) {
|
||||
const mapped: SocialRosterProfile = {
|
||||
name: res.item.name || "",
|
||||
title: res.item.title || "",
|
||||
city: res.item.city || "",
|
||||
phone: res.item.phone || "",
|
||||
linktree: res.item.linktree || "",
|
||||
skills: res.item.skills || "",
|
||||
bio: res.item.bio || "",
|
||||
updatedAt: res.item.updatedAt,
|
||||
};
|
||||
setForm(mapped);
|
||||
saveJson("roster", mapped);
|
||||
}
|
||||
setOnline(true);
|
||||
} catch {
|
||||
if (!cancelled) setOnline(false);
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
const set = (key: keyof SocialRosterProfile, value: string) =>
|
||||
setForm((prev) => ({ ...prev, [key]: value }));
|
||||
|
||||
const submit = async (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
const next = { ...form, updatedAt: new Date().toISOString() };
|
||||
saveJson("roster", next);
|
||||
if (next.name) saveJson("nick", next.name);
|
||||
setForm(next);
|
||||
try {
|
||||
await socialApi.saveRoster({
|
||||
name: next.name,
|
||||
title: next.title,
|
||||
city: next.city,
|
||||
phone: next.phone,
|
||||
linktree: next.linktree,
|
||||
skills: next.skills,
|
||||
bio: next.bio,
|
||||
});
|
||||
setOnline(true);
|
||||
setSaved("已同步到游民社区独立库");
|
||||
} catch {
|
||||
setOnline(false);
|
||||
setSaved("后端暂不可用,已先保存到本机");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<SiteShell title="花名册">
|
||||
<section className="social-hero">
|
||||
<div className="social-hero-tag">VIP · 职业花名册</div>
|
||||
<h1>
|
||||
完善个人资料
|
||||
<br />
|
||||
<span>表单 · Linktree · 手机号</span>
|
||||
</h1>
|
||||
<p>
|
||||
数据写入独立 social SQLite,不进旅居社群 / VIP 表。
|
||||
{online ? "" : " (当前离线本地)"}
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<form className="social-form social-panel" onSubmit={(e) => void submit(e)}>
|
||||
<label>
|
||||
昵称 / 姓名
|
||||
<input required value={form.name} onChange={(e) => set("name", e.target.value)} />
|
||||
</label>
|
||||
<label>
|
||||
职业头衔
|
||||
<input
|
||||
value={form.title}
|
||||
onChange={(e) => set("title", e.target.value)}
|
||||
placeholder="独立开发 / 设计师 / 运营"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
当前城市
|
||||
<input value={form.city} onChange={(e) => set("city", e.target.value)} placeholder="清迈" />
|
||||
</label>
|
||||
<label>
|
||||
手机号
|
||||
<input
|
||||
value={form.phone}
|
||||
onChange={(e) => set("phone", e.target.value)}
|
||||
placeholder="仅用于同城约见"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
社交媒体 Linktree
|
||||
<input
|
||||
value={form.linktree}
|
||||
onChange={(e) => set("linktree", e.target.value)}
|
||||
placeholder="https://linktr.ee/..."
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
技能标签
|
||||
<input
|
||||
value={form.skills}
|
||||
onChange={(e) => set("skills", e.target.value)}
|
||||
placeholder="React, 短视频, 英语"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
简介
|
||||
<textarea rows={4} value={form.bio} onChange={(e) => set("bio", e.target.value)} />
|
||||
</label>
|
||||
<button type="submit" className="social-btn primary">
|
||||
保存资料
|
||||
</button>
|
||||
{saved ? <p className="social-muted">{saved}</p> : null}
|
||||
</form>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
export { default } from "./ProfileStudio";
|
||||
|
||||
@ -1,15 +1,48 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useEffect, useState, type ReactNode } from "react";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { MessageCircle, Moon, Sun } from "lucide-react";
|
||||
import {
|
||||
useEffect,
|
||||
useId,
|
||||
useRef,
|
||||
useState,
|
||||
useSyncExternalStore,
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
import { socialPath } from "@social/lib/socialPath";
|
||||
import { applySocialSkin, SOCIAL_SKIN_DEFAULT } from "@social/lib/skin";
|
||||
import { SocialMobileDock, SocialFooter } from "./SocialNavigation";
|
||||
|
||||
function readTheme(): "light" | "dark" {
|
||||
try {
|
||||
return (localStorage.getItem("nomadro-theme") ||
|
||||
localStorage.getItem("nomad-theme")) === "light"
|
||||
? "light"
|
||||
: "dark";
|
||||
} catch {
|
||||
return "dark";
|
||||
}
|
||||
}
|
||||
|
||||
function subscribeTheme(callback: () => void) {
|
||||
window.addEventListener("storage", callback);
|
||||
window.addEventListener("nomadro-theme-changed", callback);
|
||||
return () => {
|
||||
window.removeEventListener("storage", callback);
|
||||
window.removeEventListener("nomadro-theme-changed", callback);
|
||||
};
|
||||
}
|
||||
|
||||
const serverTheme = () => "dark" as const;
|
||||
|
||||
const GROUPS = [
|
||||
{
|
||||
id: "online",
|
||||
label: "线上",
|
||||
items: [
|
||||
{ href: "/people", label: "发现同类" },
|
||||
{ href: "/chat", label: "聊天室" },
|
||||
{ href: "/meetup", label: "Meetup" },
|
||||
],
|
||||
@ -47,44 +80,79 @@ export default function SiteShell({
|
||||
home?: boolean;
|
||||
onJoin?: () => void;
|
||||
}) {
|
||||
const [theme, setTheme] = useState<"dark" | "light">("dark");
|
||||
const theme = useSyncExternalStore(subscribeTheme, readTheme, serverTheme);
|
||||
const [openGroup, setOpenGroup] = useState<string | null>(null);
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
const [scrolled, setScrolled] = useState(false);
|
||||
const [mounted, setMounted] = useState(false);
|
||||
const pathname = usePathname();
|
||||
const menuId = useId();
|
||||
const menuButtonRef = useRef<HTMLButtonElement>(null);
|
||||
const navRef = useRef<HTMLElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
setMounted(true);
|
||||
const saved =
|
||||
localStorage.getItem("nomadro-theme") || localStorage.getItem("nomad-theme");
|
||||
const next = saved === "light" ? "light" : "dark";
|
||||
setTheme(next);
|
||||
document.documentElement.setAttribute("data-theme", next);
|
||||
document.documentElement.classList.toggle("light", next === "light");
|
||||
document.documentElement.classList.toggle("dark", next === "dark");
|
||||
applySocialSkin(SOCIAL_SKIN_DEFAULT);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
document.documentElement.setAttribute("data-theme", theme);
|
||||
document.documentElement.classList.toggle("light", theme === "light");
|
||||
document.documentElement.classList.toggle("dark", theme === "dark");
|
||||
}, [theme]);
|
||||
|
||||
useEffect(() => {
|
||||
const onScroll = () => setScrolled(window.scrollY > 24);
|
||||
onScroll();
|
||||
window.addEventListener("scroll", onScroll, { passive: true });
|
||||
return () => window.removeEventListener("scroll", onScroll);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
document.body.style.overflow = menuOpen ? "hidden" : "";
|
||||
if (!menuOpen && !openGroup) return;
|
||||
const onKey = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape") {
|
||||
setMenuOpen(false);
|
||||
setOpenGroup(null);
|
||||
if (menuOpen) menuButtonRef.current?.focus();
|
||||
else
|
||||
navRef.current
|
||||
?.querySelector<HTMLButtonElement>('[aria-expanded="true"]')
|
||||
?.focus();
|
||||
}
|
||||
};
|
||||
const onOutside = (event: PointerEvent) => {
|
||||
if (!navRef.current?.contains(event.target as Node)) {
|
||||
setOpenGroup(null);
|
||||
setMenuOpen(false);
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
window.addEventListener("pointerdown", onOutside);
|
||||
return () => {
|
||||
document.body.style.overflow = "";
|
||||
window.removeEventListener("keydown", onKey);
|
||||
window.removeEventListener("pointerdown", onOutside);
|
||||
};
|
||||
}, [menuOpen, openGroup]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!menuOpen) return;
|
||||
const previousOverflow = document.body.style.overflow;
|
||||
document.body.style.overflow = "hidden";
|
||||
return () => {
|
||||
document.body.style.overflow = previousOverflow;
|
||||
};
|
||||
}, [menuOpen]);
|
||||
|
||||
const toggleTheme = () => {
|
||||
const next = theme === "dark" ? "light" : "dark";
|
||||
setTheme(next);
|
||||
localStorage.setItem("nomadro-theme", next);
|
||||
try {
|
||||
localStorage.setItem("nomadro-theme", next);
|
||||
} catch {
|
||||
/* private mode */
|
||||
}
|
||||
document.documentElement.setAttribute("data-theme", next);
|
||||
document.documentElement.classList.toggle("light", next === "light");
|
||||
document.documentElement.classList.toggle("dark", next === "dark");
|
||||
window.dispatchEvent(new Event("nomadro-theme-changed"));
|
||||
};
|
||||
|
||||
const closeMenus = () => {
|
||||
@ -104,38 +172,49 @@ export default function SiteShell({
|
||||
加群
|
||||
</button>
|
||||
) : (
|
||||
<Link href={socialPath("/join")} className="btn btn-primary btn-sm" onClick={closeMenus}>
|
||||
<Link
|
||||
href={socialPath("/join")}
|
||||
className="btn btn-primary btn-sm"
|
||||
onClick={closeMenus}
|
||||
>
|
||||
加群
|
||||
</Link>
|
||||
);
|
||||
|
||||
const nav = (
|
||||
<nav
|
||||
className={`navbar${mounted && scrolled ? " scrolled" : ""}`}
|
||||
ref={navRef}
|
||||
className={`navbar${scrolled ? " scrolled" : ""}`}
|
||||
aria-label="游民社区"
|
||||
>
|
||||
<div className="nav-container">
|
||||
<Link href={socialPath("/")} className="nav-logo" onClick={closeMenus}>
|
||||
<span className="logo-icon">◈</span>
|
||||
<span className="logo-text">{title || "游民社区"}</span>
|
||||
<span className="logo-text">游民社区</span>
|
||||
</Link>
|
||||
|
||||
<div className={`nav-links${menuOpen ? " open" : ""}`}>
|
||||
<div id={menuId} className={`nav-links${menuOpen ? " open" : ""}`}>
|
||||
{GROUPS.map((g) => (
|
||||
<div
|
||||
key={g.id}
|
||||
className={`nav-group${openGroup === g.id ? " open" : ""}`}
|
||||
className={`nav-group${openGroup === g.id ? " open" : ""}${g.items.some((item) => pathname.startsWith(socialPath(item.href))) ? " is-active" : ""}`}
|
||||
onMouseEnter={() => {
|
||||
if (window.matchMedia("(min-width: 769px)").matches) setOpenGroup(g.id);
|
||||
if (window.matchMedia("(min-width: 901px)").matches)
|
||||
setOpenGroup(g.id);
|
||||
}}
|
||||
onMouseLeave={() => {
|
||||
if (window.matchMedia("(min-width: 769px)").matches) setOpenGroup(null);
|
||||
onMouseLeave={(event) => {
|
||||
if (
|
||||
window.matchMedia("(min-width: 901px)").matches &&
|
||||
!event.currentTarget.contains(document.activeElement)
|
||||
)
|
||||
setOpenGroup(null);
|
||||
}}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
className="nav-group-btn"
|
||||
aria-expanded={openGroup === g.id}
|
||||
aria-controls={`${menuId}-${g.id}`}
|
||||
onClick={() => setOpenGroup(openGroup === g.id ? null : g.id)}
|
||||
>
|
||||
{g.label}
|
||||
@ -143,11 +222,14 @@ export default function SiteShell({
|
||||
▾
|
||||
</span>
|
||||
</button>
|
||||
<div className="nav-group-panel">
|
||||
<div id={`${menuId}-${g.id}`} className="nav-group-panel">
|
||||
{g.items.map((item) => (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={socialPath(item.href)}
|
||||
aria-current={
|
||||
pathname === socialPath(item.href) ? "page" : undefined
|
||||
}
|
||||
onClick={closeMenus}
|
||||
>
|
||||
{item.label}
|
||||
@ -158,7 +240,11 @@ export default function SiteShell({
|
||||
))}
|
||||
<div className="nav-mobile-extras">
|
||||
{joinBtn}
|
||||
<Link href="/" className="btn btn-ghost btn-sm" onClick={closeMenus}>
|
||||
<Link
|
||||
href="/"
|
||||
className="btn btn-ghost btn-sm"
|
||||
onClick={closeMenus}
|
||||
>
|
||||
门户
|
||||
</Link>
|
||||
</div>
|
||||
@ -172,7 +258,7 @@ export default function SiteShell({
|
||||
aria-label="切换明暗"
|
||||
suppressHydrationWarning
|
||||
>
|
||||
{!mounted || theme === "dark" ? "🌙" : "☀️"}
|
||||
{theme === "dark" ? <Moon size={17} /> : <Sun size={17} />}
|
||||
</button>
|
||||
<Link
|
||||
href={socialPath("/chat")}
|
||||
@ -180,18 +266,23 @@ export default function SiteShell({
|
||||
aria-label="聊天室"
|
||||
onClick={closeMenus}
|
||||
>
|
||||
◎
|
||||
<MessageCircle size={17} />
|
||||
</Link>
|
||||
<span className="social-nav-desktop-cta">{joinBtn}</span>
|
||||
<Link href="/" className="btn btn-ghost btn-sm social-nav-desktop-cta">
|
||||
<Link
|
||||
href="/"
|
||||
className="btn btn-ghost btn-sm social-nav-desktop-cta"
|
||||
>
|
||||
门户
|
||||
</Link>
|
||||
<button
|
||||
ref={menuButtonRef}
|
||||
type="button"
|
||||
className={`mobile-menu-btn${menuOpen ? " open" : ""}`}
|
||||
onClick={() => setMenuOpen((v) => !v)}
|
||||
aria-label="菜单"
|
||||
aria-expanded={menuOpen}
|
||||
aria-controls={menuId}
|
||||
>
|
||||
<span />
|
||||
<span />
|
||||
@ -205,16 +296,34 @@ export default function SiteShell({
|
||||
if (home) {
|
||||
return (
|
||||
<>
|
||||
<a className="connection-skip-link" href="#social-main">
|
||||
跳到主要内容
|
||||
</a>
|
||||
{nav}
|
||||
{children}
|
||||
<SocialMobileDock />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="social-flow social-root">
|
||||
<div className="social-flow social-root social-workspace">
|
||||
<a className="connection-skip-link" href="#social-main">
|
||||
跳到主要内容
|
||||
</a>
|
||||
{nav}
|
||||
<div className="social-main social-page-pad">{children}</div>
|
||||
<div className="social-workspace-grid">
|
||||
<main className="social-main" id="social-main">
|
||||
<div className="social-breadcrumb">
|
||||
<Link href={socialPath("/")}>nomadro</Link>
|
||||
<span>/</span>
|
||||
<span>{title || "社区"}</span>
|
||||
</div>
|
||||
{children}
|
||||
<SocialFooter />
|
||||
</main>
|
||||
</div>
|
||||
<SocialMobileDock />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
30
src/modules/social/components/SocialAvatar.tsx
Normal file
30
src/modules/social/components/SocialAvatar.tsx
Normal file
@ -0,0 +1,30 @@
|
||||
"use client";
|
||||
|
||||
import Image from "next/image";
|
||||
|
||||
/** Unoptimized keeps external profile images compatible with configured/offline sources. */
|
||||
export default function SocialAvatar({
|
||||
src,
|
||||
size,
|
||||
lazy = false,
|
||||
}: {
|
||||
src: string;
|
||||
size: number;
|
||||
lazy?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<Image
|
||||
src={src}
|
||||
alt=""
|
||||
width={size}
|
||||
height={size}
|
||||
unoptimized
|
||||
loading={lazy ? "lazy" : "eager"}
|
||||
onError={(event) => {
|
||||
const img = event.currentTarget;
|
||||
if (!img.src.endsWith("/icons/nomadro.webp"))
|
||||
img.src = "/icons/nomadro.webp";
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
186
src/modules/social/components/SocialExperience.tsx
Normal file
186
src/modules/social/components/SocialExperience.tsx
Normal file
@ -0,0 +1,186 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
createContext,
|
||||
useContext,
|
||||
useEffect,
|
||||
useRef,
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
import { Sparkles, Zap } from "lucide-react";
|
||||
import { useLocalState } from "@social/lib/useLocalState";
|
||||
import { useRemoteConfig } from "~/lib/use-remote-config";
|
||||
import { DEFAULT_REMOTE_CONFIG } from "~/lib/remote-config";
|
||||
|
||||
const SocialConfigContext = createContext(DEFAULT_REMOTE_CONFIG);
|
||||
export const useSocialConfig = () => useContext(SocialConfigContext);
|
||||
|
||||
function Constellation({ active }: { active: boolean }) {
|
||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||
useEffect(() => {
|
||||
const canvas = canvasRef.current;
|
||||
const context = canvas?.getContext("2d");
|
||||
if (!canvas || !context || !active) return;
|
||||
const media = matchMedia("(prefers-reduced-motion: reduce)");
|
||||
let frame = 0,
|
||||
width = 0,
|
||||
height = 0,
|
||||
last = 0;
|
||||
let pointer = { x: -1000, y: -1000 };
|
||||
let points: {
|
||||
x: number;
|
||||
y: number;
|
||||
vx: number;
|
||||
vy: number;
|
||||
r: number;
|
||||
color: string;
|
||||
}[] = [];
|
||||
const resize = () => {
|
||||
width = innerWidth;
|
||||
height = innerHeight;
|
||||
const ratio = Math.min(devicePixelRatio || 1, 1.5);
|
||||
canvas.width = width * ratio;
|
||||
canvas.height = height * ratio;
|
||||
context.setTransform(ratio, 0, 0, ratio, 0, 0);
|
||||
points = Array.from({ length: width < 700 ? 48 : 96 }, (_, i) => ({
|
||||
x: Math.random() * width,
|
||||
y: Math.random() * height,
|
||||
vx: (Math.random() - 0.5) * 0.48,
|
||||
vy: (Math.random() - 0.5) * 0.48,
|
||||
r: 1.2 + Math.random() * 2.1,
|
||||
color: ["78,205,196", "255,107,107", "255,230,109"][i % 3],
|
||||
}));
|
||||
};
|
||||
const draw = (time: number) => {
|
||||
if (document.hidden || media.matches) return;
|
||||
const delta = Math.min((time - last) / 16.67 || 1, 2);
|
||||
last = time;
|
||||
context.clearRect(0, 0, width, height);
|
||||
points.forEach((p, index) => {
|
||||
p.x = (p.x + p.vx * delta + width) % width;
|
||||
p.y = (p.y + p.vy * delta + height) % height;
|
||||
const near = Math.hypot(pointer.x - p.x, pointer.y - p.y) < 240;
|
||||
context.beginPath();
|
||||
context.arc(p.x, p.y, p.r, 0, Math.PI * 2);
|
||||
context.fillStyle = `rgba(${p.color},${near ? 0.95 : 0.55})`;
|
||||
context.fill();
|
||||
if (near) {
|
||||
context.beginPath();
|
||||
context.arc(p.x, p.y, p.r + 6, 0, Math.PI * 2);
|
||||
context.fillStyle = `rgba(${p.color},0.16)`;
|
||||
context.fill();
|
||||
}
|
||||
if (width > 700)
|
||||
points.slice(index + 1).forEach((q) => {
|
||||
const distance = Math.hypot(q.x - p.x, q.y - p.y);
|
||||
if (distance > 170) return;
|
||||
context.beginPath();
|
||||
context.moveTo(p.x, p.y);
|
||||
context.lineTo(q.x, q.y);
|
||||
context.strokeStyle = `rgba(78,205,196,${(1 - distance / 170) * 0.32})`;
|
||||
context.lineWidth = 1.05;
|
||||
context.stroke();
|
||||
});
|
||||
});
|
||||
frame = requestAnimationFrame(draw);
|
||||
};
|
||||
const restart = () => {
|
||||
cancelAnimationFrame(frame);
|
||||
last = 0;
|
||||
context.clearRect(0, 0, width, height);
|
||||
if (!document.hidden && !media.matches)
|
||||
frame = requestAnimationFrame(draw);
|
||||
};
|
||||
const move = (event: PointerEvent) => {
|
||||
if (event.pointerType === "mouse")
|
||||
pointer = { x: event.clientX, y: event.clientY };
|
||||
};
|
||||
resize();
|
||||
restart();
|
||||
addEventListener("resize", resize);
|
||||
addEventListener("pointermove", move, { passive: true });
|
||||
document.addEventListener("visibilitychange", restart);
|
||||
media.addEventListener("change", restart);
|
||||
return () => {
|
||||
cancelAnimationFrame(frame);
|
||||
removeEventListener("resize", resize);
|
||||
removeEventListener("pointermove", move);
|
||||
document.removeEventListener("visibilitychange", restart);
|
||||
media.removeEventListener("change", restart);
|
||||
context.clearRect(0, 0, width, height);
|
||||
};
|
||||
}, [active]);
|
||||
return (
|
||||
<canvas
|
||||
ref={canvasRef}
|
||||
className="social-constellation"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default function SocialExperience({
|
||||
children,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const { config } = useRemoteConfig();
|
||||
const [immersive, setImmersive] = useLocalState("immersive-fx-v2", true);
|
||||
const rootRef = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
const root = rootRef.current;
|
||||
if (!root || !immersive) return;
|
||||
let frame = 0;
|
||||
const move = (event: PointerEvent) => {
|
||||
if (
|
||||
event.pointerType !== "mouse" ||
|
||||
matchMedia("(prefers-reduced-motion: reduce)").matches
|
||||
)
|
||||
return;
|
||||
cancelAnimationFrame(frame);
|
||||
frame = requestAnimationFrame(() => {
|
||||
root.style.setProperty("--pointer-x", `${event.clientX}px`);
|
||||
root.style.setProperty("--pointer-y", `${event.clientY}px`);
|
||||
const card = (event.target as Element).closest<HTMLElement>(
|
||||
".social-card, .social-list-item, .social-panel, .social-member-card",
|
||||
);
|
||||
if (card) {
|
||||
const rect = card.getBoundingClientRect();
|
||||
card.style.setProperty("--spot-x", `${event.clientX - rect.left}px`);
|
||||
card.style.setProperty("--spot-y", `${event.clientY - rect.top}px`);
|
||||
}
|
||||
});
|
||||
};
|
||||
root.addEventListener("pointermove", move, { passive: true });
|
||||
return () => {
|
||||
cancelAnimationFrame(frame);
|
||||
root.removeEventListener("pointermove", move);
|
||||
};
|
||||
}, [immersive]);
|
||||
return (
|
||||
<div
|
||||
className="social-experience"
|
||||
data-immersive={immersive ? "true" : "false"}
|
||||
ref={rootRef}
|
||||
>
|
||||
<div className="social-ambient" aria-hidden="true">
|
||||
<i />
|
||||
<i />
|
||||
<i />
|
||||
</div>
|
||||
<Constellation active={immersive} />
|
||||
<div className="social-pointer-glow" aria-hidden="true" />
|
||||
<SocialConfigContext value={config}>{children}</SocialConfigContext>
|
||||
<button
|
||||
type="button"
|
||||
className="social-fx-control"
|
||||
onClick={() => setImmersive(!immersive)}
|
||||
aria-pressed={immersive}
|
||||
title="切换视觉动效强度"
|
||||
>
|
||||
<span>{immersive ? <Sparkles size={14} /> : <Zap size={14} />}</span>
|
||||
<span>动效 · {immersive ? "沉浸" : "轻量"}</span>
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
68
src/modules/social/components/SocialNavigation.tsx
Normal file
68
src/modules/social/components/SocialNavigation.tsx
Normal file
@ -0,0 +1,68 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import {
|
||||
CircleUserRound,
|
||||
Compass,
|
||||
House,
|
||||
MessageCircle,
|
||||
Radio,
|
||||
} from "lucide-react";
|
||||
import { socialPath } from "@social/lib/socialPath";
|
||||
|
||||
const LINKS = [
|
||||
{ href: "/", label: "社区首页", icon: House },
|
||||
{ href: "/people", label: "发现同类", icon: Compass },
|
||||
{ href: "/chat", label: "话题聊天室", icon: MessageCircle },
|
||||
{ href: "/meetup", label: "Meetup 活动", icon: Radio },
|
||||
{ href: "/roster", label: "我的游民名片", icon: CircleUserRound },
|
||||
];
|
||||
|
||||
export function SocialMobileDock() {
|
||||
const pathname = usePathname();
|
||||
const links = LINKS;
|
||||
return (
|
||||
<nav className="social-mobile-dock" aria-label="快捷导航">
|
||||
{links.map((item) => (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={socialPath(item.href)}
|
||||
aria-current={
|
||||
(
|
||||
item.href === "/"
|
||||
? pathname === socialPath("/")
|
||||
: pathname.startsWith(socialPath(item.href))
|
||||
)
|
||||
? "page"
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<item.icon size={19} strokeWidth={1.6} />
|
||||
<span>
|
||||
{item.label === "我的游民名片"
|
||||
? "我的名片"
|
||||
: item.label === "话题聊天室"
|
||||
? "聊天"
|
||||
: item.label === "Meetup 活动"
|
||||
? "活动"
|
||||
: item.label}
|
||||
</span>
|
||||
</Link>
|
||||
))}
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
export function SocialFooter() {
|
||||
return (
|
||||
<footer className="social-workspace-footer">
|
||||
<span>nomadro social · Meet beyond borders.</span>
|
||||
<div>
|
||||
<Link href={socialPath("/feedback")}>反馈与建议</Link>
|
||||
<Link href={socialPath("/join")}>加入社区</Link>
|
||||
<Link href={socialPath("/roster")}>我的名片</Link>
|
||||
</div>
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
230
src/modules/social/components/SocialUI.tsx
Normal file
230
src/modules/social/components/SocialUI.tsx
Normal file
@ -0,0 +1,230 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState, type ReactNode } from "react";
|
||||
import { ArrowUpRight, Check, Copy, Search, X } from "lucide-react";
|
||||
import { useLocalState } from "@social/lib/useLocalState";
|
||||
import { useSocialConfig } from "./SocialExperience";
|
||||
import { usePathname } from "next/navigation";
|
||||
|
||||
export function PageIntro({
|
||||
eyebrow,
|
||||
title,
|
||||
accent,
|
||||
description,
|
||||
children,
|
||||
}: {
|
||||
eyebrow: string;
|
||||
title: string;
|
||||
accent: string;
|
||||
description: string;
|
||||
children?: ReactNode;
|
||||
}) {
|
||||
const config = useSocialConfig();
|
||||
const key = usePathname().split("/")[2] || "home";
|
||||
const copy = config.copy.socialPages?.[key];
|
||||
eyebrow =
|
||||
typeof copy?.eyebrow === "string" && copy.eyebrow.trim()
|
||||
? copy.eyebrow
|
||||
: eyebrow;
|
||||
title =
|
||||
typeof copy?.title === "string" && copy.title.trim() ? copy.title : title;
|
||||
accent =
|
||||
typeof copy?.accent === "string" && copy.accent.trim()
|
||||
? copy.accent
|
||||
: accent;
|
||||
description =
|
||||
typeof copy?.description === "string" && copy.description.trim()
|
||||
? copy.description
|
||||
: description;
|
||||
return (
|
||||
<section className="social-page-intro">
|
||||
<div className="social-page-orbit" aria-hidden="true">
|
||||
<i />
|
||||
<i />
|
||||
<i />
|
||||
<span>✦</span>
|
||||
</div>
|
||||
<div className="social-page-kicker">
|
||||
<span />
|
||||
{eyebrow}
|
||||
</div>
|
||||
<h1>
|
||||
{title}
|
||||
<br />
|
||||
<span>{accent}</span>
|
||||
</h1>
|
||||
<p>{description}</p>
|
||||
{children}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export function SearchField({
|
||||
value,
|
||||
onChange,
|
||||
placeholder,
|
||||
label = "搜索",
|
||||
}: {
|
||||
value: string;
|
||||
onChange: (v: string) => void;
|
||||
placeholder: string;
|
||||
label?: string;
|
||||
}) {
|
||||
return (
|
||||
<label className="social-search">
|
||||
<Search size={17} />
|
||||
<input
|
||||
type="search"
|
||||
aria-label={label}
|
||||
placeholder={placeholder}
|
||||
value={value}
|
||||
onChange={(event) => onChange(event.target.value)}
|
||||
/>
|
||||
{value && (
|
||||
<button
|
||||
type="button"
|
||||
aria-label="清空搜索"
|
||||
onClick={() => onChange("")}
|
||||
>
|
||||
<X size={14} />
|
||||
</button>
|
||||
)}
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
export function BookmarkButton({
|
||||
id,
|
||||
collection = "saved-items",
|
||||
label = "收藏",
|
||||
}: {
|
||||
id: string;
|
||||
collection?: string;
|
||||
label?: string;
|
||||
}) {
|
||||
const [items, setItems] = useLocalState<string[]>(collection, []);
|
||||
const selected = Array.isArray(items) && items.includes(id);
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className={`social-save${selected ? " selected" : ""}`}
|
||||
aria-pressed={selected}
|
||||
onClick={() =>
|
||||
setItems((current) =>
|
||||
selected ? current.filter((item) => item !== id) : [...current, id],
|
||||
)
|
||||
}
|
||||
title="收藏保存在当前设备"
|
||||
>
|
||||
{selected ? <Check size={15} /> : <span aria-hidden>+</span>}
|
||||
{selected ? "已收藏" : label}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
export function ShareButton({ path, title }: { path: string; title: string }) {
|
||||
const [state, setState] = useState("");
|
||||
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
useEffect(
|
||||
() => () => {
|
||||
if (timer.current) clearTimeout(timer.current);
|
||||
},
|
||||
[],
|
||||
);
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="social-save"
|
||||
onClick={async () => {
|
||||
const url = new URL(path, location.origin).href;
|
||||
try {
|
||||
if (navigator.share) {
|
||||
await navigator.share({ title, url });
|
||||
setState("已分享");
|
||||
} else {
|
||||
await navigator.clipboard.writeText(url);
|
||||
setState("已复制");
|
||||
}
|
||||
} catch (error) {
|
||||
if ((error as DOMException).name !== "AbortError")
|
||||
setState("请复制地址栏链接");
|
||||
}
|
||||
if (timer.current) clearTimeout(timer.current);
|
||||
timer.current = setTimeout(() => setState(""), 3000);
|
||||
}}
|
||||
>
|
||||
<Copy size={14} />
|
||||
<span role="status">{state || "分享"}</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
export function EmptyState({
|
||||
title = "暂时没有找到",
|
||||
description = "换个关键词,或试试其他筛选。",
|
||||
children,
|
||||
}: {
|
||||
title?: string;
|
||||
description?: string;
|
||||
children?: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div className="social-empty">
|
||||
<span aria-hidden>✦</span>
|
||||
<h3>{title}</h3>
|
||||
<p>{description}</p>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function SocialDialog({
|
||||
title,
|
||||
onClose,
|
||||
children,
|
||||
}: {
|
||||
title: string;
|
||||
onClose: () => void;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const ref = useRef<HTMLDialogElement>(null);
|
||||
useEffect(() => {
|
||||
const dialog = ref.current;
|
||||
const opener = document.activeElement as HTMLElement;
|
||||
const overflow = document.body.style.overflow;
|
||||
dialog?.showModal();
|
||||
document.body.style.overflow = "hidden";
|
||||
return () => {
|
||||
dialog?.close();
|
||||
document.body.style.overflow = overflow;
|
||||
opener?.focus();
|
||||
};
|
||||
}, []);
|
||||
return (
|
||||
<dialog
|
||||
className="social-detail-dialog"
|
||||
ref={ref}
|
||||
aria-label={title}
|
||||
onCancel={(event) => {
|
||||
event.preventDefault();
|
||||
onClose();
|
||||
}}
|
||||
onClick={(event) => {
|
||||
if (event.target === event.currentTarget) onClose();
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<header>
|
||||
<span>
|
||||
MAKE A CONNECTION <ArrowUpRight size={14} />
|
||||
</span>
|
||||
<button type="button" aria-label="关闭详情" onClick={onClose}>
|
||||
<X size={20} />
|
||||
</button>
|
||||
</header>
|
||||
<h2>{title}</h2>
|
||||
{children}
|
||||
</div>
|
||||
</dialog>
|
||||
);
|
||||
}
|
||||
@ -1,161 +1,3 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo, useState } from "react";
|
||||
import SiteShell from "./SiteShell";
|
||||
import { socialApi } from "@social/lib/api";
|
||||
import { SEED_GIGS, TEAM_KIND_LABEL } from "@social/lib/seed";
|
||||
import { loadJson, saveJson, uid } from "@social/lib/storage";
|
||||
import type { SocialTeamKind } from "@social/lib/types";
|
||||
|
||||
type Application = {
|
||||
id: string;
|
||||
gigId: string;
|
||||
name: string;
|
||||
contact: string;
|
||||
note: string;
|
||||
at: string;
|
||||
};
|
||||
|
||||
const TABS: { id: SocialTeamKind | "all"; label: string }[] = [
|
||||
{ id: "all", label: "全部" },
|
||||
{ id: "volunteer", label: "志愿者" },
|
||||
{ id: "parttime", label: "兼职" },
|
||||
{ id: "fulltime", label: "全职" },
|
||||
];
|
||||
|
||||
export default function TeamClient({
|
||||
initialKind = "all",
|
||||
}: {
|
||||
initialKind?: SocialTeamKind | "all";
|
||||
}) {
|
||||
const [tab, setTab] = useState<SocialTeamKind | "all">(initialKind);
|
||||
const roles = useMemo(() => {
|
||||
if (tab === "all") return SEED_GIGS;
|
||||
return SEED_GIGS.filter((g) => (g.kind || "parttime") === tab);
|
||||
}, [tab]);
|
||||
|
||||
const [gigId, setGigId] = useState(roles[0]?.id || SEED_GIGS[0]?.id || "");
|
||||
const [name, setName] = useState("");
|
||||
const [contact, setContact] = useState("");
|
||||
const [note, setNote] = useState("");
|
||||
const [ok, setOk] = useState("");
|
||||
|
||||
const active = SEED_GIGS.find((g) => g.id === gigId) || roles[0];
|
||||
|
||||
const selectTab = (next: SocialTeamKind | "all") => {
|
||||
setTab(next);
|
||||
setOk("");
|
||||
const list =
|
||||
next === "all" ? SEED_GIGS : SEED_GIGS.filter((g) => (g.kind || "parttime") === next);
|
||||
if (list[0]) setGigId(list[0].id);
|
||||
};
|
||||
|
||||
const apply = async () => {
|
||||
if (!gigId || !name.trim() || !contact.trim()) return;
|
||||
const payload = {
|
||||
name: name.trim(),
|
||||
contact: contact.trim(),
|
||||
note: note.trim(),
|
||||
};
|
||||
try {
|
||||
await socialApi.applyGig(gigId, payload);
|
||||
setOk("已同步到游民社区独立库。");
|
||||
} catch {
|
||||
const list = loadJson<Application[]>("gig-apps", []);
|
||||
const item: Application = {
|
||||
id: uid("app"),
|
||||
gigId,
|
||||
...payload,
|
||||
at: new Date().toISOString(),
|
||||
};
|
||||
saveJson("gig-apps", [item, ...list]);
|
||||
setOk("后端暂不可用,申请已先存本机。");
|
||||
}
|
||||
setNote("");
|
||||
};
|
||||
|
||||
return (
|
||||
<SiteShell title="远程团队">
|
||||
<section className="social-hero">
|
||||
<div className="social-hero-tag">TEAM</div>
|
||||
<h1>
|
||||
远程团队
|
||||
<br />
|
||||
<span>志愿者 · 兼职 · 全职</span>
|
||||
</h1>
|
||||
<p>先看人、再投递。可远程协作,群里也能问内推。</p>
|
||||
</section>
|
||||
|
||||
<div className="social-team-tabs" role="tablist" aria-label="岗位类型">
|
||||
{TABS.map((t) => (
|
||||
<button
|
||||
key={t.id}
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={tab === t.id}
|
||||
className={`social-team-tab${tab === t.id ? " active" : ""}`}
|
||||
onClick={() => selectTab(t.id)}
|
||||
>
|
||||
{t.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="social-list" style={{ marginTop: 14 }}>
|
||||
{roles.length === 0 ? (
|
||||
<p className="social-muted">该分类暂无岗位。</p>
|
||||
) : (
|
||||
roles.map((g) => (
|
||||
<button
|
||||
key={g.id}
|
||||
type="button"
|
||||
className={`social-list-item social-card-btn${g.id === gigId ? " active" : ""}`}
|
||||
onClick={() => setGigId(g.id)}
|
||||
>
|
||||
<div>
|
||||
<strong>{g.title}</strong>
|
||||
<p>
|
||||
{TEAM_KIND_LABEL[g.kind || "parttime"]} · {g.role} · {g.pay} ·{" "}
|
||||
{g.remote ? "远程" : "驻场 / 混合"}
|
||||
</p>
|
||||
<p className="social-muted">{g.tags.join(" · ")}</p>
|
||||
</div>
|
||||
</button>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
|
||||
{active ? (
|
||||
<section className="social-panel" style={{ marginTop: 20 }}>
|
||||
<h2>投递 · {active.title}</h2>
|
||||
<p className="social-muted" style={{ marginTop: 4 }}>
|
||||
{TEAM_KIND_LABEL[active.kind || "parttime"]} · {active.pay}
|
||||
</p>
|
||||
<div className="social-form">
|
||||
<label>
|
||||
姓名
|
||||
<input value={name} onChange={(e) => setName(e.target.value)} maxLength={64} />
|
||||
</label>
|
||||
<label>
|
||||
联系方式
|
||||
<input
|
||||
value={contact}
|
||||
onChange={(e) => setContact(e.target.value)}
|
||||
placeholder="微信 / 手机 / 邮箱"
|
||||
maxLength={120}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
自我介绍 / 作品链接
|
||||
<textarea rows={3} value={note} onChange={(e) => setNote(e.target.value)} maxLength={2000} />
|
||||
</label>
|
||||
<button type="button" className="social-btn primary" onClick={() => void apply()}>
|
||||
提交申请
|
||||
</button>
|
||||
{ok ? <p className="social-muted">{ok}</p> : null}
|
||||
</div>
|
||||
</section>
|
||||
) : null}
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
export { default } from "./RoleBoard";
|
||||
|
||||
@ -1,44 +1,3 @@
|
||||
"use client";
|
||||
|
||||
import SiteShell from "./SiteShell";
|
||||
import { SEED_VIDEOS } from "@social/lib/seed";
|
||||
|
||||
export default function VideosClient() {
|
||||
return (
|
||||
<SiteShell title="视频">
|
||||
<section className="social-hero">
|
||||
<div className="social-hero-tag">UGC · 视频</div>
|
||||
<h1>
|
||||
视频库
|
||||
<br />
|
||||
<span>访谈 · 旅居切片 · Date 成片</span>
|
||||
</h1>
|
||||
<p>当前为可浏览目录;片源可接 PeerTube / SeaweedFS。点击条目可锚定分享。</p>
|
||||
</section>
|
||||
<div className="social-grid">
|
||||
{SEED_VIDEOS.map((v) => (
|
||||
<article key={v.id} id={v.id} className="social-card">
|
||||
<div className="social-card-top">
|
||||
<span className="social-card-ico">{v.coverEmoji}</span>
|
||||
<span className="social-badge">{v.minutes} 分</span>
|
||||
</div>
|
||||
<strong>{v.title}</strong>
|
||||
<p>
|
||||
{v.city} · {v.summary}
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
className="social-btn"
|
||||
onClick={() => {
|
||||
const url = `${window.location.pathname}#${v.id}`;
|
||||
void navigator.clipboard?.writeText(window.location.origin + url);
|
||||
}}
|
||||
>
|
||||
复制分享链接
|
||||
</button>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
export { VideosLibrary as default } from "./ResourceLibrary";
|
||||
|
||||
@ -1,65 +1,3 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import SiteShell from "./SiteShell";
|
||||
import { socialPath } from "@social/lib/socialPath";
|
||||
import { useRemoteConfig } from "~/lib/use-remote-config";
|
||||
|
||||
export default function VipClient() {
|
||||
const { config } = useRemoteConfig();
|
||||
const fen = config.copy?.vipPriceFen || 29800;
|
||||
const price = (fen / 100).toFixed(0);
|
||||
const cta = config.copy?.vipCta || `立即加入 · ¥${price}`;
|
||||
|
||||
return (
|
||||
<SiteShell title="会员">
|
||||
<section className="social-hero">
|
||||
<div className="social-hero-tag">虚拟支付</div>
|
||||
<h1>
|
||||
游民社区 VIP
|
||||
<br />
|
||||
<span>花名册广场 · 优先约见 · 活动席位</span>
|
||||
</h1>
|
||||
<p>
|
||||
国内虚拟支付走门户统一网关(zpay / xpay);海外可接 Creem。价格由远程配置下发:¥{price}。
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<div className="social-grid">
|
||||
<article className="social-card">
|
||||
<div className="social-card-top">
|
||||
<span className="social-card-ico">📇</span>
|
||||
<span className="social-badge live">权益</span>
|
||||
</div>
|
||||
<strong>职业花名册公开</strong>
|
||||
<p>资料进入可检索花名册,同城 / 同业可见</p>
|
||||
</article>
|
||||
<article className="social-card">
|
||||
<div className="social-card-top">
|
||||
<span className="social-card-ico">☕</span>
|
||||
<span className="social-badge live">权益</span>
|
||||
</div>
|
||||
<strong>Coffeechat 优先</strong>
|
||||
<p>合作咖啡馆预约与线下活动席位优先</p>
|
||||
</article>
|
||||
<article className="social-card">
|
||||
<div className="social-card-top">
|
||||
<span className="social-card-ico">📹</span>
|
||||
<span className="social-badge live">权益</span>
|
||||
</div>
|
||||
<strong>Meetup 席位</strong>
|
||||
<p>线上 WebRTC 房间与 AMA 优先入场</p>
|
||||
</article>
|
||||
</div>
|
||||
|
||||
<div className="social-actions" style={{ marginTop: 24 }}>
|
||||
<Link className="social-btn primary" href="/vip">
|
||||
{cta}
|
||||
</Link>
|
||||
<Link className="social-btn" href={socialPath("/roster")}>
|
||||
先完善花名册
|
||||
</Link>
|
||||
</div>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
export { CommunityMembership as default } from "./CommunityWelcome";
|
||||
|
||||
65
src/modules/social/components/WorldConnections.tsx
Normal file
65
src/modules/social/components/WorldConnections.tsx
Normal file
@ -0,0 +1,65 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { Globe2 } from "lucide-react";
|
||||
|
||||
const CITIES = [
|
||||
{ name: "清迈", zone: "Asia/Bangkok", caption: "CHIANG MAI", emoji: "🌿" },
|
||||
{ name: "大理", zone: "Asia/Shanghai", caption: "DALI", emoji: "🏔️" },
|
||||
{ name: "里斯本", zone: "Europe/Lisbon", caption: "LISBON", emoji: "🌊" },
|
||||
{ name: "巴厘岛", zone: "Asia/Makassar", caption: "BALI", emoji: "🌴" },
|
||||
];
|
||||
export default function WorldConnections() {
|
||||
const [now, setNow] = useState<Date | null>(null);
|
||||
useEffect(() => {
|
||||
const update = () => setNow(new Date());
|
||||
const first = requestAnimationFrame(update);
|
||||
const timer = setInterval(update, 30000);
|
||||
return () => {
|
||||
cancelAnimationFrame(first);
|
||||
clearInterval(timer);
|
||||
};
|
||||
}, []);
|
||||
return (
|
||||
<div className="container social-world-strip">
|
||||
<div>
|
||||
<strong>
|
||||
<Globe2
|
||||
size={14}
|
||||
style={{
|
||||
display: "inline",
|
||||
verticalAlign: "middle",
|
||||
marginRight: 7,
|
||||
}}
|
||||
/>
|
||||
世界在流动,连接在发生
|
||||
</strong>
|
||||
<p>四座城市 · 此刻的当地时间</p>
|
||||
</div>
|
||||
{CITIES.map((city) => (
|
||||
<div className="social-world-city" key={city.zone}>
|
||||
<strong>
|
||||
<span aria-hidden>{city.emoji}</span>
|
||||
{city.name}
|
||||
</strong>
|
||||
<time>
|
||||
{now
|
||||
? new Intl.DateTimeFormat("en-GB", {
|
||||
timeZone: city.zone,
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
hour12: false,
|
||||
}).format(now)
|
||||
: "--:--"}
|
||||
</time>
|
||||
<small>{city.caption}</small>
|
||||
<Link
|
||||
href={`/social/people?city=${encodeURIComponent(city.name)}`}
|
||||
aria-label={`发现${city.name}的游民`}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -32,6 +32,7 @@ async function req<T>(
|
||||
headers,
|
||||
body,
|
||||
cache: "no-store",
|
||||
signal: init?.signal || AbortSignal.timeout(8000),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = await res.text().catch(() => "");
|
||||
@ -49,7 +50,8 @@ export type SocialRealtimeToken = {
|
||||
};
|
||||
|
||||
export const socialApi = {
|
||||
health: () => req<{ ok: boolean; isolated?: boolean; centrifugo?: boolean }>("/health"),
|
||||
health: () =>
|
||||
req<{ ok: boolean; isolated?: boolean; centrifugo?: boolean }>("/health"),
|
||||
|
||||
realtimeToken: (channelId: string) =>
|
||||
req<SocialRealtimeToken>(
|
||||
@ -57,32 +59,57 @@ export const socialApi = {
|
||||
),
|
||||
|
||||
listMessages: (channelId: string) =>
|
||||
req<{ items: Array<{ id: string; channelId: string; author: string; text: string; at: string; guestId?: string }> }>(
|
||||
`/channels/${encodeURIComponent(channelId)}/messages`,
|
||||
),
|
||||
req<{
|
||||
items: Array<{
|
||||
id: string;
|
||||
channelId: string;
|
||||
author: string;
|
||||
text: string;
|
||||
at: string;
|
||||
guestId?: string;
|
||||
}>;
|
||||
}>(`/channels/${encodeURIComponent(channelId)}/messages`),
|
||||
|
||||
sendMessage: (channelId: string, author: string, text: string) =>
|
||||
req<{ id: string; channelId: string; author: string; text: string; at: string }>(
|
||||
`/channels/${encodeURIComponent(channelId)}/messages`,
|
||||
{ method: "POST", json: { author, text } },
|
||||
),
|
||||
req<{
|
||||
id: string;
|
||||
channelId: string;
|
||||
author: string;
|
||||
text: string;
|
||||
at: string;
|
||||
}>(`/channels/${encodeURIComponent(channelId)}/messages`, {
|
||||
method: "POST",
|
||||
json: { author, text },
|
||||
}),
|
||||
|
||||
listReviews: (cafeId: string) =>
|
||||
req<{ items: Array<{ id: string; cafeId: string; author: string; score: number; text: string; photoNote?: string; at: string }> }>(
|
||||
`/cafes/${encodeURIComponent(cafeId)}/reviews`,
|
||||
),
|
||||
req<{
|
||||
items: Array<{
|
||||
id: string;
|
||||
cafeId: string;
|
||||
author: string;
|
||||
score: number;
|
||||
text: string;
|
||||
photoNote?: string;
|
||||
at: string;
|
||||
}>;
|
||||
}>(`/cafes/${encodeURIComponent(cafeId)}/reviews`),
|
||||
|
||||
postReview: (
|
||||
cafeId: string,
|
||||
payload: { author: string; score: number; text: string; photoNote?: string },
|
||||
payload: {
|
||||
author: string;
|
||||
score: number;
|
||||
text: string;
|
||||
photoNote?: string;
|
||||
},
|
||||
) =>
|
||||
req(`/cafes/${encodeURIComponent(cafeId)}/reviews`, {
|
||||
method: "POST",
|
||||
json: payload,
|
||||
}),
|
||||
|
||||
getRoster: () =>
|
||||
req<{ item: Record<string, string> | null }>("/roster/me"),
|
||||
getRoster: () => req<{ item: Record<string, string> | null }>("/roster/me"),
|
||||
|
||||
saveRoster: (payload: Record<string, string>) =>
|
||||
req("/roster/me", { method: "PUT", json: payload }),
|
||||
@ -90,7 +117,10 @@ export const socialApi = {
|
||||
postFeedback: (payload: { kind: string; text: string; contact?: string }) =>
|
||||
req("/feedback", { method: "POST", json: payload }),
|
||||
|
||||
applyGig: (gigId: string, payload: { name: string; contact: string; note?: string }) =>
|
||||
applyGig: (
|
||||
gigId: string,
|
||||
payload: { name: string; contact: string; note?: string },
|
||||
) =>
|
||||
req(`/gigs/${encodeURIComponent(gigId)}/apply`, {
|
||||
method: "POST",
|
||||
json: payload,
|
||||
|
||||
77
src/modules/social/lib/calendar.ts
Normal file
77
src/modules/social/lib/calendar.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import type { SocialMeetup } from "./types";
|
||||
|
||||
/** Seed schedules explicitly use Asia/Shanghai; IANA zones can override per event. */
|
||||
export function eventDate(event: SocialMeetup): Date {
|
||||
const [year, month, day] = event.date.split("-").map(Number);
|
||||
const [hour, minute] = event.time.split(":").map(Number);
|
||||
const target = Date.UTC(year, month - 1, day, hour, minute);
|
||||
let instant = target;
|
||||
const formatter = new Intl.DateTimeFormat("en-CA", {
|
||||
timeZone: event.timeZone || "Asia/Shanghai",
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
second: "2-digit",
|
||||
hourCycle: "h23",
|
||||
});
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const parts = Object.fromEntries(
|
||||
formatter
|
||||
.formatToParts(instant)
|
||||
.filter((part) => part.type !== "literal")
|
||||
.map((part) => [part.type, Number(part.value)]),
|
||||
);
|
||||
const represented = Date.UTC(
|
||||
parts.year,
|
||||
parts.month - 1,
|
||||
parts.day,
|
||||
parts.hour,
|
||||
parts.minute,
|
||||
parts.second,
|
||||
);
|
||||
instant += target - represented;
|
||||
}
|
||||
return new Date(instant);
|
||||
}
|
||||
|
||||
function escapeIcs(value: string) {
|
||||
return value
|
||||
.replace(/\\/g, "\\\\")
|
||||
.replace(/\n/g, "\\n")
|
||||
.replace(/,/g, "\\,")
|
||||
.replace(/;/g, "\\;");
|
||||
}
|
||||
export function saveEventCalendar(event: SocialMeetup) {
|
||||
const stamp = (date: Date) =>
|
||||
date
|
||||
.toISOString()
|
||||
.replace(/[-:]/g, "")
|
||||
.replace(/\.\d{3}/, "");
|
||||
const url = `${location.origin}/social/meetup/${encodeURIComponent(event.id)}`;
|
||||
const content = [
|
||||
"BEGIN:VCALENDAR",
|
||||
"VERSION:2.0",
|
||||
"PRODID:-//nomadro//Social Events//ZH",
|
||||
"CALSCALE:GREGORIAN",
|
||||
"BEGIN:VEVENT",
|
||||
`UID:${event.id}@nomadro.social`,
|
||||
`DTSTAMP:${stamp(new Date())}`,
|
||||
`DTSTART:${stamp(eventDate(event))}`,
|
||||
`SUMMARY:${escapeIcs(event.title)}`,
|
||||
`DESCRIPTION:${escapeIcs(`nomadro 活动预览。活动时区:${event.timeZone || "Asia/Shanghai"}。具体安排请在活动频道确认。\n${url}`)}`,
|
||||
`URL:${url}`,
|
||||
"END:VEVENT",
|
||||
"END:VCALENDAR",
|
||||
].join("\r\n");
|
||||
const blob = new Blob([content], { type: "text/calendar;charset=utf-8" });
|
||||
const href = URL.createObjectURL(blob);
|
||||
const anchor = document.createElement("a");
|
||||
anchor.href = href;
|
||||
anchor.download = `nomadro-${event.id}.ics`;
|
||||
document.body.appendChild(anchor);
|
||||
anchor.click();
|
||||
anchor.remove();
|
||||
setTimeout(() => URL.revokeObjectURL(href), 1000);
|
||||
}
|
||||
36
src/modules/social/lib/landing.ts
Normal file
36
src/modules/social/lib/landing.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import {
|
||||
DEFAULT_REMOTE_CONFIG,
|
||||
type NomadroRemoteConfig,
|
||||
} from "~/lib/remote-config";
|
||||
|
||||
const COPY_KEYS = [
|
||||
"socialEyebrow",
|
||||
"socialHeroLine1",
|
||||
"socialHeroAccent",
|
||||
"socialHeroLead",
|
||||
"socialJoinCta",
|
||||
"socialInviteTitle",
|
||||
"socialInviteLead",
|
||||
"socialOnlineTitle",
|
||||
"socialOfflineTitle",
|
||||
"socialTeamTitle",
|
||||
] as const;
|
||||
|
||||
export type SocialLandingCopy = Record<(typeof COPY_KEYS)[number], string>;
|
||||
|
||||
/** Treat malformed remote fields as absent and keep the landing usable offline. */
|
||||
export function resolveSocialLandingCopy(
|
||||
copy: NomadroRemoteConfig["copy"],
|
||||
): SocialLandingCopy {
|
||||
return Object.fromEntries(
|
||||
COPY_KEYS.map((key) => {
|
||||
const value = copy[key];
|
||||
return [
|
||||
key,
|
||||
typeof value === "string" && value.trim()
|
||||
? value
|
||||
: DEFAULT_REMOTE_CONFIG.copy[key],
|
||||
];
|
||||
}),
|
||||
) as SocialLandingCopy;
|
||||
}
|
||||
@ -26,8 +26,7 @@ export async function connectChatRealtime(
|
||||
|
||||
const handlePub = (ctx: { data?: unknown }) => {
|
||||
const data = ctx?.data as
|
||||
| { type?: string; message?: SocialChatMessage }
|
||||
| undefined;
|
||||
{ type?: string; message?: SocialChatMessage } | undefined;
|
||||
if (!data || data.type !== "chat.message" || !data.message?.id) return;
|
||||
onMessage({
|
||||
id: data.message.id,
|
||||
@ -36,6 +35,7 @@ export async function connectChatRealtime(
|
||||
text: data.message.text || "",
|
||||
at: data.message.at || new Date().toISOString(),
|
||||
mine: Boolean(data.message.mine),
|
||||
guestId: data.message.guestId,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -12,6 +12,8 @@ export type SocialChatMessage = {
|
||||
text: string;
|
||||
at: string;
|
||||
mine?: boolean;
|
||||
guestId?: string;
|
||||
delivery?: "sent" | "local" | "demo";
|
||||
};
|
||||
|
||||
export type SocialCafe = {
|
||||
@ -44,6 +46,7 @@ export type SocialMeetup = {
|
||||
time: string;
|
||||
mode: "online" | "hybrid";
|
||||
mirotalkRoom: string;
|
||||
timeZone?: string;
|
||||
channelId: string;
|
||||
};
|
||||
|
||||
|
||||
37
src/modules/social/lib/useLocalState.ts
Normal file
37
src/modules/social/lib/useLocalState.ts
Normal file
@ -0,0 +1,37 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useMemo, useSyncExternalStore } from "react";
|
||||
import { loadJson, saveJson } from "./storage";
|
||||
|
||||
const CHANGE = "nomadro-social-storage";
|
||||
function subscribe(callback: () => void) {
|
||||
window.addEventListener(CHANGE, callback);
|
||||
window.addEventListener("storage", callback);
|
||||
return () => {
|
||||
window.removeEventListener(CHANGE, callback);
|
||||
window.removeEventListener("storage", callback);
|
||||
};
|
||||
}
|
||||
|
||||
/** Hydration-safe local preferences, drafts and bookmarks; never presented as server data. */
|
||||
export function useLocalState<T>(key: string, fallback: T) {
|
||||
const initial = JSON.stringify(fallback);
|
||||
const snapshot = useSyncExternalStore(
|
||||
subscribe,
|
||||
() => JSON.stringify(loadJson(key, fallback)),
|
||||
() => initial,
|
||||
);
|
||||
const value = useMemo(() => JSON.parse(snapshot) as T, [snapshot]);
|
||||
const setValue = useCallback(
|
||||
(next: T | ((current: T) => T)) => {
|
||||
const current = loadJson<T>(key, JSON.parse(initial) as T);
|
||||
saveJson(
|
||||
key,
|
||||
typeof next === "function" ? (next as (v: T) => T)(current) : next,
|
||||
);
|
||||
window.dispatchEvent(new Event(CHANGE));
|
||||
},
|
||||
[key, initial],
|
||||
);
|
||||
return [value, setValue] as const;
|
||||
}
|
||||
169
src/modules/social/lib/useSocialChat.ts
Normal file
169
src/modules/social/lib/useSocialChat.ts
Normal file
@ -0,0 +1,169 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { socialApi, getGuestId } from "./api";
|
||||
import { SEED_MESSAGES } from "./seed";
|
||||
import { loadJson, saveJson, uid } from "./storage";
|
||||
import { useLocalState } from "./useLocalState";
|
||||
import type { SocialChatMessage } from "./types";
|
||||
|
||||
export function useSocialChat(channelId: string) {
|
||||
const seeds = useMemo(
|
||||
() =>
|
||||
SEED_MESSAGES.filter((item) => item.channelId === channelId).map(
|
||||
(item) => ({ ...item, delivery: "demo" as const }),
|
||||
),
|
||||
[channelId],
|
||||
);
|
||||
const [messages, setMessages] = useLocalState<SocialChatMessage[]>(
|
||||
`chat:${channelId}`,
|
||||
seeds,
|
||||
);
|
||||
const [draft, setDraft] = useLocalState(`chat-draft:${channelId}`, "");
|
||||
const [nick, setNick] = useLocalState("nick", "游民");
|
||||
const [status, setStatus] = useState<
|
||||
"connecting" | "online" | "offline" | "preview"
|
||||
>("connecting");
|
||||
const [sending, setSending] = useState(false);
|
||||
const lock = useRef(false);
|
||||
const mounted = useRef(true);
|
||||
|
||||
useEffect(() => {
|
||||
mounted.current = true;
|
||||
let cancelled = false,
|
||||
refreshing = false;
|
||||
let stop: (() => void) | null = null;
|
||||
const refresh = async () => {
|
||||
if (cancelled || document.hidden || refreshing) return;
|
||||
refreshing = true;
|
||||
try {
|
||||
const response = await socialApi.listMessages(channelId);
|
||||
if (cancelled) return;
|
||||
const items = response.items || [];
|
||||
if (items.length) {
|
||||
setMessages((current) => {
|
||||
const knownOwn = new Set(
|
||||
current.filter((item) => item.mine).map((item) => item.id),
|
||||
);
|
||||
const remote = items.map((item) => ({
|
||||
...item,
|
||||
mine: item.guestId === getGuestId() || knownOwn.has(item.id),
|
||||
delivery: "sent" as const,
|
||||
}));
|
||||
const ids = new Set(remote.map((item) => item.id));
|
||||
return [
|
||||
...remote,
|
||||
...current.filter(
|
||||
(item) =>
|
||||
item.mine && !ids.has(item.id) && item.delivery !== "demo",
|
||||
),
|
||||
].slice(-300);
|
||||
});
|
||||
}
|
||||
setStatus(items.length ? "online" : "preview");
|
||||
} catch {
|
||||
if (!cancelled) setStatus("offline");
|
||||
} finally {
|
||||
refreshing = false;
|
||||
}
|
||||
};
|
||||
void refresh();
|
||||
const timer = setInterval(() => void refresh(), 6000);
|
||||
const onVisible = () => {
|
||||
if (!document.hidden) void refresh();
|
||||
};
|
||||
document.addEventListener("visibilitychange", onVisible);
|
||||
void import("./realtime")
|
||||
.then(async ({ connectChatRealtime }) => {
|
||||
if (cancelled) return;
|
||||
const connection = await connectChatRealtime(channelId, (item) => {
|
||||
if (cancelled) return;
|
||||
setMessages((current) =>
|
||||
current.some((message) => message.id === item.id)
|
||||
? current
|
||||
: [
|
||||
...current.filter((message) => message.delivery !== "demo"),
|
||||
{
|
||||
...item,
|
||||
mine: item.guestId === getGuestId(),
|
||||
delivery: "sent" as const,
|
||||
},
|
||||
].slice(-300),
|
||||
);
|
||||
setStatus("online");
|
||||
});
|
||||
if (cancelled) connection?.disconnect();
|
||||
else stop = connection?.disconnect || null;
|
||||
})
|
||||
.catch(() => undefined);
|
||||
return () => {
|
||||
cancelled = true;
|
||||
mounted.current = false;
|
||||
clearInterval(timer);
|
||||
stop?.();
|
||||
document.removeEventListener("visibilitychange", onVisible);
|
||||
};
|
||||
}, [channelId, setMessages]);
|
||||
|
||||
const send = useCallback(
|
||||
async (body: string, retryId?: string) => {
|
||||
if (!body.trim() || body.length > 2000 || lock.current) return false;
|
||||
lock.current = true;
|
||||
setSending(true);
|
||||
const author = nick.trim() || "游民";
|
||||
const payload = body.trim();
|
||||
try {
|
||||
const saved = await socialApi.sendMessage(channelId, author, payload);
|
||||
if (!saved.id) throw new Error("Message was not accepted");
|
||||
if (!mounted.current) return false;
|
||||
setMessages((current) =>
|
||||
[
|
||||
...current.filter(
|
||||
(item) =>
|
||||
item.id !== retryId &&
|
||||
item.delivery !== "demo" &&
|
||||
item.id !== saved.id,
|
||||
),
|
||||
{
|
||||
...saved,
|
||||
mine: true,
|
||||
guestId: getGuestId(),
|
||||
delivery: "sent" as const,
|
||||
},
|
||||
].slice(-300),
|
||||
);
|
||||
setStatus("online");
|
||||
if (!retryId && loadJson(`chat-draft:${channelId}`, "") === body)
|
||||
setDraft("");
|
||||
saveJson("nick", author);
|
||||
return true;
|
||||
} catch {
|
||||
if (!mounted.current) return false;
|
||||
if (!retryId)
|
||||
setMessages((current) =>
|
||||
[
|
||||
...current,
|
||||
{
|
||||
id: uid("local"),
|
||||
channelId,
|
||||
author,
|
||||
text: payload,
|
||||
at: new Date().toISOString(),
|
||||
mine: true,
|
||||
delivery: "local" as const,
|
||||
},
|
||||
].slice(-300),
|
||||
);
|
||||
setStatus("offline");
|
||||
if (!retryId && loadJson(`chat-draft:${channelId}`, "") === body)
|
||||
setDraft("");
|
||||
return false;
|
||||
} finally {
|
||||
lock.current = false;
|
||||
if (mounted.current) setSending(false);
|
||||
}
|
||||
},
|
||||
[channelId, nick, setDraft, setMessages],
|
||||
);
|
||||
return { messages, draft, setDraft, nick, setNick, status, sending, send };
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user