Files
factorio-clusterio/plugins/inventory_sync/web/index.jsx
T
Luciole 0b3550b472 Port remaining plugins to Typescript (#499)
* .js to .ts

* Allow access to _items entries; getItemCount return number

* add permission field to PluginPage interface

* port plugins to typescript

* update Request classes

* fix IpcFlowType
2023-08-22 16:17:16 +02:00

49 lines
1.2 KiB
React

import React, { useContext, useEffect, useState } from "react";
import * as lib from "@clusterio/lib";
import { 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 lib.BaseWebPlugin {
async init() {
this.pages = [
{
path: "/inventory",
sidebarName: "Inventory sync",
permission: "inventory_sync.inventory.view",
content: <InventoryPage />,
},
];
}
onControllerConnectionEvent(event) {
if (event === "connect") {
}
}
}