mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 07:04:53 +09:00
Move BaseControllerPlugin to controller/src/BaseControllerPlugin.ts Move BaseInstancePlugin to host/src/BaseInstancePlugin.ts Move BaseControlPlugin to ctl/src/BaseCtlPlugin.ts Move BaseWebPlugin to web_ui/src/BaseWebPlugin.ts This solves the circular package dependency problem of the base plugins needing types that are available only in the dependencies to lib.
48 lines
1.1 KiB
React
48 lines
1.1 KiB
React
import React, { useContext, useEffect, useState } from "react";
|
|
|
|
import { BaseWebPlugin, PageLayout, ControlContext } from "@clusterio/web_ui";
|
|
import { DatabaseStatsRequest } from "../dist/plugin/messages";
|
|
|
|
import "./index.css";
|
|
|
|
function InventoryPage() {
|
|
let control = useContext(ControlContext);
|
|
|
|
let [statsData, updateStatsData] = useState();
|
|
|
|
useEffect(() => {
|
|
(async () => {
|
|
// Get statistics
|
|
updateStatsData(await control.send(new DatabaseStatsRequest()));
|
|
})();
|
|
}, []);
|
|
|
|
return <PageLayout nav={[{ name: "Inventory sync" }]}>
|
|
<h2>Inventory sync</h2>
|
|
{statsData && <>
|
|
<p>Database size: {Math.round(statsData.databaseSize / 1000)}kB</p>
|
|
<p>Database entries: {statsData.databaseEntries}</p>
|
|
<p>Largest entry is {statsData.largestEntry.name} with {(statsData.largestEntry.size / 1000)}kB</p>
|
|
</>}
|
|
</PageLayout>;
|
|
}
|
|
|
|
export class WebPlugin extends BaseWebPlugin {
|
|
async init() {
|
|
this.pages = [
|
|
{
|
|
path: "/inventory",
|
|
sidebarName: "Inventory sync",
|
|
permission: "inventory_sync.inventory.view",
|
|
content: <InventoryPage />,
|
|
},
|
|
];
|
|
}
|
|
|
|
onControllerConnectionEvent(event) {
|
|
if (event === "connect") {
|
|
|
|
}
|
|
}
|
|
}
|