import { useEffect, useState } from "react"; import { Boxes, Search, PlusCircle, Code2, KeyRound, Headset } from "lucide-react"; import Home from "./components/Home"; import ProductView from "./components/ProductView"; import Contribute from "./components/Contribute"; import ApiDocs from "./components/ApiDocs"; import Account from "./components/Account"; import Contact from "./components/Contact"; import { api } from "./api"; type View = | { name: "home" } | { name: "product"; id: string } | { name: "contribute" } | { name: "api" } | { name: "account" } | { name: "contact" }; const NAV: { key: View["name"]; label: string; icon: typeof Search }[] = [ { key: "home", label: "检索", icon: Search }, { key: "contribute", label: "贡献档案", icon: PlusCircle }, { key: "api", label: "API", icon: Code2 }, { key: "account", label: "API 密钥", icon: KeyRound }, { key: "contact", label: "联系我们", icon: Headset }, ]; export default function App() { const [view, setView] = useState({ name: "home" }); const [qualified, setQualified] = useState(null); useEffect(() => { api .stats() .then((s) => setQualified(s.qualified)) .catch(() => setQualified(null)); }, []); return (
{view.name === "home" && ( setView({ name: "product", id })} onContribute={() => setView({ name: "contribute" })} /> )} {view.name === "product" && ( setView({ name: "home" })} /> )} {view.name === "contribute" && ( setView({ name: "home" })} /> )} {view.name === "api" && setView({ name: "account" })} />} {view.name === "account" && } {view.name === "contact" && }
); }