fix: move torrent works with highlighted selection

This commit is contained in:
Kristofers Solo 2026-01-01 04:00:36 +02:00
parent 3bbb1459f2
commit baab8a1984
Signed by: kristoferssolo
GPG Key ID: 8687F2D3EEE6F0ED
3 changed files with 23 additions and 13 deletions

View File

@ -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<Id> = 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

View File

@ -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(())
}

View File

@ -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<Id> = 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 {