mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-17 10:19:49 +00:00
widget refactoring
This commit is contained in:
parent
03fa2f86d7
commit
035dd25ece
29 changed files with 851 additions and 10 deletions
43
src/widgets/strelaysrv/component.jsx
Normal file
43
src/widgets/strelaysrv/component.jsx
Normal file
|
@ -0,0 +1,43 @@
|
|||
import useSWR from "swr";
|
||||
import { useTranslation } from "next-i18next";
|
||||
|
||||
import Widget from "components/services/widgets/widget";
|
||||
import Block from "components/services/widgets/block";
|
||||
import { formatProxyUrl } from "utils/api-helpers";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const config = service.widget;
|
||||
|
||||
const { data: statsData, error: statsError } = useSWR(formatProxyUrl(config, `status`));
|
||||
|
||||
if (statsError) {
|
||||
return <Widget error={t("widget.api_error")} />;
|
||||
}
|
||||
|
||||
if (!statsData) {
|
||||
return (
|
||||
<Widget>
|
||||
<Block label={t("strelaysrv.numActiveSessions")} />
|
||||
<Block label={t("strelaysrv.numConnections")} />
|
||||
<Block label={t("strelaysrv.bytesProxied")} />
|
||||
</Widget>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Widget>
|
||||
<Block
|
||||
label={t("strelaysrv.numActiveSessions")}
|
||||
value={t("common.number", { value: statsData.numActiveSessions })}
|
||||
/>
|
||||
<Block label={t("strelaysrv.numConnections")} value={t("common.number", { value: statsData.numConnections })} />
|
||||
<Block label={t("strelaysrv.dataRelayed")} value={t("common.bytes", { value: statsData.bytesProxied })} />
|
||||
<Block
|
||||
label={t("strelaysrv.transferRate")}
|
||||
value={t("common.bitrate", { value: statsData.kbps10s1m5m15m30m60m[5] })}
|
||||
/>
|
||||
</Widget>
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue