Files
factorio-clusterio/plugins/inventory_sync/web/index.jsx
T
Hornwitser 808eda0513 Move base plugins to their respective packages
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.
2023-11-25 18:41:43 +01:00

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") {
}
}
}