From 5e0db54fc6b622507b6e2d1519db8dd812aac862 Mon Sep 17 00:00:00 2001 From: Matin Dehghanian Date: Sat, 14 Dec 2024 12:47:24 +0330 Subject: [PATCH] Refactor theme color handling and improve infinity value representation in components --- src/components/Apps.jsx | 4 ++-- src/components/CircularWithValueLabel.jsx | 8 +++++--- src/components/UsageBox.jsx | 10 +++++++--- src/utils/Helper.js | 4 ++-- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/components/Apps.jsx b/src/components/Apps.jsx index d973e02..4222038 100644 --- a/src/components/Apps.jsx +++ b/src/components/Apps.jsx @@ -69,7 +69,7 @@ const getAccordionStyles = (theme) => ({ marginBottom: ".8rem", background: theme === "light" ? "rgba(255, 255, 255, 0.1)" : "rgba(0, 0, 0, 0.1)", - color: theme.colors.BWColorRevert[theme.palette.mode], + color: theme.colors.BWColorRevert.light, "&.Mui-expanded": { background: theme === "light" ? "rgba(255, 255, 255, 0.1)" : "rgba(0, 0, 0, 0.3)", @@ -343,7 +343,7 @@ const Apps = ({ subLink }) => { expandIcon={ } diff --git a/src/components/CircularWithValueLabel.jsx b/src/components/CircularWithValueLabel.jsx index ae0dc58..c891915 100644 --- a/src/components/CircularWithValueLabel.jsx +++ b/src/components/CircularWithValueLabel.jsx @@ -29,7 +29,7 @@ function CircularProgressWithLabel({ value }) { typographyGradient: theme.colors.gradients.high.typographyGradient, }; } - if (value <= 30 || value > 100) { + if (value <= 30) { return { gradientColors: theme.colors.gradients.high.colors[theme.palette.mode], backgroundColor: theme.colors.gradients.high.background, @@ -52,7 +52,7 @@ function CircularProgressWithLabel({ value }) { }; const processedValue = - value === Infinity ? 0 : value > 100 ? 100 : value > 0 ? value : 0; + value === Infinity ? Infinity : value > 100 ? 100 : value > 0 ? value : 0; const { gradientColors, backgroundColor, typographyGradient } = getStyles(value); @@ -106,7 +106,9 @@ function CircularProgressWithLabel({ value }) { textAlign: "center", }} > - {`${Math.round(processedValue)}%`} + {`${ + processedValue === Infinity ? "∞" : Math.round(processedValue) + "%" + }`} diff --git a/src/components/UsageBox.jsx b/src/components/UsageBox.jsx index 9065c45..9c1de92 100644 --- a/src/components/UsageBox.jsx +++ b/src/components/UsageBox.jsx @@ -18,7 +18,7 @@ const UsageBox = ({ type, value, total, remaining }) => { const getTypographyGradient = (v) => { if (v === Infinity) { return `linear-gradient(0deg, ${theme.palette.success.main}, ${theme.palette.success.dark})`; - } else if (v <= 30 || v > 100) { + } else if (v <= 30) { return `linear-gradient(0deg, ${theme.palette.success.main}, ${theme.palette.success.dark})`; } else if (v <= 70) { return `linear-gradient(0deg, ${theme.palette.warning.main}, ${theme.palette.warning.dark})`; @@ -82,7 +82,9 @@ const UsageBox = ({ type, value, total, remaining }) => { fontWeight: "700", }} > - {remainingParsed.number} + {remainingParsed.text === t("infinity") + ? remainingParsed.text + : remainingParsed.number} { {totaltitle} - {totalParsed.number} + {totalParsed.text === t("infinity") + ? totalParsed.text + : totalParsed.number} { } else if (typeof expireTimestamp === "number") { expireTimeInSeconds = expireTimestamp; } else { - return 0; + return Infinity; } const remainingSeconds = expireTimeInSeconds - Math.floor(Date.now() / 1000); @@ -111,7 +111,7 @@ export const calculateUsedTimePercentage = (expireTimestamp) => { return ((180 - daysRemaining) / 180) * 100; } - return 0; + return Infinity; }; export const formatTraffic = (bytes, t) => {