fix: Resolve UI reactivity issues by including name, status, and size in partial updates
This commit is contained in:
@@ -32,16 +32,27 @@ pub fn diff_torrents(old: &[Torrent], new: &[Torrent]) -> Vec<AppEvent> {
|
||||
|
||||
let mut update = TorrentUpdate {
|
||||
hash: new_t.hash.clone(),
|
||||
name: None,
|
||||
size: None,
|
||||
down_rate: None,
|
||||
up_rate: None,
|
||||
percent_complete: None,
|
||||
completed: None,
|
||||
eta: None,
|
||||
status: None,
|
||||
error_message: None,
|
||||
};
|
||||
|
||||
let mut has_changes = false;
|
||||
|
||||
if old_t.name != new_t.name {
|
||||
update.name = Some(new_t.name.clone());
|
||||
has_changes = true;
|
||||
}
|
||||
if old_t.size != new_t.size {
|
||||
update.size = Some(new_t.size);
|
||||
has_changes = true;
|
||||
}
|
||||
if old_t.down_rate != new_t.down_rate {
|
||||
update.down_rate = Some(new_t.down_rate);
|
||||
has_changes = true;
|
||||
@@ -67,6 +78,10 @@ pub fn diff_torrents(old: &[Torrent], new: &[Torrent]) -> Vec<AppEvent> {
|
||||
update.status = Some(new_t.status.clone());
|
||||
has_changes = true;
|
||||
}
|
||||
if old_t.error_message != new_t.error_message {
|
||||
update.error_message = Some(new_t.error_message.clone());
|
||||
has_changes = true;
|
||||
}
|
||||
|
||||
if has_changes {
|
||||
events.push(AppEvent::Update(update));
|
||||
|
||||
@@ -128,12 +128,15 @@ pub fn App() -> impl IntoView {
|
||||
AppEvent::Update(diff) => {
|
||||
set_torrents.update(|list| {
|
||||
if let Some(target) = list.iter_mut().find(|t| t.hash == diff.hash) {
|
||||
if let Some(v) = diff.name { target.name = v; }
|
||||
if let Some(v) = diff.size { target.size = v; }
|
||||
if let Some(v) = diff.down_rate { target.down_rate = v; }
|
||||
if let Some(v) = diff.up_rate { target.up_rate = v; }
|
||||
if let Some(v) = diff.percent_complete { target.percent_complete = v; }
|
||||
if let Some(v) = diff.completed { target.completed = v; }
|
||||
if let Some(v) = diff.eta { target.eta = v; }
|
||||
if let Some(v) = diff.status { target.status = v; }
|
||||
if let Some(v) = diff.error_message { target.error_message = v; }
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -435,8 +438,8 @@ pub fn App() -> impl IntoView {
|
||||
</thead>
|
||||
<tbody class={format!("divide-y {}", border)}>
|
||||
<For
|
||||
each=move || processed_torrents.get()
|
||||
key=|t| format!("{}-{}-{}-{}-{}-{}", t.hash, t.down_rate, t.up_rate, t.percent_complete, t.eta, t.error_message)
|
||||
each=move || processed_torrents.get()
|
||||
key=|t| format!("{}-{}-{:?}-{}-{}-{}-{}", t.hash, t.name, t.status, t.down_rate, t.up_rate, t.percent_complete, t.error_message)
|
||||
children=move |torrent| {
|
||||
let status_color = match torrent.status {
|
||||
TorrentStatus::Downloading => "text-blue-500 bg-blue-500/10 border-blue-500/20",
|
||||
@@ -515,7 +518,7 @@ pub fn App() -> impl IntoView {
|
||||
<div class="md:hidden space-y-4">
|
||||
<For
|
||||
each=move || processed_torrents.get()
|
||||
key=|t| format!("{}-{}-{}-{}-{}-{}", t.hash, t.down_rate, t.up_rate, t.percent_complete, t.eta, t.error_message)
|
||||
key=|t| format!("{}-{}-{:?}-{}-{}-{}-{}", t.hash, t.name, t.status, t.down_rate, t.up_rate, t.percent_complete, t.error_message)
|
||||
children=move |torrent| {
|
||||
let status_color = match torrent.status {
|
||||
TorrentStatus::Downloading => "text-blue-500",
|
||||
|
||||
@@ -35,12 +35,15 @@ pub enum AppEvent {
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct TorrentUpdate {
|
||||
pub hash: String,
|
||||
pub name: Option<String>,
|
||||
pub size: Option<i64>,
|
||||
pub down_rate: Option<i64>,
|
||||
pub up_rate: Option<i64>,
|
||||
pub percent_complete: Option<f64>,
|
||||
pub completed: Option<i64>,
|
||||
pub eta: Option<i64>,
|
||||
pub status: Option<TorrentStatus>,
|
||||
pub error_message: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
|
||||
Reference in New Issue
Block a user