2017-12-21 22:08:54 +01:00
|
|
|
import React from 'react';
|
2018-01-19 16:12:28 +01:00
|
|
|
import { buildURI } from 'lbryURI';
|
2017-12-21 22:08:54 +01:00
|
|
|
import FormField from 'component/formField';
|
|
|
|
import FileTile from 'component/fileTile';
|
|
|
|
import { BusyMessage } 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 = {
|
2018-02-15 16:21:35 +01:00
|
|
|
sortBy: 'dateNew',
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-23 18:10:45 +02:00
|
|
|
|
2017-04-30 18:01:43 +02:00
|
|
|
this._sortFunctions = {
|
2018-03-09 07:25:55 +01:00
|
|
|
dateNew: (fileInfos) =>
|
|
|
|
fileInfos.slice().sort((fileInfo1, fileInfo2) => {
|
|
|
|
const height1 = this.props.claimsById[fileInfo1.claim_id].height;
|
|
|
|
const height2 = this.props.claimsById[fileInfo2.claim_id].height;
|
2018-02-15 16:21:35 +01:00
|
|
|
if (height1 > height2) {
|
|
|
|
return -1;
|
|
|
|
} else if (height1 < height2) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2018-03-09 07:25:55 +01:00
|
|
|
}),
|
|
|
|
dateOld: (fileInfos) =>
|
|
|
|
fileInfos.slice().sort((fileInfo1, fileInfo2) => {
|
|
|
|
const height1 = this.props.claimsById[fileInfo1.claim_id].height;
|
|
|
|
const height2 = this.props.claimsById[fileInfo2.claim_id].height;
|
2018-02-15 16:21:35 +01:00
|
|
|
if (height1 < height2) {
|
|
|
|
return -1;
|
|
|
|
} else if (height1 > height2) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2018-03-09 07:25:55 +01:00
|
|
|
}),
|
|
|
|
title: (fileInfos) =>
|
|
|
|
fileInfos.slice().sort((fileInfo1, fileInfo2) => {
|
2017-11-21 23:00:53 +01:00
|
|
|
const title1 = fileInfo1.value
|
|
|
|
? fileInfo1.value.stream.metadata.title.toLowerCase()
|
2018-02-21 20:01:43 +01:00
|
|
|
: fileInfo1.claim_name;
|
2017-11-21 23:00:53 +01:00
|
|
|
const title2 = fileInfo2.value
|
|
|
|
? fileInfo2.value.stream.metadata.title.toLowerCase()
|
2018-02-21 20:01:43 +01:00
|
|
|
: fileInfo2.claim_name;
|
2017-04-30 18:01:43 +02:00
|
|
|
if (title1 < title2) {
|
|
|
|
return -1;
|
|
|
|
} else if (title1 > title2) {
|
|
|
|
return 1;
|
|
|
|
}
|
2017-12-21 22:08:54 +01:00
|
|
|
return 0;
|
2018-03-09 07:25:55 +01:00
|
|
|
}),
|
|
|
|
filename: (fileInfos) =>
|
|
|
|
fileInfos.slice().sort(({ file_name: fileName1 }, { file_name: fileName2 }) => {
|
2017-12-21 22:08:54 +01:00
|
|
|
const fileName1Lower = fileName1.toLowerCase();
|
|
|
|
const fileName2Lower = fileName2.toLowerCase();
|
|
|
|
if (fileName1Lower < fileName2Lower) {
|
|
|
|
return -1;
|
|
|
|
} else if (fileName2Lower > fileName1Lower) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2018-03-09 07:25:55 +01:00
|
|
|
}),
|
|
|
|
};
|
|
|
|
}
|
2017-04-23 18:10:45 +02:00
|
|
|
|
2017-08-27 07:00:44 +02:00
|
|
|
getChannelSignature(fileInfo) {
|
|
|
|
if (fileInfo.value) {
|
|
|
|
return fileInfo.value.publisherSignature.certificateId;
|
|
|
|
}
|
2018-02-21 20:01:43 +01:00
|
|
|
return fileInfo.channel_claim_id;
|
2017-08-27 07:00:44 +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 => {
|
2017-12-21 22:08:54 +01:00
|
|
|
const uriParams = {};
|
2017-08-26 09:55:26 +02:00
|
|
|
|
2017-06-29 00:08:16 +02:00
|
|
|
if (fileInfo.channel_name) {
|
|
|
|
uriParams.channelName = fileInfo.channel_name;
|
2018-03-09 08:03:30 +01:00
|
|
|
uriParams.contentName = fileInfo.claim_name || fileInfo.name;
|
2017-08-27 07:00:44 +02:00
|
|
|
uriParams.claimId = this.getChannelSignature(fileInfo);
|
2017-06-29 00:08:16 +02:00
|
|
|
} else {
|
|
|
|
uriParams.claimId = fileInfo.claim_id;
|
2018-03-09 06:27:06 +01:00
|
|
|
uriParams.claimName = fileInfo.claim_name || fileInfo.name;
|
2017-06-29 00:08:16 +02:00
|
|
|
}
|
2018-01-19 16:12:28 +01:00
|
|
|
const uri = buildURI(uriParams);
|
2017-06-23 08:58:08 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
content.push(
|
|
|
|
<FileTile
|
2017-07-12 10:08:59 +02:00
|
|
|
key={fileInfo.outpoint || fileInfo.claim_id}
|
2017-06-06 23:19:12 +02:00
|
|
|
uri={uri}
|
2017-09-12 06:24:04 +02:00
|
|
|
showPrice={false}
|
|
|
|
showLocal={false}
|
2017-12-21 22:08:54 +01:00
|
|
|
showActions
|
2017-06-06 23:19:12 +02:00
|
|
|
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">
|
2017-12-21 22:08:54 +01:00
|
|
|
{__('Sort by')}{' '}
|
2017-04-30 18:01:43 +02:00
|
|
|
<FormField type="select" onChange={this.handleSortChanged.bind(this)}>
|
2018-02-15 18:55:25 +01:00
|
|
|
<option value="dateNew">{__('Newest First')}</option>
|
|
|
|
<option value="dateOld">{__('Oldest First')}</option>
|
2017-12-21 22:08:54 +01:00
|
|
|
<option value="title">{__('Title')}</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;
|