Move
This commit is contained in:
parent
c4756fb847
commit
daeccdab32
7 changed files with 47 additions and 50 deletions
|
@ -7,7 +7,7 @@ import VideocamOutlined from "@mui/icons-material/VideocamOutlined";
|
|||
import Box from "@mui/material/Box";
|
||||
import { useEffect, useState } from "react";
|
||||
import { EnteFile } from "types/file";
|
||||
import { makeHumanReadableStorage } from "utils/billing";
|
||||
import { makeHumanReadableStorage } from "utils/units";
|
||||
import { changeFileName, updateExistingFilePubMetadata } from "utils/file";
|
||||
import { FileNameEditDialog } from "./FileNameEditDialog";
|
||||
import InfoItem from "./InfoItem";
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { SpaceBetweenFlex } from "@ente/shared/components/Container";
|
||||
import { Box, Typography } from "@mui/material";
|
||||
import { t } from "i18next";
|
||||
import { makeHumanReadableStorage } from "utils/billing";
|
||||
import { makeHumanReadableStorage } from "utils/units";
|
||||
|
||||
import { Progressbar } from "../../styledComponents";
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Box, styled, Typography } from "@mui/material";
|
||||
import { t } from "i18next";
|
||||
import { convertBytesToGBs, makeHumanReadableStorage } from "utils/billing";
|
||||
import { convertBytesToGBs, makeHumanReadableStorage } from "utils/units";
|
||||
|
||||
const MobileSmallBox = styled(Box)`
|
||||
display: none;
|
||||
|
|
|
@ -2,7 +2,7 @@ import { SpaceBetweenFlex } from "@ente/shared/components/Container";
|
|||
import { Box, styled, Typography } from "@mui/material";
|
||||
|
||||
import { Trans } from "react-i18next";
|
||||
import { makeHumanReadableStorage } from "utils/billing";
|
||||
import { makeHumanReadableStorage } from "utils/units";
|
||||
|
||||
const RowContainer = styled(SpaceBetweenFlex)(({ theme }) => ({
|
||||
// gap: theme.spacing(1.5),
|
||||
|
|
|
@ -6,11 +6,8 @@ import { Badge } from "components/Badge";
|
|||
import { PLAN_PERIOD } from "constants/gallery";
|
||||
import { t } from "i18next";
|
||||
import { Plan, Subscription } from "types/billing";
|
||||
import {
|
||||
convertBytesToGBs,
|
||||
hasPaidSubscription,
|
||||
isUserSubscribedPlan,
|
||||
} from "utils/billing";
|
||||
import { hasPaidSubscription, isUserSubscribedPlan } from "utils/billing";
|
||||
import { convertBytesToGBs } from "utils/units";
|
||||
|
||||
interface Iprops {
|
||||
plan: Plan;
|
||||
|
|
|
@ -31,44 +31,6 @@ enum RESPONSE_STATUS {
|
|||
fail = "fail",
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
export function makeHumanReadableStorage(
|
||||
bytes: number,
|
||||
{ roundUp } = { roundUp: false },
|
||||
): string {
|
||||
if (bytes <= 0) {
|
||||
return `0 ${t("STORAGE_UNITS.MB")}`;
|
||||
}
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
||||
|
||||
let quantity = bytes / Math.pow(1024, i);
|
||||
let unit = StorageUnits[i];
|
||||
|
||||
if (quantity > 100 && unit !== "GB") {
|
||||
quantity /= 1024;
|
||||
unit = StorageUnits[i + 1];
|
||||
}
|
||||
|
||||
quantity = Number(quantity.toFixed(1));
|
||||
|
||||
if (bytes >= 10 * ONE_GB) {
|
||||
if (roundUp) {
|
||||
quantity = Math.ceil(quantity);
|
||||
} else {
|
||||
quantity = Math.round(quantity);
|
||||
}
|
||||
}
|
||||
|
||||
return `${quantity} ${t(`STORAGE_UNITS.${unit}`)}`;
|
||||
}
|
||||
|
||||
export function hasPaidSubscription(subscription: Subscription) {
|
||||
return (
|
||||
subscription &&
|
||||
|
@ -160,9 +122,8 @@ export function isSubscriptionPastDue(subscription: Subscription) {
|
|||
);
|
||||
}
|
||||
|
||||
export function isPopularPlan(plan: Plan) {
|
||||
return plan.storage === 100 * ONE_GB;
|
||||
}
|
||||
export const isPopularPlan = (plan: Plan) =>
|
||||
plan.storage === 100 * 1024 * 1024 * 1024; /* 100 GB */
|
||||
|
||||
export async function updateSubscription(
|
||||
plan: Plan,
|
||||
|
|
39
web/apps/photos/src/utils/units.ts
Normal file
39
web/apps/photos/src/utils/units.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
import { t } from "i18next";
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
export function makeHumanReadableStorage(
|
||||
bytes: number,
|
||||
{ roundUp } = { roundUp: false },
|
||||
): string {
|
||||
if (bytes <= 0) {
|
||||
return `0 ${t("STORAGE_UNITS.MB")}`;
|
||||
}
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
||||
|
||||
let quantity = bytes / Math.pow(1024, i);
|
||||
let unit = StorageUnits[i];
|
||||
|
||||
if (quantity > 100 && unit !== "GB") {
|
||||
quantity /= 1024;
|
||||
unit = StorageUnits[i + 1];
|
||||
}
|
||||
|
||||
quantity = Number(quantity.toFixed(1));
|
||||
|
||||
if (bytes >= 10 * ONE_GB) {
|
||||
if (roundUp) {
|
||||
quantity = Math.ceil(quantity);
|
||||
} else {
|
||||
quantity = Math.round(quantity);
|
||||
}
|
||||
}
|
||||
|
||||
return `${quantity} ${t(`STORAGE_UNITS.${unit}`)}`;
|
||||
}
|
Loading…
Add table
Reference in a new issue