Sort downloads (show newest first) #7684
1 changed files with 15 additions and 9 deletions
|
@ -161,18 +161,24 @@ function filterFileInfos(fileInfos, query) {
|
||||||
export const makeSelectSearchDownloadUrlsForPage = (query, page = 1) =>
|
export const makeSelectSearchDownloadUrlsForPage = (query, page = 1) =>
|
||||||
createSelector(selectFileInfosDownloaded, (fileInfos) => {
|
createSelector(selectFileInfosDownloaded, (fileInfos) => {
|
||||||
const matchingFileInfos = filterFileInfos(fileInfos, query);
|
const matchingFileInfos = filterFileInfos(fileInfos, query);
|
||||||
|
if (!matchingFileInfos || !matchingFileInfos.length) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
const start = (Number(page) - 1) * Number(PAGE_SIZE);
|
const start = (Number(page) - 1) * Number(PAGE_SIZE);
|
||||||
const end = Number(page) * 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
|
return sortedMatchedFileInfos.slice(start, end).map((fileInfo) =>
|
||||||
? matchingFileInfos.slice(start, end).map((fileInfo) =>
|
buildURI({
|
||||||
buildURI({
|
streamName: fileInfo.claim_name,
|
||||||
streamName: fileInfo.claim_name,
|
channelName: fileInfo.channel_name,
|
||||||
channelName: fileInfo.channel_name,
|
channelClaimId: fileInfo.channel_claim_id,
|
||||||
channelClaimId: fileInfo.channel_claim_id,
|
})
|
||||||
})
|
);
|
||||||
)
|
|
||||||
: [];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export const makeSelectSearchDownloadUrlsCount = (query) =>
|
export const makeSelectSearchDownloadUrlsCount = (query) =>
|
||||||
|
|
Loading…
Reference in a new issue