chore(frontend): remove unused imports and variables

This commit is contained in:
spinline
2026-02-03 22:30:43 +03:00
parent f7d6ddb7a9
commit 8f16265107
2 changed files with 121 additions and 89 deletions

View File

@@ -1,5 +1,4 @@
use leptos::*; use leptos::*;
use wasm_bindgen::JsCast;
#[component] #[component]
pub fn StatusBar() -> impl IntoView { pub fn StatusBar() -> impl IntoView {

View File

@@ -2,16 +2,17 @@ use leptos::*;
use wasm_bindgen::closure::Closure; use wasm_bindgen::closure::Closure;
use wasm_bindgen::JsCast; use wasm_bindgen::JsCast;
fn format_bytes(bytes: i64) -> String { fn format_bytes(bytes: i64) -> String {
const UNITS: [&str; 6] = ["B", "KB", "MB", "GB", "TB", "PB"]; const UNITS: [&str; 6] = ["B", "KB", "MB", "GB", "TB", "PB"];
if bytes < 1024 { if bytes < 1024 {
return format!("{} B", bytes); return format!("{} B", bytes);
} }
let i = (bytes as f64).log2().div_euclid(10.0) as usize; let i = (bytes as f64).log2().div_euclid(10.0) as usize;
format!("{:.1} {}", (bytes as f64) / 1024_f64.powi(i as i32), UNITS[i]) format!(
"{:.1} {}",
(bytes as f64) / 1024_f64.powi(i as i32),
UNITS[i]
)
} }
fn format_speed(bytes_per_sec: i64) -> String { fn format_speed(bytes_per_sec: i64) -> String {
@@ -46,17 +47,31 @@ pub fn TorrentTable() -> impl IntoView {
let sort_dir = create_rw_signal(SortDirection::Ascending); let sort_dir = create_rw_signal(SortDirection::Ascending);
let filtered_torrents = move || { let filtered_torrents = move || {
let mut torrents = store.torrents.get().into_iter().filter(|t| { let mut torrents = store
.torrents
.get()
.into_iter()
.filter(|t| {
let filter = store.filter.get(); let filter = store.filter.get();
let search = store.search_query.get().to_lowercase(); let search = store.search_query.get().to_lowercase();
let matches_filter = match filter { let matches_filter = match filter {
crate::store::FilterStatus::All => true, crate::store::FilterStatus::All => true,
crate::store::FilterStatus::Downloading => t.status == shared::TorrentStatus::Downloading, crate::store::FilterStatus::Downloading => {
crate::store::FilterStatus::Seeding => t.status == shared::TorrentStatus::Seeding, t.status == shared::TorrentStatus::Downloading
crate::store::FilterStatus::Completed => t.status == shared::TorrentStatus::Seeding || t.status == shared::TorrentStatus::Paused, // Approximate }
crate::store::FilterStatus::Inactive => t.status == shared::TorrentStatus::Paused || t.status == shared::TorrentStatus::Error, crate::store::FilterStatus::Seeding => {
_ => true t.status == shared::TorrentStatus::Seeding
}
crate::store::FilterStatus::Completed => {
t.status == shared::TorrentStatus::Seeding
|| t.status == shared::TorrentStatus::Paused
} // Approximate
crate::store::FilterStatus::Inactive => {
t.status == shared::TorrentStatus::Paused
|| t.status == shared::TorrentStatus::Error
}
_ => true,
}; };
let matches_search = if search.is_empty() { let matches_search = if search.is_empty() {
@@ -66,7 +81,8 @@ pub fn TorrentTable() -> impl IntoView {
}; };
matches_filter && matches_search matches_filter && matches_search
}).collect::<Vec<_>>(); })
.collect::<Vec<_>>();
torrents.sort_by(|a, b| { torrents.sort_by(|a, b| {
let col = sort_col.get(); let col = sort_col.get();
@@ -74,7 +90,10 @@ pub fn TorrentTable() -> impl IntoView {
let cmp = match col { let cmp = match col {
SortColumn::Name => a.name.to_lowercase().cmp(&b.name.to_lowercase()), SortColumn::Name => a.name.to_lowercase().cmp(&b.name.to_lowercase()),
SortColumn::Size => a.size.cmp(&b.size), SortColumn::Size => a.size.cmp(&b.size),
SortColumn::Progress => a.percent_complete.partial_cmp(&b.percent_complete).unwrap_or(std::cmp::Ordering::Equal), SortColumn::Progress => a
.percent_complete
.partial_cmp(&b.percent_complete)
.unwrap_or(std::cmp::Ordering::Equal),
SortColumn::Status => format!("{:?}", a.status).cmp(&format!("{:?}", b.status)), SortColumn::Status => format!("{:?}", a.status).cmp(&format!("{:?}", b.status)),
SortColumn::DownSpeed => a.down_rate.cmp(&b.down_rate), SortColumn::DownSpeed => a.down_rate.cmp(&b.down_rate),
SortColumn::UpSpeed => a.up_rate.cmp(&b.up_rate), SortColumn::UpSpeed => a.up_rate.cmp(&b.up_rate),
@@ -89,7 +108,11 @@ pub fn TorrentTable() -> impl IntoView {
a_eta.cmp(&b_eta) a_eta.cmp(&b_eta)
} }
}; };
if dir == SortDirection::Descending { cmp.reverse() } else { cmp } if dir == SortDirection::Descending {
cmp.reverse()
} else {
cmp
}
}); });
torrents torrents
@@ -97,9 +120,11 @@ pub fn TorrentTable() -> impl IntoView {
let handle_sort = move |col: SortColumn| { let handle_sort = move |col: SortColumn| {
if sort_col.get() == col { if sort_col.get() == col {
sort_dir.update(|d| *d = match d { sort_dir.update(|d| {
*d = match d {
SortDirection::Ascending => SortDirection::Descending, SortDirection::Ascending => SortDirection::Descending,
SortDirection::Descending => SortDirection::Ascending, SortDirection::Descending => SortDirection::Ascending,
}
}); });
} else { } else {
sort_col.set(col); sort_col.set(col);
@@ -110,11 +135,16 @@ pub fn TorrentTable() -> impl IntoView {
let sort_arrow = move |col: SortColumn| { let sort_arrow = move |col: SortColumn| {
if sort_col.get() == col { if sort_col.get() == col {
match sort_dir.get() { match sort_dir.get() {
SortDirection::Ascending => view!{ <span class="ml-1 text-xs">""</span> }.into_view(), SortDirection::Ascending => {
SortDirection::Descending => view!{ <span class="ml-1 text-xs">""</span> }.into_view(), view! { <span class="ml-1 text-xs">""</span> }.into_view()
}
SortDirection::Descending => {
view! { <span class="ml-1 text-xs">""</span> }.into_view()
}
} }
} else { } else {
view!{ <span class="ml-1 text-xs opacity-0 group-hover:opacity-50">""</span> }.into_view() view! { <span class="ml-1 text-xs opacity-0 group-hover:opacity-50">""</span> }
.into_view()
} }
}; };
@@ -134,29 +164,34 @@ pub fn TorrentTable() -> impl IntoView {
set_menu_visible.set(false); // Close menu immediately set_menu_visible.set(false); // Close menu immediately
spawn_local(async move { spawn_local(async move {
let action_req = if action == "delete_with_data" { "delete_with_data" } else { &action }; let action_req = if action == "delete_with_data" {
"delete_with_data"
} else {
&action
};
let req_body = shared::TorrentActionRequest { let req_body = shared::TorrentActionRequest {
hash: hash.clone(), hash: hash.clone(),
action: action_req.to_string(), action: action_req.to_string(),
}; };
let client = gloo_net::http::Request::post("/api/torrents/action") let client = gloo_net::http::Request::post("/api/torrents/action").json(&req_body);
.json(&req_body);
match client { match client {
Ok(req) => { Ok(req) => match req.send().await {
match req.send().await {
Ok(resp) => { Ok(resp) => {
if !resp.ok() { if !resp.ok() {
logging::error!("Failed to execute action: {} {}", resp.status(), resp.status_text()); logging::error!(
"Failed to execute action: {} {}",
resp.status(),
resp.status_text()
);
} else { } else {
logging::log!("Action {} executed successfully", action); logging::log!("Action {} executed successfully", action);
} }
} }
Err(e) => logging::error!("Network error executing action: {}", e), Err(e) => logging::error!("Network error executing action: {}", e),
} },
}
Err(e) => logging::error!("Failed to serialize request: {}", e), Err(e) => logging::error!("Failed to serialize request: {}", e),
} }
}); });
@@ -264,9 +299,7 @@ pub fn TorrentTable() -> impl IntoView {
// We don't need t_hash_click separately if we use t_hash, but existing pattern uses clones // We don't need t_hash_click separately if we use t_hash, but existing pattern uses clones
let t_hash_click = t.hash.clone(); let t_hash_click = t.hash.clone();
let is_selected_fn = move || {
selected_hash.get() == Some(t_hash.clone())
};
// Long press logic // Long press logic
let (timer_id, set_timer_id) = create_signal(Option::<i32>::None); let (timer_id, set_timer_id) = create_signal(Option::<i32>::None);