nomadro/src/modules/social/components/RoleBoard.tsx
Eric da22814584 Polish /social H5: Ways order, dock, mobile sheets, and chat/date touch UX.
Add dedicated h5.css so group chat leads CTAs, orbit stays compact on phones, and composer/actions clear the bottom dock.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-01 22:43:27 +08:00

403 lines
12 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { useMemo, useRef, useState, type FormEvent } from "react";
import Link from "next/link";
import {
ArrowUpRight,
BookOpen,
BriefcaseBusiness,
Check,
Globe2,
HeartHandshake,
Send,
Sparkles,
} from "lucide-react";
import SiteShell from "./SiteShell";
import {
BookmarkButton,
DemoBadge,
EmptyState,
PageIntro,
SearchField,
SocialDialog,
} from "./SocialUI";
import { TEAM_KIND_LABEL } from "@social/lib/seed";
import { socialApi } from "@social/lib/api";
import { useLocalState } from "@social/lib/useLocalState";
import { resolveSocialCatalog } from "@social/lib/resolveCatalog";
import { useSocialConfig } from "./SocialExperience";
import { socialPath } from "@social/lib/socialPath";
import type { SocialGig, SocialTeamKind } from "@social/lib/types";
const NOTE_PROMPTS = [
"做过类似项目…",
"每周可投入…",
"作品在这里…",
"想一起做成…",
] as const;
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 filled =
Number(Boolean(draft.name.trim())) +
Number(Boolean(draft.contact.trim())) +
Number(Boolean(draft.note.trim()));
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);
}
};
if (delivery === "sent") {
return (
<div className="social-apply-done">
<span className="social-apply-done-mark" aria-hidden>
<Check size={22} strokeWidth={2.4} />
</span>
<strong>已表达兴趣</strong>
<p>{status || "对方看到后会再联系你。"}</p>
<div className="social-apply-summary">
<em>{gig.title}</em>
<span>{TEAM_KIND_LABEL[gig.kind || "parttime"]}</span>
</div>
<div className="social-actions">
<Link className="social-btn primary" href={socialPath("/chat")}>
去群里打个招呼
</Link>
<Link className="social-btn" href={socialPath("/ebook")}>
<BookOpen size={14} />
逛逛共创
</Link>
<button
type="button"
className="social-btn"
onClick={() => {
setDelivery("draft");
setStatus("可以再改一版后提交。");
}}
>
再投一份
</button>
</div>
</div>
);
}
return (
<div className="social-apply">
<div className="social-apply-hero">
<span className="social-apply-kind">
{TEAM_KIND_LABEL[gig.kind || "parttime"]}
</span>
<strong>{gig.title}</strong>
<p className="social-role-brief">{gig.role}</p>
<div className="social-tags">
<span>{gig.pay}</span>
<span>{gig.remote ? "线上也能做" : "可以见面做"}</span>
{gig.tags.slice(0, 4).map((tag) => (
<span key={tag}>{tag}</span>
))}
</div>
</div>
<div
className="social-apply-progress"
aria-label={`已填 ${filled} / 3`}
>
<span className="social-apply-progress-track">
<i style={{ width: `${(filled / 3) * 100}%` }} />
</span>
<small>
{filled === 0
? "先简单介绍自己"
: filled < 3
? `还差 ${3 - filled} 项(简介可选)`
: "可以提交了"}
</small>
</div>
<form className="social-form social-apply-form" onSubmit={(e) => void submit(e)}>
<fieldset disabled={busy} className="social-fieldset">
<label>
怎么称呼你
<input
required
maxLength={64}
autoComplete="nickname"
placeholder="昵称或真名都行"
value={draft.name}
onChange={(event) => update("name", event.target.value)}
/>
</label>
<label>
联系方式
<input
required
maxLength={120}
autoComplete="email"
placeholder="邮箱 / 微信 / Telegram…"
value={draft.contact}
onChange={(event) => update("contact", event.target.value)}
/>
</label>
<label>
你能带来什么
<textarea
rows={5}
maxLength={2000}
value={draft.note}
onChange={(event) => update("note", event.target.value)}
placeholder="相关经历、作品链接、每周能投入多久…"
/>
<span className="social-apply-prompts" aria-hidden>
{NOTE_PROMPTS.map((tip) => (
<button
key={tip}
type="button"
className="social-apply-chip"
onClick={() =>
update(
"note",
draft.note.trim()
? `${draft.note.trim()}\n${tip}`
: tip,
)
}
>
{tip}
</button>
))}
</span>
<small className="social-muted">
{draft.note.length}/2000 · 多写一点,对方更容易回你
</small>
</label>
</fieldset>
<div className="social-actions">
<button
type="submit"
className="social-btn primary"
disabled={
busy || !draft.name.trim() || !draft.contact.trim()
}
>
<Send size={14} />
{busy
? "提交中…"
: delivery === "local"
? "重试提交"
: "发送参与申请"}
</button>
</div>
{status ? (
<p
role="status"
className={`social-status${delivery === "local" ? " warn" : ""}`}
>
{status}
</p>
) : null}
<small className="social-muted">
草稿会先留在你这边。提交只是表达兴趣,不代表已经被录用。
</small>
</form>
</div>
);
}
export default function RoleBoard({
initialKind = "all",
}: {
initialKind?: SocialTeamKind | "all";
}) {
const config = useSocialConfig();
const catalog = useMemo(
() => resolveSocialCatalog(config.copy.socialCatalogs),
[config.copy.socialCatalogs],
);
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 = catalog.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 title="一起,做点事" accent="找搭子">
<div className="social-actions social-cocreate-switch">
<span className="social-btn primary" aria-current="page">
找搭子
</span>
<Link className="social-btn" href={socialPath("/ebook")}>
<BookOpen size={14} />
共创
</Link>
<DemoBadge>
{catalog.source === "remote" ? "最新机会" : "先看看这些机会"}
</DemoBadge>
<span className="social-muted">{roles.length} 个机会</span>
</div>
</PageIntro>
<p className="social-muted social-event-lead reveal">
远程也能一起推进:认领角色、写申请,草稿会先留在本机。
</p>
<div className="social-toolbar reveal">
<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 reveal">
{[["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-grid social-role-grid">
{roles.map((gig, index) => (
<article
className="social-card social-role-card social-panel-fx reveal"
key={gig.id}
style={{ ["--stagger" as string]: `${index * 70}ms` }}
>
<div className="social-role-art" aria-hidden="true">
<span>{String(index + 1).padStart(2, "0")}</span>
<i />
<i />
{gig.kind === "volunteer" ? (
<HeartHandshake size={28} strokeWidth={1.2} />
) : (
<BriefcaseBusiness size={28} strokeWidth={1.2} />
)}
</div>
<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
title="暂时没有合适的机会"
description="换个词试试,或者看看共创内容找灵感。"
>
<button
type="button"
className="social-btn"
onClick={() => {
setQuery("");
setKind("all");
setSavedOnly(false);
}}
>
重新看看
</button>
<Link className="social-btn" href={socialPath("/ebook")}>
<Sparkles size={14} />
去共创逛逛
</Link>
</EmptyState>
)}
</div>
{active && (
<SocialDialog title="表达兴趣" onClose={() => setActive(null)}>
<ApplicationForm gig={active} />
</SocialDialog>
)}
</SiteShell>
);
}