Hide membership entry, brand ebook/video as 共创, harden H5 touch layout, and align copy with everyday nomad language. Co-authored-by: Cursor <cursoragent@cursor.com>
274 lines
8.6 KiB
TypeScript
274 lines
8.6 KiB
TypeScript
"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,
|
||
DemoBadge,
|
||
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";
|
||
import { socialPath } from "@social/lib/socialPath";
|
||
|
||
type Kind = "videos" | "date" | "ebook";
|
||
const COPY = {
|
||
videos: { title: "共创 · 视频", accent: "大家拍的" },
|
||
date: { title: "共创 · 访谈", accent: "听听大家" },
|
||
ebook: { title: "共创 · 小册", accent: "大家写的" },
|
||
};
|
||
|
||
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-actions social-cocreate-switch">
|
||
<Link
|
||
className={`social-btn${books ? " primary" : ""}`}
|
||
href={socialPath("/ebook")}
|
||
>
|
||
小册
|
||
</Link>
|
||
<Link
|
||
className={`social-btn${!books && kind === "videos" ? " primary" : ""}`}
|
||
href={socialPath("/videos")}
|
||
>
|
||
视频
|
||
</Link>
|
||
<DemoBadge>
|
||
{books ? "先看看有哪些" : "有的可以看,有的先看封面"}
|
||
</DemoBadge>
|
||
</div>
|
||
</PageIntro>
|
||
<div className="social-toolbar reveal">
|
||
<SearchField
|
||
value={query}
|
||
onChange={setQuery}
|
||
placeholder={books ? "书名 / 主题" : "城市 / 关键词"}
|
||
/>
|
||
<div className="social-filters">
|
||
<button
|
||
type="button"
|
||
className={!savedOnly ? "active" : ""}
|
||
aria-pressed={!savedOnly}
|
||
onClick={() => setSavedOnly(false)}
|
||
>
|
||
全部
|
||
</button>
|
||
<button
|
||
type="button"
|
||
className={savedOnly ? "active" : ""}
|
||
aria-pressed={savedOnly}
|
||
onClick={() => setSavedOnly(true)}
|
||
>
|
||
收藏 · {saved.length}
|
||
</button>
|
||
</div>
|
||
</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 social-panel-fx reveal"
|
||
key={item.id}
|
||
style={{ ["--stagger" as string]: `${index * 70}ms` }}
|
||
>
|
||
<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>共创</small>
|
||
<BookOpen size={27} strokeWidth={1} />
|
||
<strong>{item.title}</strong>
|
||
<span>阅读</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)}
|
||
>
|
||
打开
|
||
<ArrowUpRight size={14} />
|
||
</button>
|
||
<ShareButton
|
||
path={`/social/${kind}#${item.id}`}
|
||
title={item.title}
|
||
/>
|
||
</div>
|
||
</article>
|
||
))}
|
||
{!shown.length && (
|
||
<EmptyState title="没有内容" description="换关键词或看全部。">
|
||
<button
|
||
type="button"
|
||
className="social-btn"
|
||
onClick={() => {
|
||
setQuery("");
|
||
setSavedOnly(false);
|
||
}}
|
||
>
|
||
重置筛选
|
||
</button>
|
||
</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-actions">
|
||
{books && (
|
||
<Link className="social-btn primary" href="/book">
|
||
打开书库 <BookOpen size={15} />
|
||
</Link>
|
||
)}
|
||
<Link
|
||
className={`social-btn${books ? "" : " primary"}`}
|
||
href={socialPath(
|
||
`/chat?intro=${encodeURIComponent(`看到「${active.title}」,想聊聊。`)}`,
|
||
)}
|
||
>
|
||
<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" />;
|
||
}
|