Duration and size tags

This commit is contained in:
Gregory Schier
2023-04-13 20:50:17 -07:00
parent f33ef73f43
commit a22154e8ce
4 changed files with 59 additions and 4 deletions

View File

@@ -0,0 +1,25 @@
interface Props {
millis: number;
}
export function DurationTag({ millis }: Props) {
let num;
let unit;
if (millis > 1000 * 60) {
num = millis / 1000 / 60;
unit = 'min';
} else if (millis > 1000) {
num = millis / 1000;
unit = 's';
} else {
num = millis;
unit = 'ms';
}
return (
<>
{Math.round(num * 10) / 10} {unit}
</>
);
}

View File

@@ -0,0 +1,28 @@
interface Props {
contentLength: number;
}
export function SizeTag({ contentLength }: Props) {
let num;
let unit;
if (contentLength > 1000 * 1000 * 1000) {
num = contentLength / 1000 / 1000 / 1000;
unit = 'GB';
} else if (contentLength > 1000 * 1000) {
num = contentLength / 1000 / 1000;
unit = 'MB';
} else if (contentLength > 1000) {
num = contentLength / 1000;
unit = 'KB';
} else {
num = contentLength;
unit = 'B';
}
return (
<>
{Math.round(num * 10) / 10} {unit}
</>
);
}