Refactor the rqbit-web file by breaking it down into components and helper functions. Improve code organization and maintainability
This commit is contained in:
parent
a5e7a5a5f5
commit
f978ad02fe
25 changed files with 1722 additions and 926 deletions
19
crates/librqbit/webui/src/helper/formatSecondsToTime.ts
Normal file
19
crates/librqbit/webui/src/helper/formatSecondsToTime.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
export function formatSecondsToTime(seconds: number): string {
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
const remainingSeconds = seconds % 60;
|
||||
|
||||
const formatUnit = (value: number, unit: string) =>
|
||||
value > 0 ? `${value}${unit}` : "";
|
||||
|
||||
if (hours > 0) {
|
||||
return `${formatUnit(hours, "h")} ${formatUnit(minutes, "m")}`.trim();
|
||||
} else if (minutes > 0) {
|
||||
return `${formatUnit(minutes, "m")} ${formatUnit(
|
||||
remainingSeconds,
|
||||
"s"
|
||||
)}`.trim();
|
||||
} else {
|
||||
return `${formatUnit(remainingSeconds, "s")}`.trim();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue