From 2f8ce4174df6fdea1dc28dca71b8a8e2ba2b2e54 Mon Sep 17 00:00:00 2001 From: Diogo Silva Date: Sat, 24 Dec 2022 02:22:40 +0100 Subject: [PATCH 1/3] Added torrent listing to the qBittorrent --- src/widgets/qbittorrent/component.jsx | 116 ++++++++++++++++++++++++-- 1 file changed, 110 insertions(+), 6 deletions(-) diff --git a/src/widgets/qbittorrent/component.jsx b/src/widgets/qbittorrent/component.jsx index d3836a6ba1a..e64791f9636 100644 --- a/src/widgets/qbittorrent/component.jsx +++ b/src/widgets/qbittorrent/component.jsx @@ -1,9 +1,106 @@ +import { BsDownload, BsPause, BsUpload, BsExclamationTriangle, BsThreeDots, BsCheckLg } from "react-icons/bs"; import { useTranslation } from "next-i18next"; import Container from "components/services/widget/container"; import Block from "components/services/widget/block"; import useWidgetAPI from "utils/proxy/use-widget-api"; +function secondsToTime(totalSeconds) { + const seconds = Math.floor((totalSeconds) % 60); + const minutes = Math.floor((totalSeconds / 60) % 60); + const hours = Math.floor((totalSeconds / (60 * 60)) % 24); + return { hours, minutes, seconds }; +} + +function secondsToString(totalSeconds) { + const { hours, minutes, seconds } = secondsToTime(totalSeconds); + const parts = []; + if (hours > 0) { + parts.push(hours); + } + parts.push(minutes); + parts.push(seconds); + + return parts.map((part) => part.toString().padStart(2, "0")).join(":"); +} + +function getIconFromTorrentState(state) { + switch(state) { + case 'pausedUP': + case 'pausedDL': + return ; + case 'uploading': + case 'queuedUP': + case 'stalledUP': + case 'checkingUP': + case 'forcedUP': + return ; + case 'allocating': + case 'downloading': + case 'metaDL': + case 'queuedDL': + case 'stalledDL': + case 'checkingDL': + case 'forcedDL': + return ; + case 'checkingResumeData': + case 'moving': + return ; + case 'missingFiles': + case 'error': + default: + return ; + } +} + +function readEtaFromTorrent(state) { + switch(state) { + case 'allocating': + case 'downloading': + case 'metaDL': + case 'queuedDL': + case 'stalledDL': + case 'checkingDL': + case 'forcedDL': + return true; + case 'error': + default: + return false; + } +} + +function TorrentEntry({ torrent }) { + const { state, name, progress, eta, upspeed, dlspeed } = torrent; + const { t } = useTranslation(); + + return ( +
+
+
+ {getIconFromTorrentState(state)} +
+
+
{name}
+
+
+ {t("common.byterate", { value: dlspeed, decimals: 1 })} +
+
+ {t("common.byterate", { value: upspeed, decimals: 1 })} +
+
+ {readEtaFromTorrent(state) === true ? secondsToString(eta) : + } +
+
+ ); +} + export default function Component({ service }) { const { t } = useTranslation(); @@ -42,11 +139,18 @@ export default function Component({ service }) { const leech = torrentData.length - completed; return ( - - - - - - + <> + + + + + + +
+ {torrentData.map((torrent) => ( + + ))} +
+ ); } From e9aeed1f926162c88b982287422c10e8989685be Mon Sep 17 00:00:00 2001 From: Diogo Silva Date: Sat, 24 Dec 2022 02:48:33 +0100 Subject: [PATCH 2/3] Show torrents when requested in fields --- src/widgets/qbittorrent/component.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/widgets/qbittorrent/component.jsx b/src/widgets/qbittorrent/component.jsx index e64791f9636..f8a938efbb0 100644 --- a/src/widgets/qbittorrent/component.jsx +++ b/src/widgets/qbittorrent/component.jsx @@ -137,7 +137,7 @@ export default function Component({ service }) { } const leech = torrentData.length - completed; - + const torrentsEnabled = service.widget.fields === null || service.widget.fields?.includes('torrents'); return ( <> @@ -146,7 +146,7 @@ export default function Component({ service }) { -
+
{torrentData.map((torrent) => ( ))} From 15b78a2f739e3480a22b3e2164c51dee0ca80950 Mon Sep 17 00:00:00 2001 From: Diogo Silva Date: Sat, 24 Dec 2022 03:01:41 +0100 Subject: [PATCH 3/3] Provided a more unique key to the rendering in qBittorrent widget --- src/widgets/qbittorrent/component.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/widgets/qbittorrent/component.jsx b/src/widgets/qbittorrent/component.jsx index f8a938efbb0..1b10edeb10e 100644 --- a/src/widgets/qbittorrent/component.jsx +++ b/src/widgets/qbittorrent/component.jsx @@ -139,7 +139,7 @@ export default function Component({ service }) { const leech = torrentData.length - completed; const torrentsEnabled = service.widget.fields === null || service.widget.fields?.includes('torrents'); return ( - <> +
@@ -148,9 +148,9 @@ export default function Component({ service }) {
{torrentData.map((torrent) => ( - + ))}
- +
); }