1
This commit is contained in:
parent
daeccdab32
commit
7993a07607
7 changed files with 30 additions and 31 deletions
|
@ -19,7 +19,7 @@ import {
|
|||
} from "react-window";
|
||||
import { Duplicate } from "services/deduplicationService";
|
||||
import { EnteFile } from "types/file";
|
||||
import { convertBytesToHumanReadable } from "utils/file";
|
||||
import { convertBytesToHumanReadable } from "utils/units";
|
||||
|
||||
export enum ITEM_TYPE {
|
||||
TIME = "TIME",
|
||||
|
|
|
@ -22,9 +22,9 @@ import {
|
|||
areEqual,
|
||||
} from "react-window";
|
||||
import { EnteFile } from "types/file";
|
||||
import { convertBytesToHumanReadable } from "utils/file";
|
||||
import { handleSelectCreator } from "utils/photoFrame";
|
||||
import { PublicCollectionGalleryContext } from "utils/publicCollectionGallery";
|
||||
import { convertBytesToHumanReadable } from "utils/units";
|
||||
|
||||
const A_DAY = 24 * 60 * 60 * 1000;
|
||||
const FOOTER_HEIGHT = 90;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Box, styled, Typography } from "@mui/material";
|
||||
import { t } from "i18next";
|
||||
import { convertBytesToGBs, makeHumanReadableStorage } from "utils/units";
|
||||
import { bytesInGB, makeHumanReadableStorage } from "utils/units";
|
||||
|
||||
const MobileSmallBox = styled(Box)`
|
||||
display: none;
|
||||
|
@ -40,9 +40,7 @@ export default function StorageSection({ usage, storage }: Iprops) {
|
|||
fontWeight={"bold"}
|
||||
sx={{ fontSize: "24px", lineHeight: "30px" }}
|
||||
>
|
||||
{`${convertBytesToGBs(usage)} / ${convertBytesToGBs(
|
||||
storage,
|
||||
)} ${t("GB")} ${t("USED")}`}
|
||||
{`${bytesInGB(usage)} / ${bytesInGB(storage)} ${t("GB")} ${t("USED")}`}
|
||||
</Typography>
|
||||
</MobileSmallBox>
|
||||
</Box>
|
||||
|
|
|
@ -5,11 +5,8 @@ import Box from "@mui/material/Box";
|
|||
import Typography from "@mui/material/Typography";
|
||||
import { t } from "i18next";
|
||||
import { Trans } from "react-i18next";
|
||||
import {
|
||||
convertBytesToGBs,
|
||||
hasAddOnBonus,
|
||||
isSubscriptionCancelled,
|
||||
} from "utils/billing";
|
||||
import { hasAddOnBonus, isSubscriptionCancelled } from "utils/billing";
|
||||
import { bytesInGB } from "utils/units";
|
||||
import { ManageSubscription } from "../manageSubscription";
|
||||
import { PeriodToggler } from "../periodToggler";
|
||||
import Plans from "../plans";
|
||||
|
@ -35,8 +32,7 @@ export default function PaidSubscriptionPlanSelectorCard({
|
|||
{t("SUBSCRIPTION")}
|
||||
</Typography>
|
||||
<Typography variant="small" color={"text.muted"}>
|
||||
{convertBytesToGBs(subscription.storage, 2)}{" "}
|
||||
{t("GB")}
|
||||
{bytesInGB(subscription.storage, 2)} {t("GB")}
|
||||
</Typography>
|
||||
</Box>
|
||||
<IconButton onClick={closeModal} color="secondary">
|
||||
|
@ -50,7 +46,7 @@ export default function PaidSubscriptionPlanSelectorCard({
|
|||
<Trans
|
||||
i18nKey="CURRENT_USAGE"
|
||||
values={{
|
||||
usage: `${convertBytesToGBs(usage, 2)} ${t("GB")}`,
|
||||
usage: `${bytesInGB(usage, 2)} ${t("GB")}`,
|
||||
}}
|
||||
/>
|
||||
</Typography>
|
||||
|
|
|
@ -7,7 +7,7 @@ import { PLAN_PERIOD } from "constants/gallery";
|
|||
import { t } from "i18next";
|
||||
import { Plan, Subscription } from "types/billing";
|
||||
import { hasPaidSubscription, isUserSubscribedPlan } from "utils/billing";
|
||||
import { convertBytesToGBs } from "utils/units";
|
||||
import { bytesInGB } from "utils/units";
|
||||
|
||||
interface Iprops {
|
||||
plan: Plan;
|
||||
|
@ -63,7 +63,7 @@ export function PlanRow({
|
|||
<PlanRowContainer>
|
||||
<TopAlignedFluidContainer>
|
||||
<Typography variant="h1" fontWeight={"bold"}>
|
||||
{convertBytesToGBs(plan.storage)}
|
||||
{bytesInGB(plan.storage)}
|
||||
</Typography>
|
||||
<FlexWrapper flexWrap={"wrap"} gap={1}>
|
||||
<Typography variant="h3" color="text.muted">
|
||||
|
|
|
@ -103,19 +103,6 @@ export async function getUpdatedEXIFFileForDownload(
|
|||
}
|
||||
}
|
||||
|
||||
export function convertBytesToHumanReadable(
|
||||
bytes: number,
|
||||
precision = 2,
|
||||
): string {
|
||||
if (bytes === 0 || isNaN(bytes)) {
|
||||
return "0 MB";
|
||||
}
|
||||
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
||||
const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
||||
return (bytes / Math.pow(1024, i)).toFixed(precision) + " " + sizes[i];
|
||||
}
|
||||
|
||||
export async function downloadFile(file: EnteFile) {
|
||||
try {
|
||||
const fileReader = new FileReader();
|
||||
|
|
|
@ -4,8 +4,26 @@ const StorageUnits = ["B", "KB", "MB", "GB", "TB"];
|
|||
|
||||
const ONE_GB = 1024 * 1024 * 1024;
|
||||
|
||||
export function convertBytesToGBs(bytes: number, precision = 0): string {
|
||||
return (bytes / (1024 * 1024 * 1024)).toFixed(precision);
|
||||
/**
|
||||
* Convert the given number of {@link bytes} to their equivalent GB string with
|
||||
* {@link precision}.
|
||||
*
|
||||
* The returned string does not have the GB prefix.
|
||||
*/
|
||||
export const bytesInGB = (bytes: number, precision = 0): string =>
|
||||
(bytes / (1024 * 1024 * 1024)).toFixed(precision);
|
||||
|
||||
export function convertBytesToHumanReadable(
|
||||
bytes: number,
|
||||
precision = 2,
|
||||
): string {
|
||||
if (bytes === 0 || isNaN(bytes)) {
|
||||
return "0 MB";
|
||||
}
|
||||
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
||||
const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
||||
return (bytes / Math.pow(1024, i)).toFixed(precision) + " " + sizes[i];
|
||||
}
|
||||
|
||||
export function makeHumanReadableStorage(
|
||||
|
|
Loading…
Add table
Reference in a new issue