From 573bd9d64c524f50a96410cbb146c68df2b73fb5 Mon Sep 17 00:00:00 2001 From: Franco Montenegro Date: Mon, 5 Sep 2022 14:19:03 -0300 Subject: [PATCH] Sort downloads (show newest first) --- ui/redux/selectors/file_info.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/ui/redux/selectors/file_info.js b/ui/redux/selectors/file_info.js index 57170d323..34b7f2a45 100644 --- a/ui/redux/selectors/file_info.js +++ b/ui/redux/selectors/file_info.js @@ -161,18 +161,24 @@ function filterFileInfos(fileInfos, query) { export const makeSelectSearchDownloadUrlsForPage = (query, page = 1) => createSelector(selectFileInfosDownloaded, (fileInfos) => { const matchingFileInfos = filterFileInfos(fileInfos, query); + if (!matchingFileInfos || !matchingFileInfos.length) { + return []; + } + const start = (Number(page) - 1) * Number(PAGE_SIZE); const end = Number(page) * Number(PAGE_SIZE); + // Recently downloaded elements first. + const sortedMatchedFileInfos = matchingFileInfos.sort((a, b) => { + return b.added_on - a.added_on; + }); - return matchingFileInfos && matchingFileInfos.length - ? matchingFileInfos.slice(start, end).map((fileInfo) => - buildURI({ - streamName: fileInfo.claim_name, - channelName: fileInfo.channel_name, - channelClaimId: fileInfo.channel_claim_id, - }) - ) - : []; + return sortedMatchedFileInfos.slice(start, end).map((fileInfo) => + buildURI({ + streamName: fileInfo.claim_name, + channelName: fileInfo.channel_name, + channelClaimId: fileInfo.channel_claim_id, + }) + ); }); export const makeSelectSearchDownloadUrlsCount = (query) => -- 2.45.2