Compare commits
2 Commits
release-20
...
release-20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e23585dfea | ||
|
|
9d5092649f |
@@ -21,7 +21,7 @@ wasm-bindgen = "0.2"
|
||||
wasm-bindgen-futures = "0.4"
|
||||
uuid = { version = "1", features = ["v4", "js"] }
|
||||
futures = "0.3"
|
||||
chrono = { version = "0.4", features = ["serde", "wasm-bindgen"] }
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
web-sys = { version = "0.3", features = [
|
||||
"HtmlDivElement",
|
||||
"HtmlUListElement",
|
||||
|
||||
@@ -46,11 +46,19 @@ 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(),
|
||||
if timestamp <= 0 {
|
||||
return "-".to_string();
|
||||
}
|
||||
let date = js_sys::Date::new(&wasm_bindgen::JsValue::from_f64((timestamp * 1000) as f64));
|
||||
|
||||
// Simple formatting: YYYY-MM-DD HH:mm
|
||||
let year = date.get_full_year();
|
||||
let month = date.get_month() + 1; // 0-based
|
||||
let day = date.get_date();
|
||||
let hours = date.get_hours();
|
||||
let minutes = date.get_minutes();
|
||||
|
||||
format!("{:04}-{:02}-{:02} {:02}:{:02}", year, month, day, hours, minutes)
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
@@ -62,7 +70,7 @@ enum SortColumn {
|
||||
DownSpeed,
|
||||
UpSpeed,
|
||||
ETA,
|
||||
AddedDate,
|
||||
Added,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
@@ -75,7 +83,7 @@ enum SortDirection {
|
||||
pub fn TorrentTable() -> impl IntoView {
|
||||
let store = use_context::<crate::store::TorrentStore>().expect("store not provided");
|
||||
|
||||
let sort_col = create_rw_signal(SortColumn::AddedDate);
|
||||
let sort_col = create_rw_signal(SortColumn::Added);
|
||||
let sort_dir = create_rw_signal(SortDirection::Descending);
|
||||
|
||||
let filtered_torrents = move || {
|
||||
@@ -136,7 +144,7 @@ pub fn TorrentTable() -> impl IntoView {
|
||||
let b_eta = if b.eta <= 0 { i64::MAX } else { b.eta };
|
||||
a_eta.cmp(&b_eta)
|
||||
}
|
||||
SortColumn::AddedDate => a.added_date.cmp(&b.added_date),
|
||||
SortColumn::Added => a.added_date.cmp(&b.added_date),
|
||||
};
|
||||
if dir == SortDirection::Descending {
|
||||
cmp.reverse()
|
||||
@@ -274,8 +282,8 @@ 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)>
|
||||
<div class="flex items-center">"ETA" {move || sort_arrow(SortColumn::ETA)}</div>
|
||||
</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 class="w-32 cursor-pointer hover:bg-base-300 group select-none" on:click=move |_| handle_sort(SortColumn::Added)>
|
||||
<div class="flex items-center">"Added" {move || sort_arrow(SortColumn::Added)}</div>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -330,7 +338,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-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 whitespace-nowrap">{format_date(t.added_date)}</td>
|
||||
<td class="text-right font-mono text-[11px] opacity-60 whitespace-nowrap">{format_date(t.added_date)}</td>
|
||||
</tr>
|
||||
}
|
||||
}).collect::<Vec<_>>()}
|
||||
@@ -338,84 +346,85 @@ pub fn TorrentTable() -> impl IntoView {
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="md:hidden flex flex-col h-full bg-base-200 relative">
|
||||
// Transparent overlay to close sort dropdown
|
||||
<Show when=move || sort_open.get()>
|
||||
<div
|
||||
class="fixed inset-0 z-[98] cursor-default"
|
||||
on:pointerdown=move |_| set_sort_open.set(false)
|
||||
></div>
|
||||
</Show>
|
||||
<div class="md:hidden flex flex-col h-full bg-base-200 relative">
|
||||
// Transparent overlay to close sort dropdown
|
||||
<Show when=move || sort_open.get()>
|
||||
<div
|
||||
class="fixed inset-0 z-[98] cursor-default"
|
||||
on:pointerdown=move |_| set_sort_open.set(false)
|
||||
></div>
|
||||
</Show>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
|
||||
<div class="relative">
|
||||
<div
|
||||
role="button"
|
||||
class="btn btn-ghost btn-xs gap-1 opacity-70 font-normal"
|
||||
on:pointerdown=move |e| {
|
||||
e.stop_propagation();
|
||||
let cur = sort_open.get_untracked();
|
||||
set_sort_open.set(!cur);
|
||||
}
|
||||
>
|
||||
<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">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M3 7.5L7.5 3m0 0L12 7.5M7.5 3v13.5m13.5 0L16.5 21m0 0L12 16.5m4.5 4.5V7.5" />
|
||||
</svg>
|
||||
"Sort"
|
||||
</div>
|
||||
<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"
|
||||
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>
|
||||
{
|
||||
let columns = vec![
|
||||
(SortColumn::Name, "Name"),
|
||||
(SortColumn::Size, "Size"),
|
||||
(SortColumn::Progress, "Progress"),
|
||||
(SortColumn::Status, "Status"),
|
||||
(SortColumn::DownSpeed, "Down Speed"),
|
||||
(SortColumn::UpSpeed, "Up Speed"),
|
||||
(SortColumn::ETA, "ETA"),
|
||||
(SortColumn::AddedDate, "Date"),
|
||||
];
|
||||
<div class="relative">
|
||||
<div
|
||||
role="button"
|
||||
class="btn btn-ghost btn-xs gap-1 opacity-70 font-normal"
|
||||
on:pointerdown=move |e| {
|
||||
e.stop_propagation();
|
||||
let cur = sort_open.get_untracked();
|
||||
set_sort_open.set(!cur);
|
||||
}
|
||||
>
|
||||
<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">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M3 7.5L7.5 3m0 0L12 7.5M7.5 3v13.5m13.5 0L16.5 21m0 0L12 16.5m4.5 4.5V7.5" />
|
||||
</svg>
|
||||
"Sort"
|
||||
</div>
|
||||
<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"
|
||||
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>
|
||||
{
|
||||
let columns = vec![
|
||||
(SortColumn::Added, "Date Added"),
|
||||
(SortColumn::Name, "Name"),
|
||||
(SortColumn::Size, "Size"),
|
||||
(SortColumn::Progress, "Progress"),
|
||||
(SortColumn::Status, "Status"),
|
||||
(SortColumn::DownSpeed, "Down Speed"),
|
||||
(SortColumn::UpSpeed, "Up Speed"),
|
||||
(SortColumn::ETA, "ETA"),
|
||||
];
|
||||
|
||||
columns.into_iter().map(|(col, label)| {
|
||||
let is_active = move || sort_col.get() == col;
|
||||
let current_dir = move || sort_dir.get();
|
||||
columns.into_iter().map(|(col, label)| {
|
||||
let is_active = move || sort_col.get() == col;
|
||||
let current_dir = move || sort_dir.get();
|
||||
|
||||
view! {
|
||||
<li>
|
||||
<button
|
||||
class=move || if is_active() { "bg-primary/10 text-primary font-bold flex justify-between" } else { "flex justify-between" }
|
||||
on:pointerdown=move |e| {
|
||||
e.stop_propagation();
|
||||
handle_sort(col);
|
||||
set_sort_open.set(false);
|
||||
}
|
||||
>
|
||||
{label}
|
||||
<Show when=is_active fallback=|| ()>
|
||||
<span class="opacity-70 text-[10px]">
|
||||
{move || match current_dir() {
|
||||
SortDirection::Ascending => "▲",
|
||||
SortDirection::Descending => "▼",
|
||||
}}
|
||||
</span>
|
||||
</Show>
|
||||
</button>
|
||||
</li>
|
||||
view! {
|
||||
<li>
|
||||
<button
|
||||
class=move || if is_active() { "bg-primary/10 text-primary font-bold flex justify-between" } else { "flex justify-between" }
|
||||
on:pointerdown=move |e| {
|
||||
e.stop_propagation();
|
||||
handle_sort(col);
|
||||
set_sort_open.set(false);
|
||||
}
|
||||
}).collect::<Vec<_>>()
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
>
|
||||
{label}
|
||||
<Show when=is_active fallback=|| ()>
|
||||
<span class="opacity-70 text-[10px]">
|
||||
{move || match current_dir() {
|
||||
SortDirection::Ascending => "▲",
|
||||
SortDirection::Descending => "▼",
|
||||
}}
|
||||
</span>
|
||||
</Show>
|
||||
</button>
|
||||
</li>
|
||||
}
|
||||
}).collect::<Vec<_>>()
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="overflow-y-auto p-3 pb-20 flex-1 grid grid-cols-1 content-start gap-3"> {move || filtered_torrents().into_iter().map(|t| {
|
||||
<div class="overflow-y-auto p-3 pb-20 flex-1 grid grid-cols-1 content-start gap-3">
|
||||
{move || filtered_torrents().into_iter().map(|t| {
|
||||
let progress_class = if t.percent_complete >= 100.0 { "progress-success" } else { "progress-primary" };
|
||||
let status_str = format!("{:?}", t.status);
|
||||
let status_badge_class = match t.status {
|
||||
@@ -515,7 +524,7 @@ pub fn TorrentTable() -> impl IntoView {
|
||||
<progress class={format!("progress w-full h-1.5 {}", progress_class)} value={t.percent_complete} max="100"></progress>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-4 gap-2 text-[10px] font-mono opacity-80 pt-1 border-t border-base-200/50">
|
||||
<div class="grid grid-cols-3 gap-2 text-[10px] font-mono opacity-80 pt-1 border-t border-base-200/50">
|
||||
<div class="flex flex-col">
|
||||
<span class="text-[9px] opacity-60 uppercase">"Down"</span>
|
||||
<span class="text-success">{format_speed(t.down_rate)}</span>
|
||||
@@ -524,14 +533,10 @@ pub fn TorrentTable() -> impl IntoView {
|
||||
<span class="text-[9px] opacity-60 uppercase">"Up"</span>
|
||||
<span class="text-primary">{format_speed(t.up_rate)}</span>
|
||||
</div>
|
||||
<div class="flex flex-col text-center border-r border-base-200/50">
|
||||
<div class="flex flex-col text-right">
|
||||
<span class="text-[9px] opacity-60 uppercase">"ETA"</span>
|
||||
<span>{format_duration(t.eta)}</span>
|
||||
</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>
|
||||
|
||||
Reference in New Issue
Block a user