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>
This commit is contained in:
Matt Van HornandMatt Van Horn authored and GitHub committed 2026-06-19 20:42:48 +02:00
1 parent 3ea49f0391
commit c56d9d6894
1 file changed
+10
@@ -529,6 +529,16 @@ export default function DownloadClientsWidget({
},
{
...columnsDefBase({ key: "time", showHeader: true }),
sortingFn: (rowA, rowB) => {
const timeA = rowA.getValue<ExtendedDownloadClientItem["time"]>("time");
const timeB = rowB.getValue<ExtendedDownloadClientItem["time"]>("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<ExtendedDownloadClientItem["time"]>();
return time === 0 ? <IconInfinity size={16} /> : <Text size="xs">{dayjs().add(time).fromNow()}</Text>;