File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -10,14 +10,15 @@ import { styled } from '@mui/material/styles';
1010import AuthContext from 'context/authContext' ;
1111import { useContext } from 'react' ;
1212
13- import { formatBytes } from '../utils/utils' ;
13+ import { formatUsedQuotaInGB } from '../utils/utils' ;
1414
1515export const Quota = ( ) => {
1616 const { user } = useContext ( AuthContext ) ;
1717 const quota = user ?. quota || 0 ;
1818 const usedQuota = user ?. usedQuota || 0 ;
1919
20- const percentage = ( ( usedQuota / quota ) * 100 ) . toFixed ( 1 ) ;
20+ const percentage = ( usedQuota / quota ) * 100 ;
21+ const displayedUsedQuota = percentage > 0 ? Math . max ( 0.1 , Math . round ( percentage * 10 ) / 10 ) . toFixed ( 1 ) : "0.0" ;
2122
2223 const BorderLinearProgress = styled ( LinearProgress ) ( ( ) => ( {
2324 height : 8 ,
@@ -60,7 +61,7 @@ export const Quota = () => {
6061 Quota
6162 </ Typography >
6263 < Typography color = "text.primary" fontWeight = "600" variant = "h4" >
63- { percentage } %
64+ { displayedUsedQuota } %
6465 </ Typography >
6566 </ Stack >
6667 </ Stack >
@@ -73,7 +74,7 @@ export const Quota = () => {
7374 />
7475 </ Box >
7576 < Typography color = "text.secondary" gutterBottom sx = { { mt : 3 } } >
76- { formatBytes ( usedQuota , 2 ) } GB of { formatBytes ( quota , 2 ) } GB used
77+ { formatUsedQuotaInGB ( usedQuota , 2 ) } GB of { formatUsedQuotaInGB ( quota , 2 ) } GB used
7778 </ Typography >
7879 </ Box >
7980 ) : (
Original file line number Diff line number Diff line change @@ -79,3 +79,12 @@ export const generateImageHash = async (file: File) => {
7979 const base64String = hexToBase64 ( hashValue ) ;
8080 return base64String ;
8181} ;
82+
83+ export const formatUsedQuotaInGB = ( usedQuota : number , decimals = 2 ) => {
84+ if ( usedQuota <= 0 ) return "0.0" ;
85+
86+ const rawGB = formatBytes ( usedQuota , decimals ) ;
87+ const gbValue = parseFloat ( rawGB ) ;
88+
89+ return gbValue < 0.1 ? "0.1" : `${ rawGB } ` ;
90+ }
You can’t perform that action at this time.
0 commit comments