mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-20 00:23:58 +01:00
Duration and size tags
This commit is contained in:
25
src-web/components/core/DurationTag.tsx
Normal file
25
src-web/components/core/DurationTag.tsx
Normal 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}
|
||||
</>
|
||||
);
|
||||
}
|
||||
28
src-web/components/core/SizeTag.tsx
Normal file
28
src-web/components/core/SizeTag.tsx
Normal 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}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user