Skip to content

Commit

Permalink
Sort downloads (show newest first) (#7684)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruk33 authored Sep 5, 2022
1 parent 329d434 commit 3fd38be
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions ui/redux/selectors/file_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down

0 comments on commit 3fd38be

Please sign in to comment.