"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { LandingNav } from "@/components/landing/LandingNav"; import { LandingFooter } from "@/components/landing/LandingFooter"; import type { DocsLang } from "@/lib/i18n"; import { DBX_STORE_CONTRIBUTING_URL, fetchPluginCatalog, latestPluginVersion, pluginDisplayDescription, pluginDisplayName, type MarketplacePlugin, } from "@/lib/pluginCatalog"; const i18n = { en: { title: "Plugin Center", viewPlugin: "View plugin", refreshError: "Could not refresh the catalog; showing the last snapshot.", submitTitle: "Built a plugin for DBX?", submitDesc: "Package it as a .dbxp, submit a PR to dbx-store, and it will appear here and in the in-app plugin center after review.", submitAction: "Submit to dbx-store", submitDocs: "Plugin development docs", emptyTitle: "No plugins yet", emptyDesc: "The marketplace catalog is empty or unreachable right now. Try again in a moment.", }, cn: { title: "插件中心", viewPlugin: "查看插件", refreshError: "目录刷新失败,当前展示构建时的快照。", submitTitle: "为 DBX 开发了插件?", submitDesc: "打包为 .dbxp,向 dbx-store 提交 PR,审核通过后会同时出现在本页面和客户端插件中心。", submitAction: "提交到 dbx-store", submitDocs: "插件开发文档", emptyTitle: "暂无插件", emptyDesc: "商店目录暂时为空或无法访问,请稍后再试。", }, }; function mergePlugins(snapshot: MarketplacePlugin[], live: MarketplacePlugin[]): MarketplacePlugin[] { if (!snapshot.length) return live; const byId = new Map(snapshot.map((plugin) => [plugin.id, plugin])); for (const plugin of live) byId.set(plugin.id, plugin); return [...byId.values()]; } export function PluginsClient({ lang, initialPlugins }: { lang: DocsLang; initialPlugins: MarketplacePlugin[] }) { const [plugins, setPlugins] = useState(initialPlugins); const [refreshFailed, setRefreshFailed] = useState(false); const t = i18n[lang]; useEffect(() => { let cancelled = false; fetchPluginCatalog({ cache: "no-cache" }) .then((catalog) => { if (cancelled) return; if (catalog) setPlugins((current) => mergePlugins(current, catalog.plugins)); else setRefreshFailed(true); }) .catch(() => { if (!cancelled) setRefreshFailed(true); }); return () => { cancelled = true; }; }, []); return (

{t.title}

{refreshFailed &&

{t.refreshError}

} {plugins.length === 0 ? (

{t.emptyTitle}

{t.emptyDesc}

) : (
{plugins.map((plugin) => { const latest = latestPluginVersion(plugin); return (
{/* Stretched link: the whole card navigates; interactive children sit above it. */}
{plugin.icon ? ( // eslint-disable-next-line @next/next/no-img-element ) : null}

{pluginDisplayName(plugin, lang)}

{latest ? v{latest.version} : null}

{plugin.publisher} {plugin.license ? ` · ${plugin.license}` : ""}

{pluginDisplayDescription(plugin, lang)}

{(plugin.tags ?? []).slice(0, 5).map((tag) => ( {tag} ))}
); })}
)}

{t.submitTitle}

{t.submitDesc}

{t.submitAction} {t.submitDocs}
); }