mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-29 23:41:16 -07:00
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com> Signed-off-by: dependabot[bot] <support@github.com>
48 lines
1.4 KiB
React
48 lines
1.4 KiB
React
import { useEffect, useState } from "react";
|
|
|
|
import Block from "components/services/widget/block";
|
|
import Container from "components/services/widget/container";
|
|
import { formatProxyUrl } from "utils/proxy/api-helpers";
|
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
|
|
|
export default function Component({ service }) {
|
|
const { widget } = service;
|
|
|
|
const { data: workersData, error: workersError } = useWidgetAPI(widget, "workers");
|
|
|
|
const [pendingData, setPendingData] = useState(null);
|
|
|
|
useEffect(() => {
|
|
async function fetchPending() {
|
|
const url = formatProxyUrl(widget, "pending");
|
|
const res = await fetch(url, { method: "POST" });
|
|
setPendingData(await res.json());
|
|
}
|
|
if (!pendingData) {
|
|
fetchPending();
|
|
}
|
|
}, [widget, pendingData]);
|
|
|
|
if (workersError) {
|
|
return <Container service={service} error={workersError} />;
|
|
}
|
|
|
|
if (!workersData || !pendingData) {
|
|
return (
|
|
<Container service={service}>
|
|
<Block label="unmanic.active_workers" />
|
|
<Block label="unmanic.total_workers" />
|
|
<Block label="unmanic.records_total" />
|
|
</Container>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Container service={service}>
|
|
<Block label="unmanic.active_workers" value={workersData.active_workers} />
|
|
<Block label="unmanic.total_workers" value={workersData.total_workers} />
|
|
<Block label="unmanic.records_total" value={pendingData.recordsTotal} />
|
|
</Container>
|
|
);
|
|
}
|