Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

fix(downloads): sort stalled torrents last when sorting by finish time (#6011)

Matt Van Hornc56d9d6894c7
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<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>;