mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-18 10:39:49 +00:00
refactor service widgets
This commit is contained in:
parent
7807a38a9c
commit
94e9d66bec
19 changed files with 382 additions and 502 deletions
41
src/components/services/widgets/service/radarr.jsx
Normal file
41
src/components/services/widgets/service/radarr.jsx
Normal file
|
@ -0,0 +1,41 @@
|
|||
import useSWR from "swr";
|
||||
|
||||
import Widget from "../widget";
|
||||
import Block from "../block";
|
||||
|
||||
export default function Radarr({ service }) {
|
||||
const config = service.widget;
|
||||
|
||||
function buildApiUrl(endpoint) {
|
||||
const { url, key } = config;
|
||||
return `${url}/api/v3/${endpoint}?apikey=${key}`;
|
||||
}
|
||||
|
||||
const { data: moviesData, error: moviesError } = useSWR(buildApiUrl("movie"));
|
||||
const { data: queuedData, error: queuedError } = useSWR(buildApiUrl("queue/status"));
|
||||
|
||||
if (moviesError || queuedError) {
|
||||
return <Widget error="Radarr API Error" />;
|
||||
}
|
||||
|
||||
if (!moviesData || !queuedData) {
|
||||
return (
|
||||
<Widget>
|
||||
<Block label="Wanted" />
|
||||
<Block label="Queued" />
|
||||
<Block label="Movies" />
|
||||
</Widget>
|
||||
);
|
||||
}
|
||||
|
||||
const wanted = moviesData.filter((movie) => movie.isAvailable === false);
|
||||
const have = moviesData.filter((movie) => movie.isAvailable === true);
|
||||
|
||||
return (
|
||||
<Widget>
|
||||
<Block label="Wanted" value={wanted.length} />
|
||||
<Block label="Queued" value={queuedData.totalCount} />
|
||||
<Block label="Movies" value={moviesData.length} />
|
||||
</Widget>
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue