chore(frontend): remove unused imports and variables
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use leptos::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
|
||||
#[component]
|
||||
pub fn StatusBar() -> impl IntoView {
|
||||
|
||||
@@ -2,16 +2,17 @@ use leptos::*;
|
||||
use wasm_bindgen::closure::Closure;
|
||||
use wasm_bindgen::JsCast;
|
||||
|
||||
|
||||
|
||||
|
||||
fn format_bytes(bytes: i64) -> String {
|
||||
const UNITS: [&str; 6] = ["B", "KB", "MB", "GB", "TB", "PB"];
|
||||
if bytes < 1024 {
|
||||
return format!("{} B", bytes);
|
||||
}
|
||||
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 {
|
||||
@@ -46,17 +47,31 @@ pub fn TorrentTable() -> impl IntoView {
|
||||
let sort_dir = create_rw_signal(SortDirection::Ascending);
|
||||
|
||||
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 search = store.search_query.get().to_lowercase();
|
||||
|
||||
let matches_filter = match filter {
|
||||
crate::store::FilterStatus::All => true,
|
||||
crate::store::FilterStatus::Downloading => t.status == shared::TorrentStatus::Downloading,
|
||||
crate::store::FilterStatus::Seeding => 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
|
||||
crate::store::FilterStatus::Downloading => {
|
||||
t.status == shared::TorrentStatus::Downloading
|
||||
}
|
||||
crate::store::FilterStatus::Seeding => {
|
||||
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() {
|
||||
@@ -66,7 +81,8 @@ pub fn TorrentTable() -> impl IntoView {
|
||||
};
|
||||
|
||||
matches_filter && matches_search
|
||||
}).collect::<Vec<_>>();
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
torrents.sort_by(|a, b| {
|
||||
let col = sort_col.get();
|
||||
@@ -74,7 +90,10 @@ pub fn TorrentTable() -> impl IntoView {
|
||||
let cmp = match col {
|
||||
SortColumn::Name => a.name.to_lowercase().cmp(&b.name.to_lowercase()),
|
||||
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::DownSpeed => a.down_rate.cmp(&b.down_rate),
|
||||
SortColumn::UpSpeed => a.up_rate.cmp(&b.up_rate),
|
||||
@@ -89,7 +108,11 @@ pub fn TorrentTable() -> impl IntoView {
|
||||
a_eta.cmp(&b_eta)
|
||||
}
|
||||
};
|
||||
if dir == SortDirection::Descending { cmp.reverse() } else { cmp }
|
||||
if dir == SortDirection::Descending {
|
||||
cmp.reverse()
|
||||
} else {
|
||||
cmp
|
||||
}
|
||||
});
|
||||
|
||||
torrents
|
||||
@@ -97,9 +120,11 @@ pub fn TorrentTable() -> impl IntoView {
|
||||
|
||||
let handle_sort = move |col: SortColumn| {
|
||||
if sort_col.get() == col {
|
||||
sort_dir.update(|d| *d = match d {
|
||||
sort_dir.update(|d| {
|
||||
*d = match d {
|
||||
SortDirection::Ascending => SortDirection::Descending,
|
||||
SortDirection::Descending => SortDirection::Ascending,
|
||||
}
|
||||
});
|
||||
} else {
|
||||
sort_col.set(col);
|
||||
@@ -110,11 +135,16 @@ pub fn TorrentTable() -> impl IntoView {
|
||||
let sort_arrow = move |col: SortColumn| {
|
||||
if sort_col.get() == col {
|
||||
match sort_dir.get() {
|
||||
SortDirection::Ascending => view!{ <span class="ml-1 text-xs">"▲"</span> }.into_view(),
|
||||
SortDirection::Descending => view!{ <span class="ml-1 text-xs">"▼"</span> }.into_view(),
|
||||
SortDirection::Ascending => {
|
||||
view! { <span class="ml-1 text-xs">"▲"</span> }.into_view()
|
||||
}
|
||||
SortDirection::Descending => {
|
||||
view! { <span class="ml-1 text-xs">"▼"</span> }.into_view()
|
||||
}
|
||||
}
|
||||
} 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
|
||||
|
||||
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 {
|
||||
hash: hash.clone(),
|
||||
action: action_req.to_string(),
|
||||
};
|
||||
|
||||
let client = gloo_net::http::Request::post("/api/torrents/action")
|
||||
.json(&req_body);
|
||||
let client = gloo_net::http::Request::post("/api/torrents/action").json(&req_body);
|
||||
|
||||
match client {
|
||||
Ok(req) => {
|
||||
match req.send().await {
|
||||
Ok(req) => match req.send().await {
|
||||
Ok(resp) => {
|
||||
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 {
|
||||
logging::log!("Action {} executed successfully", action);
|
||||
}
|
||||
}
|
||||
Err(e) => logging::error!("Network error executing action: {}", 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
|
||||
let t_hash_click = t.hash.clone();
|
||||
|
||||
let is_selected_fn = move || {
|
||||
selected_hash.get() == Some(t_hash.clone())
|
||||
};
|
||||
|
||||
|
||||
// Long press logic
|
||||
let (timer_id, set_timer_id) = create_signal(Option::<i32>::None);
|
||||
|
||||
Reference in New Issue
Block a user