From 260201c2b40a27dc0ff782d315552c4a0217f0b5 Mon Sep 17 00:00:00 2001 From: Jason Fischer Date: Sun, 9 Oct 2022 20:05:28 -0700 Subject: [PATCH] Decompose i18n labels for Unifi widget - Needed to decompose i18n labels for Unifi widget in order for field visibility setting to work correctly - Fixed weird edge case where a call to cached-fetch would fail if no duration was passed - Have VS Code hide the .next and node_modules folders from tree view --- .vscode/settings.json | 6 ++++++ public/locales/en/common.json | 4 ++-- src/utils/proxy/cached-fetch.js | 5 +++++ src/widgets/unifi/component.jsx | 13 +++++-------- 4 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..5a9e97f16 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.exclude": { + "**/.next": true, + "**/node_modules": true + } +} \ No newline at end of file diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 669ebd276..b1097904d 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -36,8 +36,8 @@ "uptime": "System Uptime", "days": "Days", "wan": "WAN", - "lan": "LAN", - "wlan": "WLAN", + "lan_users": "LAN Users", + "wlan_users": "WLAN Users", "up": "UP", "down": "DOWN", "wait": "Please wait" diff --git a/src/utils/proxy/cached-fetch.js b/src/utils/proxy/cached-fetch.js index 22eba37f2..0ed39562f 100644 --- a/src/utils/proxy/cached-fetch.js +++ b/src/utils/proxy/cached-fetch.js @@ -1,8 +1,13 @@ import cache from "memory-cache"; +const defaultDuration = 5; + export default async function cachedFetch(url, duration) { const cached = cache.get(url); + // eslint-disable-next-line no-param-reassign + duration = duration || defaultDuration; + if (cached) { return cached; } diff --git a/src/widgets/unifi/component.jsx b/src/widgets/unifi/component.jsx index 8a654a516..e2db8e77f 100644 --- a/src/widgets/unifi/component.jsx +++ b/src/widgets/unifi/component.jsx @@ -15,9 +15,6 @@ export default function Component({ service }) { return ; } - const wlanLabel = `${t("unifi.wlan")} ${t("unifi.users")}` - const lanLabel = `${t("unifi.lan")} ${t("unifi.users")}` - const defaultSite = statsData?.data?.find(s => s.name === "default"); if (!defaultSite) { @@ -25,8 +22,8 @@ export default function Component({ service }) { - - + + ); } @@ -45,7 +42,7 @@ export default function Component({ service }) { lan: { users: lan.num_user, status: lan.status - } + }, }; const uptime = `${t("common.number", { value: data.uptime / 86400, maximumFractionDigits: 1 })} ${t("unifi.days")}`; @@ -54,8 +51,8 @@ export default function Component({ service }) { - - + + ); }