Secondary-dev Next UI with DnD, labels, stopwatch, archive, activity; pads with revisions; README documents pnpm dev:work-api. Co-authored-by: Cursor <cursoragent@cursor.com>
112 lines
2.9 KiB
TypeScript
112 lines
2.9 KiB
TypeScript
"use client";
|
||
|
||
/**
|
||
* Next.js host for forked Planka client (vendor).
|
||
* Single React tree — Planka Root as child (no iframe / second createRoot).
|
||
*/
|
||
import Link from "next/link";
|
||
import {
|
||
Component,
|
||
type ComponentType,
|
||
type ErrorInfo,
|
||
type ReactNode,
|
||
useEffect,
|
||
useState,
|
||
} from "react";
|
||
import { socialPath } from "@social/lib/socialPath";
|
||
import "./nomadro-planka.css";
|
||
import "./shell.css";
|
||
|
||
type RootProps = {
|
||
store: unknown;
|
||
history: unknown;
|
||
};
|
||
|
||
type Bundle = {
|
||
Root: ComponentType<RootProps>;
|
||
store: unknown;
|
||
history: unknown;
|
||
};
|
||
|
||
class PlankaErrorBoundary extends Component<
|
||
{ children: ReactNode },
|
||
{ error: string }
|
||
> {
|
||
state = { error: "" };
|
||
static getDerivedStateFromError(error: Error) {
|
||
return { error: error.message || String(error) };
|
||
}
|
||
componentDidCatch(error: Error, info: ErrorInfo) {
|
||
console.error("[planka-next]", error, info);
|
||
}
|
||
render() {
|
||
if (this.state.error) {
|
||
return (
|
||
<div className="planka-next-err" role="alert">
|
||
<p>Planka 渲染错误:{this.state.error}</p>
|
||
</div>
|
||
);
|
||
}
|
||
return this.props.children;
|
||
}
|
||
}
|
||
|
||
export default function PlankaNextRoot() {
|
||
const [bundle, setBundle] = useState<Bundle | null>(null);
|
||
const [err, setErr] = useState("");
|
||
|
||
useEffect(() => {
|
||
let cancelled = false;
|
||
(async () => {
|
||
try {
|
||
const [{ default: store }, { default: history }, { default: Root }] =
|
||
await Promise.all([
|
||
import("../vendor/store.js"),
|
||
import("../vendor/history.js"),
|
||
import("../vendor/components/common/Root.jsx"),
|
||
]);
|
||
await import("../vendor/i18n.js");
|
||
if (!cancelled) {
|
||
setBundle({ Root, store, history });
|
||
}
|
||
} catch (e) {
|
||
console.error("[planka-next] load", e);
|
||
if (!cancelled) setErr(e instanceof Error ? e.message : String(e));
|
||
}
|
||
})();
|
||
return () => {
|
||
cancelled = true;
|
||
};
|
||
}, []);
|
||
|
||
const Root = bundle?.Root;
|
||
|
||
return (
|
||
<div className="planka-next-shell">
|
||
<header className="planka-next-bar">
|
||
<Link href={socialPath("/work")}>← 远程工作</Link>
|
||
<strong>看板协作</strong>
|
||
<span className={`dot ${bundle ? "on" : ""}`} />
|
||
</header>
|
||
{err ? (
|
||
<div className="planka-next-err" role="alert">
|
||
<p>Planka Next 加载失败:{err}</p>
|
||
<p>
|
||
先 <code>pnpm work:sync-ui && pnpm work:patch-ui</code>,并保证{" "}
|
||
<code>/work-api</code> 代理到 Planka 服务端。
|
||
</p>
|
||
</div>
|
||
) : null}
|
||
<div id="planka-next-root" className="planka-next-body">
|
||
<PlankaErrorBoundary>
|
||
{Root && bundle ? (
|
||
<Root store={bundle.store} history={bundle.history} />
|
||
) : !err ? (
|
||
<div className="planka-next-loading">正在装载 Planka 前端源码…</div>
|
||
) : null}
|
||
</PlankaErrorBoundary>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|