Skip to content

Commit

Permalink
Merge pull request #87 from NGR-NP/master
Browse files Browse the repository at this point in the history
feat: Enhance file size formatting
  • Loading branch information
maheshbasnet089 authored Feb 22, 2024
2 parents 5405a20 + ea4a9d6 commit 203aa35
Show file tree
Hide file tree
Showing 3 changed files with 1,460 additions and 1,114 deletions.
9 changes: 7 additions & 2 deletions tapShareFrontend/src/pages/history/history.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Stack from "@mui/material/Stack";
import { Chip } from "@mui/material";
import { PiFileCode, PiFileSvg, PiFiles } from "react-icons/pi";
import { BiFileFind } from "react-icons/bi";
import { formatFileSize } from "../../utility/FormatFileSize";

const History = () => {
const navigate = useNavigate();
Expand Down Expand Up @@ -145,7 +146,7 @@ const History = () => {
</div>
{data?.size && (
<div className="flex gap-1 ">
size: <p>{data?.size}</p>
size: <p>{formatFileSize(data?.size)}</p>
</div>
)}
{data?.text && (
Expand Down Expand Up @@ -184,7 +185,11 @@ const History = () => {
})
) : (
<div>
<img src={notFound} className="mx-auto" alt="there isn't any history" />
<img
src={notFound}
className="mx-auto"
alt="there isn't any history"
/>
<p className="text-center mt-4">No History</p>
</div>
)}
Expand Down
11 changes: 11 additions & 0 deletions tapShareFrontend/src/utility/FormatFileSize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function formatFileSize(sizeInBytes) {
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
let unitIndex = 0;

while (sizeInBytes >= 1024 && unitIndex < units.length - 1) {
sizeInBytes /= 1024;
unitIndex++;
}

return sizeInBytes.toFixed(2) + ' ' + units[unitIndex];
}
Loading

0 comments on commit 203aa35

Please sign in to comment.