Compare commits
3 Commits
release-20
...
release-20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab49c2ded5 | ||
|
|
e4957e930d | ||
|
|
ad2c6dc56e |
@@ -21,7 +21,7 @@ wasm-bindgen = "0.2"
|
|||||||
wasm-bindgen-futures = "0.4"
|
wasm-bindgen-futures = "0.4"
|
||||||
uuid = { version = "1", features = ["v4", "js"] }
|
uuid = { version = "1", features = ["v4", "js"] }
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde", "wasm-bindgen"] }
|
||||||
web-sys = { version = "0.3", features = [
|
web-sys = { version = "0.3", features = [
|
||||||
"HtmlDivElement",
|
"HtmlDivElement",
|
||||||
"HtmlUListElement",
|
"HtmlUListElement",
|
||||||
|
|||||||
@@ -45,6 +45,14 @@ fn format_duration(seconds: i64) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn format_date(timestamp: i64) -> String {
|
||||||
|
let dt = chrono::DateTime::from_timestamp(timestamp, 0);
|
||||||
|
match dt {
|
||||||
|
Some(dt) => dt.format("%d/%m/%Y %H:%M").to_string(),
|
||||||
|
None => "N/A".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
enum SortColumn {
|
enum SortColumn {
|
||||||
Name,
|
Name,
|
||||||
@@ -54,6 +62,7 @@ enum SortColumn {
|
|||||||
DownSpeed,
|
DownSpeed,
|
||||||
UpSpeed,
|
UpSpeed,
|
||||||
ETA,
|
ETA,
|
||||||
|
AddedDate,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
@@ -66,8 +75,8 @@ enum SortDirection {
|
|||||||
pub fn TorrentTable() -> impl IntoView {
|
pub fn TorrentTable() -> 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 sort_col = create_rw_signal(SortColumn::Name);
|
let sort_col = create_rw_signal(SortColumn::AddedDate);
|
||||||
let sort_dir = create_rw_signal(SortDirection::Ascending);
|
let sort_dir = create_rw_signal(SortDirection::Descending);
|
||||||
|
|
||||||
let filtered_torrents = move || {
|
let filtered_torrents = move || {
|
||||||
let mut torrents = store
|
let mut torrents = store
|
||||||
@@ -127,6 +136,7 @@ pub fn TorrentTable() -> impl IntoView {
|
|||||||
let b_eta = if b.eta <= 0 { i64::MAX } else { b.eta };
|
let b_eta = if b.eta <= 0 { i64::MAX } else { b.eta };
|
||||||
a_eta.cmp(&b_eta)
|
a_eta.cmp(&b_eta)
|
||||||
}
|
}
|
||||||
|
SortColumn::AddedDate => a.added_date.cmp(&b.added_date),
|
||||||
};
|
};
|
||||||
if dir == SortDirection::Descending {
|
if dir == SortDirection::Descending {
|
||||||
cmp.reverse()
|
cmp.reverse()
|
||||||
@@ -264,6 +274,9 @@ pub fn TorrentTable() -> impl IntoView {
|
|||||||
<th class="w-24 cursor-pointer hover:bg-base-300 group select-none" on:click=move |_| handle_sort(SortColumn::ETA)>
|
<th class="w-24 cursor-pointer hover:bg-base-300 group select-none" on:click=move |_| handle_sort(SortColumn::ETA)>
|
||||||
<div class="flex items-center">"ETA" {move || sort_arrow(SortColumn::ETA)}</div>
|
<div class="flex items-center">"ETA" {move || sort_arrow(SortColumn::ETA)}</div>
|
||||||
</th>
|
</th>
|
||||||
|
<th class="w-32 cursor-pointer hover:bg-base-300 group select-none" on:click=move |_| handle_sort(SortColumn::AddedDate)>
|
||||||
|
<div class="flex items-center">"Date" {move || sort_arrow(SortColumn::AddedDate)}</div>
|
||||||
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -317,6 +330,7 @@ pub fn TorrentTable() -> impl IntoView {
|
|||||||
<td class="text-right font-mono text-[11px] opacity-80 text-success">{format_speed(t.down_rate)}</td>
|
<td class="text-right font-mono text-[11px] opacity-80 text-success">{format_speed(t.down_rate)}</td>
|
||||||
<td class="text-right font-mono text-[11px] opacity-80 text-primary">{format_speed(t.up_rate)}</td>
|
<td class="text-right font-mono text-[11px] opacity-80 text-primary">{format_speed(t.up_rate)}</td>
|
||||||
<td class="text-right font-mono text-[11px] opacity-80">{format_duration(t.eta)}</td>
|
<td class="text-right font-mono text-[11px] opacity-80">{format_duration(t.eta)}</td>
|
||||||
|
<td class="text-right font-mono text-[11px] opacity-80 whitespace-nowrap">{format_date(t.added_date)}</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
}).collect::<Vec<_>>()}
|
}).collect::<Vec<_>>()}
|
||||||
@@ -354,7 +368,6 @@ pub fn TorrentTable() -> impl IntoView {
|
|||||||
<ul
|
<ul
|
||||||
class="absolute top-full right-0 z-[100] menu p-2 shadow bg-base-100 rounded-box w-48 mt-1 border border-base-200 text-xs"
|
class="absolute top-full right-0 z-[100] menu p-2 shadow bg-base-100 rounded-box w-48 mt-1 border border-base-200 text-xs"
|
||||||
style=move || if sort_open.get() { "display: block" } else { "display: none" }
|
style=move || if sort_open.get() { "display: block" } else { "display: none" }
|
||||||
on:pointerdown=move |e| e.stop_propagation()
|
|
||||||
>
|
>
|
||||||
<li class="menu-title px-2 py-1 opacity-50 text-[10px] uppercase font-bold">"Sort By"</li>
|
<li class="menu-title px-2 py-1 opacity-50 text-[10px] uppercase font-bold">"Sort By"</li>
|
||||||
{
|
{
|
||||||
@@ -366,6 +379,7 @@ pub fn TorrentTable() -> impl IntoView {
|
|||||||
(SortColumn::DownSpeed, "Down Speed"),
|
(SortColumn::DownSpeed, "Down Speed"),
|
||||||
(SortColumn::UpSpeed, "Up Speed"),
|
(SortColumn::UpSpeed, "Up Speed"),
|
||||||
(SortColumn::ETA, "ETA"),
|
(SortColumn::ETA, "ETA"),
|
||||||
|
(SortColumn::AddedDate, "Date"),
|
||||||
];
|
];
|
||||||
|
|
||||||
columns.into_iter().map(|(col, label)| {
|
columns.into_iter().map(|(col, label)| {
|
||||||
@@ -500,7 +514,7 @@ pub fn TorrentTable() -> impl IntoView {
|
|||||||
<progress class={format!("progress w-full h-1.5 {}", progress_class)} value={t.percent_complete} max="100"></progress>
|
<progress class={format!("progress w-full h-1.5 {}", progress_class)} value={t.percent_complete} max="100"></progress>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid grid-cols-3 gap-2 text-[10px] font-mono opacity-80 pt-1 border-t border-base-200/50">
|
<div class="grid grid-cols-4 gap-2 text-[10px] font-mono opacity-80 pt-1 border-t border-base-200/50">
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<span class="text-[9px] opacity-60 uppercase">"Down"</span>
|
<span class="text-[9px] opacity-60 uppercase">"Down"</span>
|
||||||
<span class="text-success">{format_speed(t.down_rate)}</span>
|
<span class="text-success">{format_speed(t.down_rate)}</span>
|
||||||
@@ -509,10 +523,14 @@ pub fn TorrentTable() -> impl IntoView {
|
|||||||
<span class="text-[9px] opacity-60 uppercase">"Up"</span>
|
<span class="text-[9px] opacity-60 uppercase">"Up"</span>
|
||||||
<span class="text-primary">{format_speed(t.up_rate)}</span>
|
<span class="text-primary">{format_speed(t.up_rate)}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col text-right">
|
<div class="flex flex-col text-center border-r border-base-200/50">
|
||||||
<span class="text-[9px] opacity-60 uppercase">"ETA"</span>
|
<span class="text-[9px] opacity-60 uppercase">"ETA"</span>
|
||||||
<span>{format_duration(t.eta)}</span>
|
<span>{format_duration(t.eta)}</span>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex flex-col text-right">
|
||||||
|
<span class="text-[9px] opacity-60 uppercase">"Date"</span>
|
||||||
|
<span>{format_date(t.added_date)}</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user