mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-12 07:58:49 +00:00
Implement uptime-kuma widget
This commit is contained in:
parent
f517d704b8
commit
c3d15a61c3
6 changed files with 160 additions and 1 deletions
45
src/widgets/uptimekuma/component.jsx
Normal file
45
src/widgets/uptimekuma/component.jsx
Normal file
|
@ -0,0 +1,45 @@
|
|||
import { useTranslation } from "next-i18next";
|
||||
|
||||
import Container from "components/services/widget/container";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
import Block from "components/services/widget/block";
|
||||
|
||||
const Status = {
|
||||
good: "uptimekuma.good",
|
||||
warn: "uptimekuma.warn",
|
||||
bad: "uptimekuma.bad",
|
||||
unknown: "uptimekuma.unknown",
|
||||
};
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { widget } = service;
|
||||
|
||||
const { data: statusData, error: statusError } = useWidgetAPI(widget);
|
||||
|
||||
if (statusError) {
|
||||
return <Container error={statusError} />;
|
||||
}
|
||||
|
||||
if (!statusData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="uptimekuma.status"/>
|
||||
<Block label="uptimekuma.uptime"/>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
if (statusData.icon) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
service.icon = statusData.icon;
|
||||
}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="uptimekuma.status" value={statusData.incident ? statusData.incident : t(Status[statusData.message])} />
|
||||
<Block label="uptimekuma.uptime" value={t("common.number", { value: statusData.uptime, decimals: 1 })} />
|
||||
</Container>
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue