From 1200e8ff70f2599fbf55051e3c76814e04d2c922 Mon Sep 17 00:00:00 2001 From: 3252a8 <3252a8@proton.me> Date: Fri, 5 Jun 2026 15:45:57 +0300 Subject: [PATCH] fix: prevent devices limit flicker --- frontend/src/lib/webapp/devicesLabels.js | 17 +++-- .../src/webapp/screens/DevicesScreen.svelte | 11 +++- tests/test_webapp_devices_labels.py | 65 +++++++++++++++++++ 3 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 tests/test_webapp_devices_labels.py diff --git a/frontend/src/lib/webapp/devicesLabels.js b/frontend/src/lib/webapp/devicesLabels.js index ab8894e..4906757 100644 --- a/frontend/src/lib/webapp/devicesLabels.js +++ b/frontend/src/lib/webapp/devicesLabels.js @@ -6,19 +6,28 @@ */ export function devicesLimitLabel(devicesData, t, maxDevicesOverride) { const value = maxDevicesOverride !== undefined ? maxDevicesOverride : devicesData?.max_devices; + if (value === undefined || value === null || value === "") { + return t("wa_devices_limit_pending", {}, "..."); + } const numeric = Number(value ?? 0); if (!Number.isFinite(numeric) || numeric <= 0) return t("wa_devices_unlimited"); return String(Math.trunc(numeric)); } -export function devicesCountLabel(devicesData, t) { +export function devicesCountLabel(devicesData, t, maxDevicesOverride) { const current = Number(devicesData?.current_devices ?? devicesData?.devices?.length ?? 0); - return t("wa_devices_count", { current, max: devicesLimitLabel(devicesData, t) }); + return t("wa_devices_count", { + current, + max: devicesLimitLabel(devicesData, t, maxDevicesOverride), + }); } -export function devicesPercent(devicesData) { +export function devicesPercent(devicesData, maxDevicesOverride) { const current = Number(devicesData?.current_devices ?? devicesData?.devices?.length ?? 0); - const max = Number(devicesData?.max_devices || 0); + const maxValue = + maxDevicesOverride !== undefined ? maxDevicesOverride : devicesData?.max_devices; + if (maxValue === undefined || maxValue === null || maxValue === "") return 0; + const max = Number(maxValue || 0); if (!max || max <= 0) return 100; return Math.max(0, Math.min(100, Math.round((current / max) * 100))); } diff --git a/frontend/src/webapp/screens/DevicesScreen.svelte b/frontend/src/webapp/screens/DevicesScreen.svelte index 1a42525..91d2f94 100644 --- a/frontend/src/webapp/screens/DevicesScreen.svelte +++ b/frontend/src/webapp/screens/DevicesScreen.svelte @@ -33,6 +33,7 @@ hideDevicesSummary && !(devicesBusy && !devicesLoaded) && (!devicesStatus || subscriptionNotActiveError); + $: effectiveMaxDevices = devicesData?.max_devices ?? subscription?.max_devices;
@@ -42,7 +43,7 @@ {t("wa_devices_title")} - {devicesCountLabel(devicesData, t)} + {devicesCountLabel(devicesData, t, effectiveMaxDevices)}