From 10f421bbb2bc24e475c4d60a34ecd606149aef7b Mon Sep 17 00:00:00 2001 From: Christopher Kahn <92762809+kahnclusions@users.noreply.github.com> Date: Mon, 5 Aug 2024 00:47:43 +0800 Subject: [PATCH] Update table view --- app/src/components/torrents.rs | 41 +++++++++++++++++++++++++------ qbittorrent_rs_sse/src/signals.rs | 10 ++++++++ 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/app/src/components/torrents.rs b/app/src/components/torrents.rs index 7c7ea7a..fe8efc8 100644 --- a/app/src/components/torrents.rs +++ b/app/src/components/torrents.rs @@ -1,11 +1,9 @@ use human_bytes::human_bytes; use rust_decimal::prelude::*; -use std::collections::HashMap; use tailwind_fuse::tw_merge; use fnord_ui::components::{Text, View}; use leptos::prelude::*; -use qbittorrent_rs_proto::torrents::TorrentInfo; use qbittorrent_rs_sse::signals::Torrent; static CELL_CLASS: &'static str = "shadow-border p-2 whitespace-nowrap text-left font-normal"; @@ -18,11 +16,9 @@ pub fn TorrentList(torrents: Signal>) -> impl IntoView { "Name" - "%" + "Progress" "DL/s" "UP/s" - "DL" - "UP" "SD" "LE" @@ -59,13 +55,42 @@ pub fn TorrentSummary(torrent: Torrent) -> impl IntoView { view! { {move || name()} - {move || progress()} + {move || dlspeed()} {move || upspeed()} - {move || downloaded()} - {move || uploaded()} {move || torrent.num_seeds.get()} {move || torrent.num_leechs.get()} } } + +#[component] +fn Progress( + downloaded: RwSignal, + progress: RwSignal, + size: RwSignal, + total_size: RwSignal, +) -> impl IntoView { + let percent_selected = move || size.get() / total_size.get(); + let inner_bar_w = move || (percent_selected() * 150.0).ceil(); + let percent_complete = + move || (progress.get().min(1.0) * percent_selected().min(1.0) * 150.0) - 8.0; + + Effect::new(move |_| { + tracing::info!("percent = {:?}", progress.get()); + }); + + view! { +
+
+
+
""
+
+
+
+
{move || human_bytes(downloaded.get())}
+
{move || human_bytes(total_size.get())}
+
+
+ } +} diff --git a/qbittorrent_rs_sse/src/signals.rs b/qbittorrent_rs_sse/src/signals.rs index 31d8a71..6492e7e 100644 --- a/qbittorrent_rs_sse/src/signals.rs +++ b/qbittorrent_rs_sse/src/signals.rs @@ -36,6 +36,8 @@ pub struct Torrent { pub upspeed: RwSignal, pub num_seeds: RwSignal, pub num_leechs: RwSignal, + pub size: RwSignal, + pub total_size: RwSignal, } impl From for Torrent { @@ -50,6 +52,8 @@ impl From for Torrent { upspeed: RwSignal::new(value.upspeed), num_seeds: RwSignal::new(value.num_seeds), num_leechs: RwSignal::new(value.num_leechs), + size: RwSignal::new(value.size), + total_size: RwSignal::new(value.total_size), } } } @@ -79,6 +83,12 @@ impl Torrent { if let Some(new_value) = partial.num_leechs { self.num_leechs.set(new_value); } + if let Some(new_value) = partial.size { + self.size.set(new_value); + } + if let Some(new_value) = partial.total_size { + self.total_size.set(new_value); + } } }