import a from "@/styles/account.module.css"; import { ThemeToggle } from "./ThemeToggle"; import { Brand } from "./Brand"; import Head from "next/head"; import Link from "next/link"; import { useRouter } from "next/router"; import { createContext, useCallback, useContext, useEffect, useRef, useState, type ReactNode, } from "react"; import { ArrowUpRight, BookOpen, Bot, ChevronRight, Compass, Files, Globe2, LogIn, Menu, Plus, SquarePen, UserRound, Waypoints, X, } from "lucide-react"; import s from "@/styles/guidance.module.css"; export type AccountUser = { id: string; email: string; verified_at: string }; type AccountState = { user: AccountUser | null; loading: boolean; error: string; refresh: () => Promise; }; const AccountContext = createContext({ user: null, loading: true, error: "", refresh: async () => {}, }); export const useGuidanceAccount = () => useContext(AccountContext); export default function GuidanceShell({ children, title = "探索文档", standalone = false, }: { children: ReactNode; title?: string; standalone?: boolean; }) { const router = useRouter(); const dialog = useRef(null); const [user, setUser] = useState(null), [loading, setLoading] = useState(true), [error, setError] = useState(""); const refresh = useCallback(async () => { setLoading(true); setError(""); try { const r = await fetch("/api/account/session"); const b = await r.json(); if (!r.ok) throw Error(b.error || "账户暂时不可用"); setUser(b.user || null); } catch (e) { setError(e instanceof Error ? e.message : "账户暂时不可用"); } finally { setLoading(false); } }, []); useEffect(() => { void refresh(); }, [refresh]); useEffect(() => { dialog.current?.close(); }, [router.pathname, router.query.scope]); const mine = router.query.scope === "mine"; const nav = [ { href: "/", label: "探索文档", Icon: Compass, active: router.pathname === "/" || router.pathname.startsWith("/guide/"), }, { href: "/documents", label: "社区文档", Icon: Files, active: router.pathname.startsWith("/documents") && !mine, }, { href: "/documents?scope=mine", label: "我的文档", Icon: BookOpen, active: router.pathname === "/documents" && mine, }, { href: "/write", label: "发布文档", Icon: SquarePen, active: router.pathname === "/write", }, ]; function navigation(mobile = false) { return ( <> dialog.current?.close()} >
公共知识空间 Public

工作空间

资源

从一篇文档开始

选择适用的指导,需要更多背景时,再沿链接继续阅读。

了解使用方法
{user ? ( user.email.slice(0, 1).toUpperCase() ) : ( )} {user ? user.email : loading ? "正在检查账户…" : "登录你的账户"} {user ? "管理与发布你的文档" : "邮箱登录 · 开始发布"}
); } if (standalone) return (
{`${title} · 啡跃`} 跳到正文
返回首页
{children}
); return (
{`${title} · 啡跃`} 跳到正文 {navigation(true)}
工作空间 {title}
Linked Guidance 0.1 {router.pathname !== "/write" && ( 创建文档 )} {!user && !loading && ( 登录 )}
{children}
); }