2017-06-06 23:19:12 +02:00
|
|
|
import React from "react";
|
|
|
|
import lbry from "lbry.js";
|
|
|
|
import lbryuri from "lbryuri.js";
|
|
|
|
import Link from "component/link";
|
|
|
|
import { FormField } from "component/form.js";
|
|
|
|
import FileTile from "component/fileTile";
|
|
|
|
import rewards from "rewards.js";
|
|
|
|
import lbryio from "lbryio.js";
|
|
|
|
import { BusyMessage, Thumbnail } from "component/common.js";
|
2017-04-23 18:10:45 +02:00
|
|
|
|
2017-06-08 06:42:19 +02:00
|
|
|
class FileList extends React.PureComponent {
|
2017-04-30 18:01:43 +02:00
|
|
|
constructor(props) {
|
2017-06-06 23:19:12 +02:00
|
|
|
super(props);
|
2017-04-23 18:10:45 +02:00
|
|
|
|
2017-04-30 18:01:43 +02:00
|
|
|
this.state = {
|
2017-06-06 23:19:12 +02:00
|
|
|
sortBy: "date",
|
|
|
|
};
|
2017-04-23 18:10:45 +02:00
|
|
|
|
2017-04-30 18:01:43 +02:00
|
|
|
this._sortFunctions = {
|
|
|
|
date: function(fileInfos) {
|
|
|
|
return fileInfos.slice().reverse();
|
|
|
|
},
|
|
|
|
title: function(fileInfos) {
|
|
|
|
return fileInfos.slice().sort(function(fileInfo1, fileInfo2) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const title1 = fileInfo1.metadata
|
|
|
|
? fileInfo1.metadata.stream.metadata.title.toLowerCase()
|
|
|
|
: fileInfo1.name;
|
|
|
|
const title2 = fileInfo2.metadata
|
|
|
|
? fileInfo2.metadata.stream.metadata.title.toLowerCase()
|
|
|
|
: fileInfo2.name;
|
2017-04-30 18:01:43 +02:00
|
|
|
if (title1 < title2) {
|
|
|
|
return -1;
|
|
|
|
} else if (title1 > title2) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-04-30 18:01:43 +02:00
|
|
|
},
|
|
|
|
filename: function(fileInfos) {
|
2017-06-06 23:19:12 +02:00
|
|
|
return fileInfos
|
|
|
|
.slice()
|
|
|
|
.sort(function({ file_name: fileName1 }, { file_name: fileName2 }) {
|
|
|
|
const fileName1Lower = fileName1.toLowerCase();
|
|
|
|
const fileName2Lower = fileName2.toLowerCase();
|
|
|
|
if (fileName1Lower < fileName2Lower) {
|
|
|
|
return -1;
|
|
|
|
} else if (fileName2Lower > fileName1Lower) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
});
|
2017-04-30 18:01:43 +02:00
|
|
|
},
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-30 18:01:43 +02:00
|
|
|
}
|
2017-04-23 18:10:45 +02:00
|
|
|
|
2017-04-30 18:01:43 +02:00
|
|
|
handleSortChanged(event) {
|
|
|
|
this.setState({
|
|
|
|
sortBy: event.target.value,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-04-30 18:01:43 +02:00
|
|
|
}
|
2017-04-23 18:10:45 +02:00
|
|
|
|
2017-04-30 18:01:43 +02:00
|
|
|
render() {
|
2017-06-06 23:19:12 +02:00
|
|
|
const { handleSortChanged, fetching, fileInfos } = this.props;
|
|
|
|
const { sortBy } = this.state;
|
|
|
|
const content = [];
|
2017-04-23 18:10:45 +02:00
|
|
|
|
2017-04-30 18:01:43 +02:00
|
|
|
this._sortFunctions[sortBy](fileInfos).forEach(fileInfo => {
|
|
|
|
const uri = lbryuri.build({
|
|
|
|
contentName: fileInfo.name,
|
|
|
|
channelName: fileInfo.channel_name,
|
2017-06-23 08:58:08 +02:00
|
|
|
claimId: fileInfo.claim_id,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-06-23 08:58:08 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
content.push(
|
|
|
|
<FileTile
|
|
|
|
key={uri}
|
|
|
|
uri={uri}
|
|
|
|
hidePrice={true}
|
|
|
|
showEmpty={this.props.fileTileShowEmpty}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
2017-04-23 18:10:45 +02:00
|
|
|
return (
|
2017-05-15 18:34:33 +02:00
|
|
|
<section className="file-list__header">
|
2017-06-15 06:26:26 +02:00
|
|
|
{fetching && <BusyMessage />}
|
2017-06-06 23:19:12 +02:00
|
|
|
<span className="sort-section">
|
|
|
|
{__("Sort by")} {" "}
|
2017-04-30 18:01:43 +02:00
|
|
|
<FormField type="select" onChange={this.handleSortChanged.bind(this)}>
|
2017-05-26 15:55:59 +02:00
|
|
|
<option value="date">{__("Date")}</option>
|
|
|
|
<option value="title">{__("Title")}</option>
|
|
|
|
<option value="filename">{__("File name")}</option>
|
2017-04-23 18:10:45 +02:00
|
|
|
</FormField>
|
|
|
|
</span>
|
|
|
|
{content}
|
|
|
|
</section>
|
2017-06-06 23:19:12 +02:00
|
|
|
);
|
2017-04-23 18:10:45 +02:00
|
|
|
}
|
2017-04-30 18:01:43 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
export default FileList;
|