Skip to content

Commit

Permalink
Refactor theme color handling and improve infinity value representati…
Browse files Browse the repository at this point in the history
…on in components
  • Loading branch information
MatinDehghanian committed Dec 14, 2024
1 parent 7578512 commit 5e0db54
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/components/Apps.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down Expand Up @@ -343,7 +343,7 @@ const Apps = ({ subLink }) => {
expandIcon={
<ArrowDropDownIcon
sx={{
color: theme.colors.BWColorRevert[theme.palette.mode],
color: theme.colors.BWColorRevert.light,
}}
/>
}
Expand Down
8 changes: 5 additions & 3 deletions src/components/CircularWithValueLabel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -106,7 +106,9 @@ function CircularProgressWithLabel({ value }) {
textAlign: "center",
}}
>
{`${Math.round(processedValue)}%`}
{`${
processedValue === Infinity ? "∞" : Math.round(processedValue) + "%"
}`}
</Typography>
</Box>

Expand Down
10 changes: 7 additions & 3 deletions src/components/UsageBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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})`;
Expand Down Expand Up @@ -82,7 +82,9 @@ const UsageBox = ({ type, value, total, remaining }) => {
fontWeight: "700",
}}
>
{remainingParsed.number}
{remainingParsed.text === t("infinity")
? remainingParsed.text
: remainingParsed.number}
</Typography>
<Typography
variant="h6"
Expand Down Expand Up @@ -119,7 +121,9 @@ const UsageBox = ({ type, value, total, remaining }) => {
{totaltitle}
</Typography>
<Typography variant="h6" component="div">
{totalParsed.number}
{totalParsed.text === t("infinity")
? totalParsed.text
: totalParsed.number}
</Typography>
<Typography
variant="h6"
Expand Down
4 changes: 2 additions & 2 deletions src/utils/Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const calculateUsedTimePercentage = (expireTimestamp) => {
} else if (typeof expireTimestamp === "number") {
expireTimeInSeconds = expireTimestamp;
} else {
return 0;
return Infinity;
}

const remainingSeconds = expireTimeInSeconds - Math.floor(Date.now() / 1000);
Expand All @@ -111,7 +111,7 @@ export const calculateUsedTimePercentage = (expireTimestamp) => {
return ((180 - daysRemaining) / 180) * 100;
}

return 0;
return Infinity;
};

export const formatTraffic = (bytes, t) => {
Expand Down

0 comments on commit 5e0db54

Please sign in to comment.