1
- import { useTranslation } from "next-i18next" ;
2
-
1
+ import { useTranslation } from "next-i18next" ;
3
2
import Container from "components/services/widget/container" ;
4
3
import Block from "components/services/widget/block" ;
4
+
5
+ import QueueEntry from "../../components/widgets/queue/queueEntry" ;
6
+
5
7
import useWidgetAPI from "utils/proxy/use-widget-api" ;
6
8
7
- export default function Component ( { service} ) {
8
- const { t} = useTranslation ( ) ;
9
+ export default function Component ( { service } ) {
10
+ const { t } = useTranslation ( ) ;
11
+ const { widget } = service ;
12
+ const { refreshInterval = 1000 } = widget ;
9
13
10
- const { widget} = service ;
11
- const { refreshInterval = 1000 } = widget ;
14
+ const { data : torrentData , error : torrentError } = useWidgetAPI ( widget , "torrents" ,
15
+ { refreshInterval : Math . max ( 1000 , refreshInterval ) }
16
+ ) ;
12
17
13
- const { data : torrentData , error : torrentError } = useWidgetAPI ( widget , "torrents/info" ,
14
- { refreshInterval : Math . max ( 1000 , refreshInterval ) }
18
+ if ( torrentError ) {
19
+ return < Container service = { service } error = { torrentError } /> ;
20
+ }
21
+
22
+ if ( ! torrentData ) {
23
+ return (
24
+ < Container service = { service } >
25
+ < Block label = "qbittorrent.leech" />
26
+ < Block label = "qbittorrent.download" />
27
+ < Block label = "qbittorrent.seed" />
28
+ < Block label = "qbittorrent.upload" />
29
+ </ Container >
15
30
) ;
31
+ }
16
32
17
- if ( torrentError ) {
18
- return < Container service = { service } error = { torrentError } /> ;
19
- }
33
+ let rateDl = 0 ;
34
+ let rateUl = 0 ;
35
+ let completed = 0 ;
36
+ const leechTorrents = [ ] ;
20
37
21
- if ( ! torrentData ) {
22
- return (
23
- < Container service = { service } >
24
- < Block label = "qbittorrent.leech" />
25
- < Block label = "qbittorrent.download" />
26
- < Block label = "qbittorrent.seed" />
27
- < Block label = "qbittorrent.upload" />
28
- </ Container >
29
- ) ;
38
+ for ( let i = 0 ; i < torrentData . length ; i += 1 ) {
39
+ const torrent = torrentData [ i ] ;
40
+ rateDl += torrent . dlspeed ;
41
+ rateUl += torrent . upspeed ;
42
+ if ( torrent . progress === 1 ) {
43
+ completed += 1 ;
30
44
}
31
-
32
- let rateDl = 0 ;
33
- let rateUl = 0 ;
34
- let completed = 0 ;
35
-
36
- for ( let i = 0 ; i < torrentData . length ; i += 1 ) {
37
- const torrent = torrentData [ i ] ;
38
- rateDl += torrent . dlspeed ;
39
- rateUl += torrent . upspeed ;
40
- if ( torrent . progress === 1 ) {
41
- completed += 1 ;
42
- }
45
+ if ( torrent . state . includes ( "DL" ) || torrent . state === "downloading" ) {
46
+ leechTorrents . push ( torrent ) ;
43
47
}
48
+ }
44
49
45
- const leech = torrentData . length - completed ;
50
+ const leech = torrentData . length - completed ;
46
51
47
- return (
48
- < Container service = { service } >
49
- < Block label = "qbittorrent.leech" value = { t ( "common.number" , { value : leech } ) } />
50
- < Block label = "qbittorrent.download" value = { t ( "common.bibyterate" , { value : rateDl , decimals : 1 } ) } />
51
- < Block label = "qbittorrent.seed" value = { t ( "common.number" , { value : completed } ) } />
52
- < Block label = "qbittorrent.upload" value = { t ( "common.bibyterate" , { value : rateUl , decimals : 1 } ) } />
53
- </ Container >
54
- ) ;
52
+ return (
53
+ < >
54
+ < Container service = { service } >
55
+ < Block label = "qbittorrent.leech" value = { t ( "common.number" , { value : leech } ) } />
56
+ < Block label = "qbittorrent.download" value = { t ( "common.bibyterate" , { value : rateDl , decimals : 1 } ) } />
57
+ < Block label = "qbittorrent.seed" value = { t ( "common.number" , { value : completed } ) } />
58
+ < Block label = "qbittorrent.upload" value = { t ( "common.bibyterate" , { value : rateUl , decimals : 1 } ) } />
59
+ </ Container >
60
+ { widget ?. enableLeechProgress &&
61
+ leechTorrents . map ( ( queueEntry ) => (
62
+ < QueueEntry
63
+ progress = { queueEntry . progress * 100 }
64
+ timeLeft = { t ( "common.duration" , { value : queueEntry . eta } ) }
65
+ title = { queueEntry . name }
66
+ activity = { queueEntry . state }
67
+ key = { `${ queueEntry . name } -${ queueEntry . amount_left } ` }
68
+ />
69
+ ) ) }
70
+ </ >
71
+ ) ;
55
72
}
0 commit comments