diff --git a/web/apps/photos/src/components/PhotoList/dedupe.tsx b/web/apps/photos/src/components/PhotoList/dedupe.tsx index ab7badf1f63de2d867155077ce4de4f05d7f2994..be412ad782b1e8b17f369e9852aced722c1eacce 100644 --- a/web/apps/photos/src/components/PhotoList/dedupe.tsx +++ b/web/apps/photos/src/components/PhotoList/dedupe.tsx @@ -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", diff --git a/web/apps/photos/src/components/PhotoList/index.tsx b/web/apps/photos/src/components/PhotoList/index.tsx index 4803995d4f7f9e77b7899cfea81f9e0c63d26964..508e9eab5a1956595d681310e3a52c2bda0b54c0 100644 --- a/web/apps/photos/src/components/PhotoList/index.tsx +++ b/web/apps/photos/src/components/PhotoList/index.tsx @@ -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; diff --git a/web/apps/photos/src/components/Sidebar/SubscriptionCard/contentOverlay/storageSection.tsx b/web/apps/photos/src/components/Sidebar/SubscriptionCard/contentOverlay/storageSection.tsx index 8ef5bea5ecb4548bbeb0a1f9b5267e8b0d01f32e..90705753b92aeadb47a529dc2905f63f122d1939 100644 --- a/web/apps/photos/src/components/Sidebar/SubscriptionCard/contentOverlay/storageSection.tsx +++ b/web/apps/photos/src/components/Sidebar/SubscriptionCard/contentOverlay/storageSection.tsx @@ -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")}`} diff --git a/web/apps/photos/src/components/pages/gallery/PlanSelector/card/paid.tsx b/web/apps/photos/src/components/pages/gallery/PlanSelector/card/paid.tsx index 4ef76a491ff1888e582ca4446c4c8051e10b67fa..0ef4b15947d67ae4656039a6ad33d835ad16199c 100644 --- a/web/apps/photos/src/components/pages/gallery/PlanSelector/card/paid.tsx +++ b/web/apps/photos/src/components/pages/gallery/PlanSelector/card/paid.tsx @@ -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")} - {convertBytesToGBs(subscription.storage, 2)}{" "} - {t("GB")} + {bytesInGB(subscription.storage, 2)} {t("GB")} @@ -50,7 +46,7 @@ export default function PaidSubscriptionPlanSelectorCard({ diff --git a/web/apps/photos/src/components/pages/gallery/PlanSelector/plans/planRow.tsx b/web/apps/photos/src/components/pages/gallery/PlanSelector/plans/planRow.tsx index ca01b40b393c2d296f2ee6e1d5916765d9f7423d..bb2347ddcc03360e7e5dd2ec3550f06212500b81 100644 --- a/web/apps/photos/src/components/pages/gallery/PlanSelector/plans/planRow.tsx +++ b/web/apps/photos/src/components/pages/gallery/PlanSelector/plans/planRow.tsx @@ -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({ - {convertBytesToGBs(plan.storage)} + {bytesInGB(plan.storage)} diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.ts index bb212ff21ef979c64bd13823744c9f358065ff3d..98a8dd94813db813801c422041903562e86930e8 100644 --- a/web/apps/photos/src/utils/file/index.ts +++ b/web/apps/photos/src/utils/file/index.ts @@ -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(); diff --git a/web/apps/photos/src/utils/units.ts b/web/apps/photos/src/utils/units.ts index 44ef4e023eac6a392db3e3c17d89c5454973372e..20a90e4c2956164786c0bc888e0721784deb0884 100644 --- a/web/apps/photos/src/utils/units.ts +++ b/web/apps/photos/src/utils/units.ts @@ -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(