"use client"; import { ArrowDownRight, ArrowLeft, ArrowUpRight, Bell, Bookmark, CalendarDays, Check, CircleHelp, Compass, Grid2X2, Heart, House, LayoutGrid, Link2, MapPin, MessageCircle, MoreHorizontal, Play, Search, Square, UserRound, X, } from "lucide-react"; import { useEffect, useRef, useState, type ReactNode } from "react"; import { Button } from "@/components/ui/button"; import { feedNotes, notes, profile, type Note } from "@/lib/demo-data"; import { cn } from "@/lib/utils"; const channels = ["推荐", "旅行", "游戏", "视频", "职场", "情感"]; const profileTabs = ["笔记", "收藏", "点赞", "浏览记录"] as const; const ownedNotes = ["workspace", "ai-tools", "voxel-model"]; const accounts = [ { name: "极客小分队", handle: "@geek_squad_cn", initials: "极" }, { name: "Low Quality Memes", handle: "@ipostlqmemes", initials: "LM" }, ]; const count = new Intl.NumberFormat("zh-CN"); const columns = [ { value: 1, icon: Square }, { value: 2, icon: Grid2X2 }, { value: 3, icon: LayoutGrid }, ] as const; function Picture({ src, alt, className }: { src: string; alt: string; className?: string }) { // The prototype supplies remote image URLs with no fixed source dimensions. // eslint-disable-next-line @next/next/no-img-element return {alt}; } function Card({ note, liked, onLike, onOpen, pinned, }: { note: Note; liked: boolean; onLike: () => void; onOpen: () => void; pinned?: boolean; }) { const likes = note.likes + Number(liked) - Number(note.initiallyLiked); return (
{note.author}
); } type ProfileTab = (typeof profileTabs)[number]; type DialogContent = | { type: "note"; note: Note } | { type: "about" } | { type: "topics" } | { type: "notifications" } | { type: "messages" }; export function Bedrock() { const [view, setView] = useState<"home" | "profile">("home"); const [feed, setFeed] = useState<"all" | "following">("all"); const [channel, setChannel] = useState("推荐"); const [columnCount, setColumnCount] = useState<1 | 2 | 3>(); const [compact, setCompact] = useState(false); const activeColumns = columnCount ?? (compact ? 2 : 3); const [query, setQuery] = useState(""); const [tab, setTab] = useState("笔记"); const [liked, setLiked] = useState(() => notes.filter((note) => note.initiallyLiked).map((note) => note.id)); const [saved, setSaved] = useState(["stairs"]); const [history, setHistory] = useState([]); const [follows, setFollows] = useState([]); const [dialogContent, setDialogContent] = useState(null); const [notice, setNotice] = useState(""); const dialog = useRef(null); const search = useRef(null); const menu = useRef(null); const normalizedQuery = query.trim().toLowerCase(); useEffect(() => { function openLinkedProfile() { setView(window.location.hash === "#" + profile.handle ? "profile" : "home"); } const viewport = window.matchMedia("(max-width: 720px)"); const syncViewport = () => setCompact(viewport.matches); openLinkedProfile(); syncViewport(); window.addEventListener("hashchange", openLinkedProfile); viewport.addEventListener("change", syncViewport); return () => { window.removeEventListener("hashchange", openLinkedProfile); viewport.removeEventListener("change", syncViewport); }; }, []); function changeView(next: "home" | "profile") { setView(next); const url = new URL(window.location.href); url.hash = next === "profile" ? profile.handle : ""; window.history.replaceState(window.history.state, "", url); window.scrollTo(0, 0); } function browse(next = "推荐") { setFeed("all"); setChannel(next); setQuery(""); changeView("home"); } function toggleInList(set: (update: (current: string[]) => string[]) => void, id: string) { set((current) => current.includes(id) ? current.filter((entry) => entry !== id) : [...current, id]); } function show(content: DialogContent) { setDialogContent(content); dialog.current?.showModal(); } function openNote(note: Note) { setHistory((current) => [note.id, ...current.filter((id) => id !== note.id)]); show({ type: "note", note }); } async function copyProfile() { menu.current?.removeAttribute("open"); const url = new URL(window.location.pathname, window.location.href); url.hash = profile.handle; try { await navigator.clipboard.writeText(url.href); setNotice("已复制主页链接"); } catch { setNotice(url.href); } } const following = follows.includes(profile.handle); const matches = feedNotes.filter((note) => (feed === "all" || note.following || (following && note.author === profile.name)) && (channel === "推荐" || note.category === channel) && (!normalizedQuery || [note.title, note.author, note.category].some((value) => value.toLowerCase().includes(normalizedQuery))), ); const profileIds = { 笔记: ownedNotes, 收藏: saved, 点赞: liked, 浏览记录: history }[tab]; const profileNotes = profileIds.flatMap((id) => notes.find((note) => note.id === id) ?? []); function renderCard(note: Note, pinned = false) { return toggleInList(setLiked, note.id)} onOpen={() => openNote(note)} />; } function followButton(id: string, className?: string) { const active = follows.includes(id); return ; } function closeMenuAndShow(content: DialogContent) { menu.current?.removeAttribute("open"); show(content); } let modal: ReactNode; if (dialogContent?.type === "note") { const { note } = dialogContent; modal = <>

{note.category} · {note.author}

{note.title}

{note.video &&

示例笔记仅提供视频封面。

}
; } else if (dialogContent?.type === "about") { modal = <>

关于此账号

{profile.name} · @{profile.handle}

加入时间
2022 年 4 月
账号属地
中国 · 四川
认证时间
2024 年 3 月
; } else if (dialogContent?.type === "topics") { modal = <>

关注的话题

{["游戏", "视频", "职场"].map((topic) => , )}
; } else if (dialogContent) { const label = dialogContent.type === "messages" ? "消息" : "通知"; modal = <>

{label}

暂无{label}

; } return (
{ if (notice) setNotice(""); }}>
{ event.preventDefault(); changeView("home"); }}>
{view === "home" ? <>

发现

{channels.map((item) => )}
{columns.map(({ value, icon: Icon }) => )}
{matches.length ?
{matches.map((note) => renderCard(note))}
:

没有符合条件的笔记。

} : <>
个人主页
{followButton(profile.handle)}

{profile.name}

@{profile.handle} · 小红书号 {profile.account}

Software is eating the world, AI is eating software. 分享 AI 产品拆解、独立开发实验与数字生活灵感。

成都 · 四川
128 笔记10 关注{87 + Number(following)} 粉丝2,987 获赞与收藏
{profileNotes.length ?
{profileNotes.map((note) => renderCard(note, tab === "笔记" && note.id === "workspace"))}
:

{tab === "浏览记录" ? "近期浏览的笔记会显示在这里,仅自己可见。" : "这里暂时没有笔记。"}

} }
{ if (event.target === event.currentTarget) dialog.current?.close(); }}>
{modal}

{notice}

); }