mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-09 14:58:47 +00:00
starting of widget refactoring
This commit is contained in:
parent
d6f6ea9dba
commit
562235f828
42 changed files with 337 additions and 301 deletions
8
src/widgets/components.js
Normal file
8
src/widgets/components.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
import dynamic from "next/dynamic";
|
||||
|
||||
const components = {
|
||||
overseerr: dynamic(() => import("./overseerr/component")),
|
||||
radarr: dynamic(() => import("./radarr/component")),
|
||||
};
|
||||
|
||||
export default components;
|
36
src/widgets/overseerr/component.jsx
Normal file
36
src/widgets/overseerr/component.jsx
Normal file
|
@ -0,0 +1,36 @@
|
|||
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, "request/count"));
|
||||
|
||||
if (statsError) {
|
||||
return <Widget error={t("widget.api_error")} />;
|
||||
}
|
||||
|
||||
if (!statsData) {
|
||||
return (
|
||||
<Widget>
|
||||
<Block label={t("overseerr.pending")} />
|
||||
<Block label={t("overseerr.approved")} />
|
||||
<Block label={t("overseerr.available")} />
|
||||
</Widget>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Widget>
|
||||
<Block label={t("overseerr.pending")} value={statsData.pending} />
|
||||
<Block label={t("overseerr.approved")} value={statsData.approved} />
|
||||
<Block label={t("overseerr.available")} value={statsData.available} />
|
||||
</Widget>
|
||||
);
|
||||
}
|
14
src/widgets/overseerr/widget.js
Normal file
14
src/widgets/overseerr/widget.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
import credentialedProxyHandler from "utils/proxies/credentialed";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/api/v1/{endpoint}",
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
|
||||
mappings: {
|
||||
"request/count": {
|
||||
endpoint: "request/count",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
37
src/widgets/radarr/component.jsx
Normal file
37
src/widgets/radarr/component.jsx
Normal file
|
@ -0,0 +1,37 @@
|
|||
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: moviesData, error: moviesError } = useSWR(formatProxyUrl(config, "movie"));
|
||||
const { data: queuedData, error: queuedError } = useSWR(formatProxyUrl(config, "queue/status"));
|
||||
|
||||
if (moviesError || queuedError) {
|
||||
return <Widget error={t("widget.api_error")} />;
|
||||
}
|
||||
|
||||
if (!moviesData || !queuedData) {
|
||||
return (
|
||||
<Widget>
|
||||
<Block label={t("radarr.wanted")} />
|
||||
<Block label={t("radarr.queued")} />
|
||||
<Block label={t("radarr.movies")} />
|
||||
</Widget>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Widget>
|
||||
<Block label={t("radarr.wanted")} value={moviesData.wanted} />
|
||||
<Block label={t("radarr.queued")} value={queuedData.totalCount} />
|
||||
<Block label={t("radarr.movies")} value={moviesData.have} />
|
||||
</Widget>
|
||||
);
|
||||
}
|
22
src/widgets/radarr/widget.js
Normal file
22
src/widgets/radarr/widget.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
import genericProxyHandler from "utils/proxies/generic";
|
||||
import { jsonArrayFilter } from "utils/api-helpers";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/api/v3/{endpoint}?apikey={key}",
|
||||
proxyHandler: genericProxyHandler,
|
||||
|
||||
mappings: {
|
||||
movie: {
|
||||
endpoint: "movie",
|
||||
map: (data) => ({
|
||||
wanted: jsonArrayFilter(data, (item) => item.isAvailable === false).length,
|
||||
have: jsonArrayFilter(data, (item) => item.isAvailable === true).length,
|
||||
}),
|
||||
},
|
||||
"queue/status": {
|
||||
endpoint: "queue/status",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
9
src/widgets/widgets.js
Normal file
9
src/widgets/widgets.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
import overseerr from "./overseerr/widget";
|
||||
import radarr from "./radarr/widget";
|
||||
|
||||
const widgets = {
|
||||
overseerr,
|
||||
radarr,
|
||||
};
|
||||
|
||||
export default widgets;
|
Loading…
Add table
Add a link
Reference in a new issue