Update default sort to Date Added (Descending) and display Added column
Some checks failed
Build MIPS Binary / build (push) Failing after 1m18s

This commit is contained in:
spinline
2026-02-07 20:16:30 +03:00
parent 9f009bc18b
commit 9d5092649f

View File

@@ -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::<crate::store::TorrentStore>().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 {
<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::Added)>
<div class="flex items-center">"Added" {move || sort_arrow(SortColumn::Added)}</div>
</th>
</tr>
</thead>
<tbody>
@@ -317,6 +317,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-60 whitespace-nowrap">{format_date(t.added_date)}</td>
</tr>
}
}).collect::<Vec<_>>()}
@@ -359,6 +360,7 @@ pub fn TorrentTable() -> impl IntoView {
<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"),
@@ -398,9 +400,7 @@ pub fn TorrentTable() -> impl IntoView {
}
</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> {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 {