From c56d9d6894c717b5c70ab75d6a100d4d1071c2d3 Mon Sep 17 00:00:00 2001 From: Matt Van Horn Date: Fri, 19 Jun 2026 11:42:48 -0700 Subject: [PATCH] fix(downloads): sort stalled torrents last when sorting by finish time (#6011) Stalled torrents have time=0 (infinite/never), which raw numeric sort places between negative (completed) and positive (active) values. Add a custom sortingFn on the time column that maps 0 to Infinity so stalled entries always sort last in ascending order and first in descending order. Closes #5416 Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> --- packages/widgets/src/downloads/component.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/widgets/src/downloads/component.tsx b/packages/widgets/src/downloads/component.tsx index bee31eb20..60e970c22 100644 --- a/packages/widgets/src/downloads/component.tsx +++ b/packages/widgets/src/downloads/component.tsx @@ -529,6 +529,16 @@ export default function DownloadClientsWidget({ }, { ...columnsDefBase({ key: "time", showHeader: true }), + sortingFn: (rowA, rowB) => { + const timeA = rowA.getValue("time"); + const timeB = rowB.getValue("time"); + // Map time values to canonical sort keys: + // positive = ETA in ms (sort as-is, smaller = sooner) + // 0 = stalled/infinite (sort last in ascending = Infinity) + // negative = time since completion in ms (sort first in ascending = very negative) + const toSortKey = (time: number) => (time === 0 ? Infinity : time); + return toSortKey(timeA) - toSortKey(timeB); + }, Cell: ({ cell }) => { const time = cell.getValue(); return time === 0 ? : {dayjs().add(time).fromNow()};