From baab8a1984f2e13576cf0c240c1f7cae25769f1b Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Thu, 1 Jan 2026 04:00:36 +0200 Subject: [PATCH] fix: move torrent works with highlighted selection --- src/app/command.rs | 16 ++++++++++++++++ src/app/mod.rs | 8 ++++++-- src/app/torrent.rs | 12 +----------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/app/command.rs b/src/app/command.rs index 65ca612..9c3d7ed 100644 --- a/src/app/command.rs +++ b/src/app/command.rs @@ -107,6 +107,22 @@ impl Torrents { Ok(()) } + /// Move torrents to a new location. + /// + /// # Errors + /// + /// Returns an error if the RPC call fails. + pub async fn move_torrents(&mut self, ids: Selected, location: &str) -> Result<()> { + let ids: Vec = ids.into(); + if ids.is_empty() { + return Ok(()); + } + self.client + .torrent_set_location(ids, location.to_owned(), Some(true)) + .await?; + Ok(()) + } + /// Rename a torrent. /// /// # Errors diff --git a/src/app/mod.rs b/src/app/mod.rs index 4c5d3f1..a53640c 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -168,15 +168,19 @@ impl App { Ok(()) } + /// Move selected or highlighted torrent(s) to a new location. + /// /// # Errors /// - /// TODO: add error types + /// Returns an error if the RPC call fails. pub async fn move_torrent(&mut self) -> Result<()> { + let ids = self.selected(false); self.torrents - .move_selection(&self.input_handler.text) + .move_torrents(ids, &self.input_handler.text) .await?; self.input_handler.clear(); self.input_mode = false; + self.close_help(); Ok(()) } diff --git a/src/app/torrent.rs b/src/app/torrent.rs index 5ca906d..196ba5f 100644 --- a/src/app/torrent.rs +++ b/src/app/torrent.rs @@ -2,7 +2,7 @@ use crate::{app::constants::DEFAULT_RPC_URL, error::Result}; use std::{collections::HashSet, fmt::Debug}; use transmission_rpc::{ TransClient, - types::{Id, Torrent, TorrentGetField}, + types::{Torrent, TorrentGetField}, }; use url::Url; @@ -76,16 +76,6 @@ impl Torrents { Ok(self) } - /// # Errors - /// - /// TODO: add error types - pub async fn move_selection(&mut self, location: &str) -> Result<()> { - let ids: Vec = self.selected.iter().map(|id| Id::Id(*id)).collect(); - self.client - .torrent_set_location(ids, location.to_string(), Some(true)) - .await?; - Ok(()) - } } impl Debug for Torrents {