fix(logic): exclude incomplete paused torrents from completed filter
This commit is contained in:
@@ -1,15 +1,49 @@
|
|||||||
use leptos::*;
|
|
||||||
use leptos::wasm_bindgen::JsCast;
|
use leptos::wasm_bindgen::JsCast;
|
||||||
|
use leptos::*;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Sidebar() -> impl IntoView {
|
pub fn Sidebar() -> impl IntoView {
|
||||||
let store = use_context::<crate::store::TorrentStore>().expect("store not provided");
|
let store = use_context::<crate::store::TorrentStore>().expect("store not provided");
|
||||||
|
|
||||||
let total_count = move || store.torrents.get().len();
|
let total_count = move || store.torrents.get().len();
|
||||||
let downloading_count = move || store.torrents.get().iter().filter(|t| t.status == shared::TorrentStatus::Downloading).count();
|
let downloading_count = move || {
|
||||||
let seeding_count = move || store.torrents.get().iter().filter(|t| t.status == shared::TorrentStatus::Seeding).count();
|
store
|
||||||
let completed_count = move || store.torrents.get().iter().filter(|t| t.status == shared::TorrentStatus::Seeding || t.status == shared::TorrentStatus::Paused).count();
|
.torrents
|
||||||
let inactive_count = move || store.torrents.get().iter().filter(|t| t.status == shared::TorrentStatus::Paused || t.status == shared::TorrentStatus::Error).count();
|
.get()
|
||||||
|
.iter()
|
||||||
|
.filter(|t| t.status == shared::TorrentStatus::Downloading)
|
||||||
|
.count()
|
||||||
|
};
|
||||||
|
let seeding_count = move || {
|
||||||
|
store
|
||||||
|
.torrents
|
||||||
|
.get()
|
||||||
|
.iter()
|
||||||
|
.filter(|t| t.status == shared::TorrentStatus::Seeding)
|
||||||
|
.count()
|
||||||
|
};
|
||||||
|
let completed_count = move || {
|
||||||
|
store
|
||||||
|
.torrents
|
||||||
|
.get()
|
||||||
|
.iter()
|
||||||
|
.filter(|t| {
|
||||||
|
t.status == shared::TorrentStatus::Seeding
|
||||||
|
|| (t.status == shared::TorrentStatus::Paused && t.percent_complete >= 100.0)
|
||||||
|
})
|
||||||
|
.count()
|
||||||
|
};
|
||||||
|
let inactive_count = move || {
|
||||||
|
store
|
||||||
|
.torrents
|
||||||
|
.get()
|
||||||
|
.iter()
|
||||||
|
.filter(|t| {
|
||||||
|
t.status == shared::TorrentStatus::Paused
|
||||||
|
|| t.status == shared::TorrentStatus::Error
|
||||||
|
})
|
||||||
|
.count()
|
||||||
|
};
|
||||||
|
|
||||||
let close_drawer = move || {
|
let close_drawer = move || {
|
||||||
if let Some(element) = document().get_element_by_id("my-drawer") {
|
if let Some(element) = document().get_element_by_id("my-drawer") {
|
||||||
@@ -25,7 +59,11 @@ pub fn Sidebar() -> impl IntoView {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let filter_class = move |f: crate::store::FilterStatus| {
|
let filter_class = move |f: crate::store::FilterStatus| {
|
||||||
if store.filter.get() == f { "active" } else { "" }
|
if store.filter.get() == f {
|
||||||
|
"active"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
@@ -80,7 +118,7 @@ pub fn Sidebar() -> impl IntoView {
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,8 @@ pub fn TorrentTable() -> impl IntoView {
|
|||||||
}
|
}
|
||||||
crate::store::FilterStatus::Completed => {
|
crate::store::FilterStatus::Completed => {
|
||||||
t.status == shared::TorrentStatus::Seeding
|
t.status == shared::TorrentStatus::Seeding
|
||||||
|| t.status == shared::TorrentStatus::Paused
|
|| (t.status == shared::TorrentStatus::Paused
|
||||||
|
&& t.percent_complete >= 100.0)
|
||||||
} // Approximate
|
} // Approximate
|
||||||
crate::store::FilterStatus::Inactive => {
|
crate::store::FilterStatus::Inactive => {
|
||||||
t.status == shared::TorrentStatus::Paused
|
t.status == shared::TorrentStatus::Paused
|
||||||
@@ -282,14 +283,14 @@ pub fn TorrentTable() -> impl IntoView {
|
|||||||
<div class="md:hidden flex flex-col h-full bg-base-100">
|
<div class="md:hidden flex flex-col h-full bg-base-100">
|
||||||
<div class="px-3 py-2 border-b border-base-200 flex justify-between items-center bg-base-100/95 backdrop-blur z-10 shrink-0">
|
<div class="px-3 py-2 border-b border-base-200 flex justify-between items-center bg-base-100/95 backdrop-blur z-10 shrink-0">
|
||||||
<span class="text-xs font-bold opacity-50 uppercase tracking-wider">"Torrents"</span>
|
<span class="text-xs font-bold opacity-50 uppercase tracking-wider">"Torrents"</span>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="dropdown dropdown-end"
|
class="dropdown dropdown-end"
|
||||||
on:touchstart=move |e| e.stop_propagation()
|
on:touchstart=move |e| e.stop_propagation()
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
role="button"
|
role="button"
|
||||||
class="btn btn-ghost btn-xs gap-1 opacity-70 font-normal"
|
class="btn btn-ghost btn-xs gap-1 opacity-70 font-normal"
|
||||||
>
|
>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4">
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4">
|
||||||
@@ -309,7 +310,7 @@ pub fn TorrentTable() -> impl IntoView {
|
|||||||
(SortColumn::UpSpeed, "Up Speed"),
|
(SortColumn::UpSpeed, "Up Speed"),
|
||||||
(SortColumn::ETA, "ETA"),
|
(SortColumn::ETA, "ETA"),
|
||||||
];
|
];
|
||||||
|
|
||||||
let close_dropdown = move || {
|
let close_dropdown = move || {
|
||||||
if let Some(doc) = web_sys::window().and_then(|w| w.document()) {
|
if let Some(doc) = web_sys::window().and_then(|w| w.document()) {
|
||||||
if let Some(active) = doc.active_element() {
|
if let Some(active) = doc.active_element() {
|
||||||
@@ -322,10 +323,10 @@ pub fn TorrentTable() -> impl IntoView {
|
|||||||
let is_active = move || sort_col.get() == col;
|
let is_active = move || sort_col.get() == col;
|
||||||
let current_dir = move || sort_dir.get();
|
let current_dir = move || sort_dir.get();
|
||||||
let close = close_dropdown.clone();
|
let close = close_dropdown.clone();
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<li>
|
<li>
|
||||||
<button
|
<button
|
||||||
class=move || if is_active() { "bg-primary/10 text-primary font-bold flex justify-between" } else { "flex justify-between" }
|
class=move || if is_active() { "bg-primary/10 text-primary font-bold flex justify-between" } else { "flex justify-between" }
|
||||||
on:click=move |_| {
|
on:click=move |_| {
|
||||||
handle_sort(col);
|
handle_sort(col);
|
||||||
@@ -394,7 +395,7 @@ pub fn TorrentTable() -> impl IntoView {
|
|||||||
let id = window()
|
let id = window()
|
||||||
.set_timeout_with_callback_and_timeout_and_arguments_0(
|
.set_timeout_with_callback_and_timeout_and_arguments_0(
|
||||||
closure.as_ref().unchecked_ref(),
|
closure.as_ref().unchecked_ref(),
|
||||||
600
|
600
|
||||||
)
|
)
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user