mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-15 00:24:52 +09:00
Same changes the other packages got in #475 and #476. The permissions move from definePermission calls into the plugin declaration, with the Permissions augmentation in messages.ts so the web build sees it. "type": "module", .js entrypoints and imports, webpack.config.cjs, and the tap tests use import with --type-strip-only. The web plugin now uses a default export function instead of the deprecated BaseWebPlugin class, like exp_roles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
860 B
TypeScript
28 lines
860 B
TypeScript
import React, { useCallback, useSyncExternalStore } from "react";
|
|
import { WebPluginContext } from "@clusterio/web_ui";
|
|
|
|
import * as lib from "@clusterio/lib";
|
|
import * as messages from "../messages.js";
|
|
|
|
import ReportsPage from "./components/ReportsPage";
|
|
|
|
let reports: lib.MapSubscriber<messages.ReportUpdatedEvent> | undefined;
|
|
|
|
export function useReports() {
|
|
const subscribe = useCallback((cb: () => void) => reports!.subscribe(cb), []);
|
|
return useSyncExternalStore(subscribe, () => reports!.getSnapshot());
|
|
}
|
|
|
|
export default function registerPlugin(context: WebPluginContext) {
|
|
context.control.hooks.pages.attach("exp_reports", () => [
|
|
{
|
|
path: "/reports",
|
|
sidebarName: "Reports",
|
|
permission: "exp_reports.report.list",
|
|
content: <ReportsPage />,
|
|
},
|
|
]);
|
|
|
|
reports = new lib.MapSubscriber(messages.ReportUpdatedEvent, context.control);
|
|
}
|