diff --git a/frontend/src/components/torrent/table.rs b/frontend/src/components/torrent/table.rs index 302cb64..6166c85 100644 --- a/frontend/src/components/torrent/table.rs +++ b/frontend/src/components/torrent/table.rs @@ -24,25 +24,20 @@ fn format_speed(bytes_per_sec: i64) -> String { format!("{}/s", format_bytes(bytes_per_sec)) } -fn format_duration(seconds: i64) -> String { - if seconds <= 0 { - return "∞".to_string(); +fn format_date(timestamp: i64) -> String { + if timestamp <= 0 { + return "-".to_string(); } + let date = js_sys::Date::new(&wasm_bindgen::JsValue::from_f64((timestamp * 1000) as f64)); - let days = seconds / 86400; - let hours = (seconds % 86400) / 3600; - let minutes = (seconds % 3600) / 60; - let secs = seconds % 60; + // 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(); - if days > 0 { - format!("{}d {}h", days, hours) - } else if hours > 0 { - format!("{}h {}m", hours, minutes) - } else if minutes > 0 { - format!("{}m {}s", minutes, secs) - } else { - format!("{}s", secs) - } + format!("{:04}-{:02}-{:02} {:02}:{:02}", year, month, day, hours, minutes) } #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -54,6 +49,7 @@ enum SortColumn { DownSpeed, UpSpeed, ETA, + Added, } #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -66,8 +62,8 @@ enum SortDirection { pub fn TorrentTable() -> impl IntoView { let store = use_context::().expect("store not provided"); - let sort_col = create_rw_signal(SortColumn::Name); - let sort_dir = create_rw_signal(SortDirection::Ascending); + let sort_col = create_rw_signal(SortColumn::Added); + let sort_dir = create_rw_signal(SortDirection::Descending); let filtered_torrents = move || { let mut torrents = store @@ -127,6 +123,7 @@ pub fn TorrentTable() -> impl IntoView { let b_eta = if b.eta <= 0 { i64::MAX } else { b.eta }; a_eta.cmp(&b_eta) } + SortColumn::Added => a.added_date.cmp(&b.added_date), }; if dir == SortDirection::Descending { cmp.reverse() @@ -264,6 +261,9 @@ pub fn TorrentTable() -> impl IntoView {
"ETA" {move || sort_arrow(SortColumn::ETA)}
+ +
"Added" {move || sort_arrow(SortColumn::Added)}
+ @@ -317,6 +317,7 @@ pub fn TorrentTable() -> impl IntoView { {format_speed(t.down_rate)} {format_speed(t.up_rate)} {format_duration(t.eta)} + {format_date(t.added_date)} } }).collect::>()} @@ -359,6 +360,7 @@ pub fn TorrentTable() -> impl IntoView { { let columns = vec![ + (SortColumn::Added, "Date Added"), (SortColumn::Name, "Name"), (SortColumn::Size, "Size"), (SortColumn::Progress, "Progress"), @@ -398,9 +400,7 @@ pub fn TorrentTable() -> impl IntoView { } - - -
{move || filtered_torrents().into_iter().map(|t| { +
{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 {