From 461919805181858c55d9e9a6b3cc9f51caceb77c Mon Sep 17 00:00:00 2001 From: JackEnx Date: Thu, 18 Apr 2024 17:17:07 -0300 Subject: [PATCH] refactor: change file name --- src/renderer/hooks/use-download.ts | 4 ++-- src/renderer/pages/downloads/downloads.tsx | 8 ++++---- src/renderer/pages/game-details/hero-panel.tsx | 10 +++++----- src/renderer/pages/game-details/repacks-modal.tsx | 4 ++-- src/renderer/utils/{byteFormat.ts => format-bytes.ts} | 2 +- src/renderer/utils/index.ts | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) rename src/renderer/utils/{byteFormat.ts => format-bytes.ts} (87%) diff --git a/src/renderer/hooks/use-download.ts b/src/renderer/hooks/use-download.ts index 9f6411978..522dd2c2d 100644 --- a/src/renderer/hooks/use-download.ts +++ b/src/renderer/hooks/use-download.ts @@ -11,7 +11,7 @@ import { } from "@renderer/features"; import type { GameShop, TorrentProgress } from "@types"; import { useDate } from "./use-date"; -import { byteFormat } from "@renderer/utils"; +import { formatBytes } from "@renderer/utils"; export function useDownload() { const { updateLibrary } = useLibrary(); @@ -113,7 +113,7 @@ export function useDownload() { fileSize: lastPacket?.game.fileSize, isVerifying, gameId: lastPacket?.game.id, - downloadSpeed: `${byteFormat(lastPacket?.downloadSpeed ?? 0)}/s`, + downloadSpeed: `${formatBytes(lastPacket?.downloadSpeed ?? 0)}/s`, isDownloading: Boolean(lastPacket), progress: getProgress(), numPeers: lastPacket?.numPeers, diff --git a/src/renderer/pages/downloads/downloads.tsx b/src/renderer/pages/downloads/downloads.tsx index cd5ae3693..aecf7b5eb 100644 --- a/src/renderer/pages/downloads/downloads.tsx +++ b/src/renderer/pages/downloads/downloads.tsx @@ -10,7 +10,7 @@ import { useEffect, useMemo, useRef, useState } from "react"; import { BinaryNotFoundModal } from "../shared-modals/binary-not-found-modal"; import * as styles from "./downloads.css"; import { DeleteModal } from "./delete-modal"; -import { byteFormat } from "@renderer/utils"; +import { formatBytes } from "@renderer/utils"; export function Downloads() { const { library, updateLibrary } = useLibrary(); @@ -61,10 +61,10 @@ export function Downloads() { const isGameDownloading = isDownloading && gameDownloading?.id === game?.id; if (!game) return "N/A"; - if (game.fileSize) return byteFormat(game.fileSize); + if (game.fileSize) return formatBytes(game.fileSize); if (gameDownloading?.fileSize && isGameDownloading) - return byteFormat(gameDownloading.fileSize); + return formatBytes(gameDownloading.fileSize); return game.repack?.fileSize ?? "N/A"; }; @@ -87,7 +87,7 @@ export function Downloads() { ) : ( <>

- {byteFormat(gameDownloading?.bytesDownloaded)} /{" "} + {formatBytes(gameDownloading?.bytesDownloaded)} /{" "} {finalDownloadSize}

diff --git a/src/renderer/pages/game-details/hero-panel.tsx b/src/renderer/pages/game-details/hero-panel.tsx index 1082d7069..cfee9096c 100644 --- a/src/renderer/pages/game-details/hero-panel.tsx +++ b/src/renderer/pages/game-details/hero-panel.tsx @@ -11,7 +11,7 @@ import { NoEntryIcon, PlusCircleIcon } from "@primer/octicons-react"; import { BinaryNotFoundModal } from "../shared-modals/binary-not-found-modal"; import * as styles from "./hero-panel.css"; import { useDate } from "@renderer/hooks/use-date"; -import { byteFormat } from "@renderer/utils"; +import { formatBytes } from "@renderer/utils"; export interface HeroPanelProps { game: Game | null; @@ -120,10 +120,10 @@ export function HeroPanel({ const finalDownloadSize = useMemo(() => { if (!game) return "N/A"; - if (game.fileSize) return byteFormat(game.fileSize); + if (game.fileSize) return formatBytes(game.fileSize); if (gameDownloading?.fileSize && isGameDownloading) - return byteFormat(gameDownloading.fileSize); + return formatBytes(gameDownloading.fileSize); return game.repack?.fileSize ?? "N/A"; }, [game, isGameDownloading, gameDownloading]); @@ -170,7 +170,7 @@ export function HeroPanel({ ) : (

- {byteFormat(gameDownloading?.bytesDownloaded)} /{" "} + {formatBytes(gameDownloading?.bytesDownloaded)} /{" "} {finalDownloadSize} {numPeers} peers / {numSeeds} seeds @@ -190,7 +190,7 @@ export function HeroPanel({ })}

- {byteFormat(game.bytesDownloaded)} / {finalDownloadSize} + {formatBytes(game.bytesDownloaded)} / {finalDownloadSize}

); diff --git a/src/renderer/pages/game-details/repacks-modal.tsx b/src/renderer/pages/game-details/repacks-modal.tsx index a84d76fa0..b3917b23d 100644 --- a/src/renderer/pages/game-details/repacks-modal.tsx +++ b/src/renderer/pages/game-details/repacks-modal.tsx @@ -9,7 +9,7 @@ import * as styles from "./repacks-modal.css"; import type { DiskSpace } from "check-disk-space"; import { format } from "date-fns"; import { SPACING_UNIT } from "@renderer/theme.css"; -import { byteFormat } from "@renderer/utils"; +import { formatBytes } from "@renderer/utils"; export interface RepacksModalProps { visible: boolean; @@ -66,7 +66,7 @@ export function RepacksModal({ visible={visible} title={`${gameDetails.name} Repacks`} description={t("space_left_on_disk", { - space: byteFormat(diskFreeSpace?.free ?? 0), + space: formatBytes(diskFreeSpace?.free ?? 0), })} onClose={onClose} > diff --git a/src/renderer/utils/byteFormat.ts b/src/renderer/utils/format-bytes.ts similarity index 87% rename from src/renderer/utils/byteFormat.ts rename to src/renderer/utils/format-bytes.ts index ecff16841..5aa390727 100644 --- a/src/renderer/utils/byteFormat.ts +++ b/src/renderer/utils/format-bytes.ts @@ -1,6 +1,6 @@ const FORMAT = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; -export const byteFormat = (bytes: number): string => { +export const formatBytes = (bytes: number): string => { if (!Number.isFinite(bytes) || isNaN(bytes) || bytes < 0) { return `N/A ${FORMAT[0]}`; } diff --git a/src/renderer/utils/index.ts b/src/renderer/utils/index.ts index a24caa367..7a828a7f5 100644 --- a/src/renderer/utils/index.ts +++ b/src/renderer/utils/index.ts @@ -1 +1 @@ -export * from "./byteFormat"; +export * from "./format-bytes";