Fix sorting on downloads/published pages

This commit is contained in:
liamcardenas 2018-03-08 22:25:55 -08:00
parent c199a24986
commit bd785502f4
2 changed files with 22 additions and 23 deletions

View file

@ -1,8 +1,11 @@
import React from 'react'; import React from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import FileList from './view'; import FileList from './view';
import { selectClaimsById } from 'redux/selectors/claims';
const select = state => ({}); const select = state => ({
claimsById: selectClaimsById(state),
});
const perform = dispatch => ({}); const perform = dispatch => ({});

View file

@ -13,32 +13,30 @@ class FileList extends React.PureComponent {
}; };
this._sortFunctions = { this._sortFunctions = {
dateNew(fileInfos) { dateNew: (fileInfos) =>
return fileInfos.slice().sort((fileInfo1, fileInfo2) => { fileInfos.slice().sort((fileInfo1, fileInfo2) => {
const height1 = fileInfo1.height; const height1 = this.props.claimsById[fileInfo1.claim_id].height;
const height2 = fileInfo2.height; const height2 = this.props.claimsById[fileInfo2.claim_id].height;
if (height1 > height2) { if (height1 > height2) {
return -1; return -1;
} else if (height1 < height2) { } else if (height1 < height2) {
return 1; return 1;
} }
return 0; return 0;
}); }),
}, dateOld: (fileInfos) =>
dateOld(fileInfos) { fileInfos.slice().sort((fileInfo1, fileInfo2) => {
return fileInfos.slice().sort((fileInfo1, fileInfo2) => { const height1 = this.props.claimsById[fileInfo1.claim_id].height;
const height1 = fileInfo1.height; const height2 = this.props.claimsById[fileInfo2.claim_id].height;
const height2 = fileInfo2.height;
if (height1 < height2) { if (height1 < height2) {
return -1; return -1;
} else if (height1 > height2) { } else if (height1 > height2) {
return 1; return 1;
} }
return 0; return 0;
}); }),
}, title: (fileInfos) =>
title(fileInfos) { fileInfos.slice().sort((fileInfo1, fileInfo2) => {
return fileInfos.slice().sort((fileInfo1, fileInfo2) => {
const title1 = fileInfo1.value const title1 = fileInfo1.value
? fileInfo1.value.stream.metadata.title.toLowerCase() ? fileInfo1.value.stream.metadata.title.toLowerCase()
: fileInfo1.claim_name; : fileInfo1.claim_name;
@ -51,10 +49,9 @@ class FileList extends React.PureComponent {
return 1; return 1;
} }
return 0; return 0;
}); }),
}, filename: (fileInfos) =>
filename(fileInfos) { fileInfos.slice().sort(({ file_name: fileName1 }, { file_name: fileName2 }) => {
return fileInfos.slice().sort(({ file_name: fileName1 }, { file_name: fileName2 }) => {
const fileName1Lower = fileName1.toLowerCase(); const fileName1Lower = fileName1.toLowerCase();
const fileName2Lower = fileName2.toLowerCase(); const fileName2Lower = fileName2.toLowerCase();
if (fileName1Lower < fileName2Lower) { if (fileName1Lower < fileName2Lower) {
@ -63,8 +60,7 @@ class FileList extends React.PureComponent {
return 1; return 1;
} }
return 0; return 0;
}); }),
},
}; };
} }