mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-17 18:29:48 +00:00
Feature: Hoarder service widget (#4913)
This commit is contained in:
parent
bea02fc8c7
commit
544b9aef2f
9 changed files with 95 additions and 0 deletions
|
@ -41,6 +41,7 @@ export default async function credentialedProxyHandler(req, res, map) {
|
|||
"cloudflared",
|
||||
"ghostfolio",
|
||||
"headscale",
|
||||
"hoarder",
|
||||
"linkwarden",
|
||||
"mealie",
|
||||
"netalertx",
|
||||
|
|
|
@ -47,6 +47,7 @@ const components = {
|
|||
grafana: dynamic(() => import("./grafana/component")),
|
||||
hdhomerun: dynamic(() => import("./hdhomerun/component")),
|
||||
headscale: dynamic(() => import("./headscale/component")),
|
||||
hoarder: dynamic(() => import("./hoarder/component")),
|
||||
peanut: dynamic(() => import("./peanut/component")),
|
||||
homeassistant: dynamic(() => import("./homeassistant/component")),
|
||||
homebox: dynamic(() => import("./homebox/component")),
|
||||
|
|
49
src/widgets/hoarder/component.jsx
Normal file
49
src/widgets/hoarder/component.jsx
Normal file
|
@ -0,0 +1,49 @@
|
|||
import { useTranslation } from "next-i18next";
|
||||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export const hoarderDefaultFields = ["bookmarks", "favorites", "archived", "highlights"];
|
||||
const MAX_ALLOWED_FIELDS = 4;
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
const { widget } = service;
|
||||
|
||||
const { data: statsData, error: statsError } = useWidgetAPI(widget, "stats");
|
||||
|
||||
if (statsError) {
|
||||
return <Container service={service} error={statsError} />;
|
||||
}
|
||||
|
||||
if (!widget.fields || widget.fields.length === 0) {
|
||||
widget.fields = hoarderDefaultFields;
|
||||
} else if (widget.fields?.length > MAX_ALLOWED_FIELDS) {
|
||||
widget.fields = widget.fields.slice(0, MAX_ALLOWED_FIELDS);
|
||||
}
|
||||
|
||||
if (!statsData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="hoarder.bookmarks" />
|
||||
<Block label="hoarder.favorites" />
|
||||
<Block label="hoarder.archived" />
|
||||
<Block label="hoarder.highlights" />
|
||||
<Block label="hoarder.lists" />
|
||||
<Block label="hoarder.tags" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="hoarder.bookmarks" value={t("common.number", { value: statsData.numBookmarks })} />
|
||||
<Block label="hoarder.favorites" value={t("common.number", { value: statsData.numFavorites })} />
|
||||
<Block label="hoarder.archived" value={t("common.number", { value: statsData.numArchived })} />
|
||||
<Block label="hoarder.highlights" value={t("common.number", { value: statsData.numHighlights })} />
|
||||
<Block label="hoarder.lists" value={t("common.number", { value: statsData.numLists })} />
|
||||
<Block label="hoarder.tags" value={t("common.number", { value: statsData.numTags })} />
|
||||
</Container>
|
||||
);
|
||||
}
|
15
src/widgets/hoarder/widget.js
Normal file
15
src/widgets/hoarder/widget.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
import { asJson } from "utils/proxy/api-helpers";
|
||||
|
||||
const widget = {
|
||||
api: `{url}/api/v1/{endpoint}`,
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
|
||||
mappings: {
|
||||
stats: {
|
||||
endpoint: "users/me/stats",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
|
@ -41,6 +41,7 @@ import gotify from "./gotify/widget";
|
|||
import grafana from "./grafana/widget";
|
||||
import hdhomerun from "./hdhomerun/widget";
|
||||
import headscale from "./headscale/widget";
|
||||
import hoarder from "./hoarder/widget";
|
||||
import homeassistant from "./homeassistant/widget";
|
||||
import homebox from "./homebox/widget";
|
||||
import homebridge from "./homebridge/widget";
|
||||
|
@ -176,6 +177,7 @@ const widgets = {
|
|||
grafana,
|
||||
hdhomerun,
|
||||
headscale,
|
||||
hoarder,
|
||||
homeassistant,
|
||||
homebox,
|
||||
homebridge,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue