From c92d1caf801d3132625f5b47488d0a363bd57cb0 Mon Sep 17 00:00:00 2001
From: shamoon <4887959+shamoon@users.noreply.github.com>
Date: Wed, 7 Jun 2023 13:37:38 -0700
Subject: [PATCH] Allow useWidgetAPI to not actually send a request
---
src/utils/proxy/use-widget-api.js | 6 +++++-
src/widgets/lidarr/component.jsx | 8 +++++---
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/utils/proxy/use-widget-api.js b/src/utils/proxy/use-widget-api.js
index 52e986e1b..e4744038e 100644
--- a/src/utils/proxy/use-widget-api.js
+++ b/src/utils/proxy/use-widget-api.js
@@ -7,7 +7,11 @@ export default function useWidgetAPI(widget, ...options) {
if (options && options[1]?.refreshInterval) {
config.refreshInterval = options[1].refreshInterval;
}
- const { data, error, mutate } = useSWR(formatProxyUrl(widget, ...options), config);
+ let url = formatProxyUrl(widget, ...options)
+ if (options[0] === "") {
+ url = null
+ }
+ const { data, error, mutate } = useSWR(url, config);
// make the data error the top-level error
return { data, error: data?.error ?? error, mutate }
}
diff --git a/src/widgets/lidarr/component.jsx b/src/widgets/lidarr/component.jsx
index a6aa82c7f..77d831f84 100644
--- a/src/widgets/lidarr/component.jsx
+++ b/src/widgets/lidarr/component.jsx
@@ -9,7 +9,9 @@ export default function Component({ service }) {
const { widget } = service;
- const { data: albumsData, error: albumsError } = useWidgetAPI(widget, "album");
+ // album API endpoint can get massive, so we prevent calling if not included in fields see https://github.com/benphelps/homepage/discussions/1577
+ const showAlbums = widget.fields?.includes('albums') || !widget.fields;
+ const { data: albumsData, error: albumsError } = useWidgetAPI(widget, showAlbums ? "album" : "");
const { data: wantedData, error: wantedError } = useWidgetAPI(widget, "wanted/missing");
const { data: queueData, error: queueError } = useWidgetAPI(widget, "queue/status");
@@ -18,7 +20,7 @@ export default function Component({ service }) {
return ;
}
- if (!albumsData || !wantedData || !queueData) {
+ if ((showAlbums && !albumsData) || !wantedData || !queueData) {
return (
@@ -32,7 +34,7 @@ export default function Component({ service }) {
-
+ {showAlbums && }
);
}