Add Sort option to My Files page

This commit is contained in:
Alex Liebowitz 2016-11-18 05:56:55 -05:00 committed by Alex Liebowitz
parent 350bc6d847
commit ac281105ad
2 changed files with 35 additions and 8 deletions

View file

@ -174,6 +174,7 @@ var MyFilesPage = React.createClass({
}, },
title: function(filesInfo) { title: function(filesInfo) {
return filesInfo.sort(function(a, b) { return filesInfo.sort(function(a, b) {
console.log('in title sort. a is', a, '; b is', b)
return ((a.metadata ? a.metadata.title.toLowerCase() : a.name) > return ((a.metadata ? a.metadata.title.toLowerCase() : a.name) >
(b.metadata ? b.metadata.title.toLowerCase() : b.name)); (b.metadata ? b.metadata.title.toLowerCase() : b.name));
}); });
@ -191,6 +192,7 @@ var MyFilesPage = React.createClass({
filesInfo: null, filesInfo: null,
publishedFilesSdHashes: null, publishedFilesSdHashes: null,
filesAvailable: {}, filesAvailable: {},
sortBy: 'date',
}; };
}, },
getDefaultProps: function() { getDefaultProps: function() {
@ -233,6 +235,17 @@ var MyFilesPage = React.createClass({
clearTimeout(this._fileTimeout); clearTimeout(this._fileTimeout);
} }
}, },
setFilesInfo: function(filesInfo) {
this.setState({
filesInfo: this._sortFunctions[this.state.sortBy](filesInfo),
});
},
handleSortChanged: function(event) {
this.setState({
sortBy: event.target.value,
filesInfo: this._sortFunctions[event.target.value](this.state.filesInfo),
});
},
updateFilesInfo: function() { updateFilesInfo: function() {
this._fileInfoCheckNum += 1; this._fileInfoCheckNum += 1;
@ -249,9 +262,7 @@ var MyFilesPage = React.createClass({
newFilesInfo.push(fileInfo); newFilesInfo.push(fileInfo);
} }
if (claimInfoProcessedCount >= claimsInfo.length) { if (claimInfoProcessedCount >= claimsInfo.length) {
this.setState({ this.setFilesInfo(newFilesInfo);
filesInfo: newFilesInfo
});
this._fileTimeout = setTimeout(() => { this.updateFilesInfo() }, 1000); this._fileTimeout = setTimeout(() => { this.updateFilesInfo() }, 1000);
} }
@ -262,11 +273,9 @@ var MyFilesPage = React.createClass({
// We're in the Downloaded tab, so populate this.state.filesInfo with files the user has in // We're in the Downloaded tab, so populate this.state.filesInfo with files the user has in
// lbrynet, with published files filtered out. // lbrynet, with published files filtered out.
lbry.getFilesInfo((filesInfo) => { lbry.getFilesInfo((filesInfo) => {
this.setState({ this.setFilesInfo(filesInfo.filter(({sd_hash}) => {
filesInfo: filesInfo.filter(({sd_hash}) => { return this.state.publishedFilesSdHashes.indexOf(sd_hash) == -1;
return this.state.publishedFilesSdHashes.indexOf(sd_hash) == -1; }));
}),
});
let newFilesAvailable; let newFilesAvailable;
if (!(this._fileInfoCheckNum % this._fileInfoCheckRate)) { if (!(this._fileInfoCheckNum % this._fileInfoCheckRate)) {
@ -344,6 +353,14 @@ var MyFilesPage = React.createClass({
} }
return ( return (
<main className="page"> <main className="page">
<span className='sort-section'>
Sort by { ' ' }
<FormField type="select" onChange={this.handleSortChanged}>
<option value="date">Date</option>
<option value="title">Title</option>
<option value="filename">File name</option>
</FormField>
</span>
{content} {content}
</main> </main>
); );

View file

@ -284,6 +284,16 @@ input[type="text"], input[type="search"]
} }
.sort-section {
display: block;
margin-bottom: 5px;
text-align: right;
font-size: 0.85em;
color: $color-help;
}
.modal-overlay { .modal-overlay {
position: fixed; position: fixed;
display: flex; display: flex;