2017-01-13 23:18:37 +01:00
|
|
|
import React from 'react';
|
|
|
|
import lbry from '../lbry.js';
|
2017-04-18 21:14:42 +02:00
|
|
|
import lbryuri from '../lbryuri.js';
|
2017-04-07 07:15:22 +02:00
|
|
|
import Link from 'component/link';
|
|
|
|
import FormField from '../component/form.js';
|
2017-04-27 15:17:18 +02:00
|
|
|
import {SubHeader} from '../component/header.js';
|
2017-01-13 23:18:37 +01:00
|
|
|
import {FileTileStream} from '../component/file-tile.js';
|
2017-04-17 14:27:39 +02:00
|
|
|
import rewards from '../rewards.js';
|
|
|
|
import lbryio from '../lbryio.js';
|
2017-01-13 23:18:37 +01:00
|
|
|
import {BusyMessage, Thumbnail} from '../component/common.js';
|
|
|
|
|
|
|
|
|
2017-04-27 15:17:18 +02:00
|
|
|
export let FileListNav = React.createClass({
|
|
|
|
render: function() {
|
|
|
|
return <SubHeader modifier="constrained" viewingPage={this.props.viewingPage} links={{
|
|
|
|
'?downloaded': 'Downloaded',
|
|
|
|
'?published': 'Published',
|
|
|
|
}} />;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-01-13 23:18:37 +01:00
|
|
|
export let FileListDownloaded = React.createClass({
|
|
|
|
_isMounted: false,
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
fileInfos: null,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
componentDidMount: function() {
|
|
|
|
this._isMounted = true;
|
|
|
|
|
2017-03-08 08:17:16 +01:00
|
|
|
lbry.claim_list_mine().then((myClaimInfos) => {
|
2017-01-13 23:18:37 +01:00
|
|
|
if (!this._isMounted) { return; }
|
|
|
|
|
2017-03-08 08:17:16 +01:00
|
|
|
lbry.file_list().then((fileInfos) => {
|
2017-01-13 23:18:37 +01:00
|
|
|
if (!this._isMounted) { return; }
|
|
|
|
|
2017-03-10 21:29:52 +01:00
|
|
|
const myClaimOutpoints = myClaimInfos.map(({txid, nout}) => txid + ':' + nout);
|
2017-01-13 23:18:37 +01:00
|
|
|
this.setState({
|
2017-03-08 08:17:16 +01:00
|
|
|
fileInfos: fileInfos.filter(({outpoint}) => !myClaimOutpoints.includes(outpoint)),
|
2017-01-13 23:18:37 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2017-04-17 14:27:39 +02:00
|
|
|
componentWillUnmount: function() {
|
|
|
|
this._isMounted = false;
|
|
|
|
},
|
2017-01-13 23:18:37 +01:00
|
|
|
render: function() {
|
2017-04-27 15:17:18 +02:00
|
|
|
let content = "";
|
2017-01-13 23:18:37 +01:00
|
|
|
if (this.state.fileInfos === null) {
|
2017-04-27 15:17:18 +02:00
|
|
|
content = <BusyMessage message="Loading" />;
|
2017-01-13 23:18:37 +01:00
|
|
|
} else if (!this.state.fileInfos.length) {
|
2017-04-27 15:17:18 +02:00
|
|
|
content = <span>You haven't downloaded anything from LBRY yet. Go <Link href="?discover" label="search for your first download" />!</span>;
|
2017-01-13 23:18:37 +01:00
|
|
|
} else {
|
2017-04-27 15:17:18 +02:00
|
|
|
content = <FileList fileInfos={this.state.fileInfos} hidePrices={true} />;
|
2017-01-13 23:18:37 +01:00
|
|
|
}
|
2017-04-27 15:17:18 +02:00
|
|
|
return (
|
2017-05-01 02:15:21 +02:00
|
|
|
<main className="main--single-column">
|
2017-04-27 15:17:18 +02:00
|
|
|
<FileListNav viewingPage="downloaded" />
|
|
|
|
{content}
|
|
|
|
</main>
|
|
|
|
);
|
2017-01-13 23:18:37 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export let FileListPublished = React.createClass({
|
|
|
|
_isMounted: false,
|
|
|
|
|
|
|
|
getInitialState: function () {
|
|
|
|
return {
|
|
|
|
fileInfos: null,
|
|
|
|
};
|
|
|
|
},
|
2017-04-17 14:27:39 +02:00
|
|
|
_requestPublishReward: function() {
|
|
|
|
lbryio.call('reward', 'list', {}).then(function(userRewards) {
|
|
|
|
//already rewarded
|
|
|
|
if (userRewards.filter(function (reward) {
|
|
|
|
return reward.RewardType == rewards.TYPE_FIRST_PUBLISH && reward.TransactionID;
|
|
|
|
}).length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rewards.claimReward(rewards.TYPE_FIRST_PUBLISH).catch(() => {})
|
|
|
|
}
|
2017-05-01 02:15:21 +02:00
|
|
|
}, () => {});
|
2017-04-17 14:27:39 +02:00
|
|
|
},
|
2017-01-13 23:18:37 +01:00
|
|
|
componentDidMount: function () {
|
|
|
|
this._isMounted = true;
|
2017-04-17 14:27:39 +02:00
|
|
|
this._requestPublishReward();
|
2017-01-13 23:18:37 +01:00
|
|
|
|
2017-03-08 08:17:16 +01:00
|
|
|
lbry.claim_list_mine().then((claimInfos) => {
|
|
|
|
if (!this._isMounted) { return; }
|
2017-02-24 10:22:44 +01:00
|
|
|
|
2017-03-08 08:17:16 +01:00
|
|
|
lbry.file_list().then((fileInfos) => {
|
|
|
|
if (!this._isMounted) { return; }
|
2017-01-13 23:18:37 +01:00
|
|
|
|
2017-03-10 21:29:52 +01:00
|
|
|
const myClaimOutpoints = claimInfos.map(({txid, nout}) => txid + ':' + nout);
|
2017-03-08 08:17:16 +01:00
|
|
|
this.setState({
|
|
|
|
fileInfos: fileInfos.filter(({outpoint}) => myClaimOutpoints.includes(outpoint)),
|
2017-01-13 23:18:37 +01:00
|
|
|
});
|
2017-03-08 08:17:16 +01:00
|
|
|
});
|
2017-01-13 23:18:37 +01:00
|
|
|
});
|
|
|
|
},
|
2017-04-17 14:27:39 +02:00
|
|
|
componentWillUnmount: function() {
|
|
|
|
this._isMounted = false;
|
|
|
|
},
|
2017-01-13 23:18:37 +01:00
|
|
|
render: function () {
|
2017-04-27 15:17:18 +02:00
|
|
|
let content = null;
|
2017-01-13 23:18:37 +01:00
|
|
|
if (this.state.fileInfos === null) {
|
2017-04-27 15:17:18 +02:00
|
|
|
content = <BusyMessage message="Loading" />;
|
2017-01-13 23:18:37 +01:00
|
|
|
}
|
|
|
|
else if (!this.state.fileInfos.length) {
|
2017-04-27 15:17:18 +02:00
|
|
|
content = <span>You haven't published anything to LBRY yet. Try <Link href="?publish" label="publishing" />!</span>;
|
2017-01-13 23:18:37 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-04-27 15:17:18 +02:00
|
|
|
content = <FileList fileInfos={this.state.fileInfos} />;
|
2017-01-13 23:18:37 +01:00
|
|
|
}
|
2017-04-27 15:17:18 +02:00
|
|
|
return (
|
2017-05-01 02:15:21 +02:00
|
|
|
<main className="main--single-column">
|
2017-04-27 15:17:18 +02:00
|
|
|
<FileListNav viewingPage="published" />
|
|
|
|
{content}
|
|
|
|
</main>
|
|
|
|
);
|
2017-01-13 23:18:37 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export let FileList = React.createClass({
|
|
|
|
_sortFunctions: {
|
|
|
|
date: function(fileInfos) {
|
2017-02-24 06:32:32 +01:00
|
|
|
return fileInfos.slice().reverse();
|
2017-01-13 23:18:37 +01:00
|
|
|
},
|
|
|
|
title: function(fileInfos) {
|
2017-02-24 06:32:32 +01:00
|
|
|
return fileInfos.slice().sort(function(fileInfo1, fileInfo2) {
|
|
|
|
const title1 = fileInfo1.metadata ? fileInfo1.metadata.title.toLowerCase() : fileInfo1.name;
|
|
|
|
const title2 = fileInfo2.metadata ? fileInfo2.metadata.title.toLowerCase() : fileInfo2.name;
|
|
|
|
if (title1 < title2) {
|
|
|
|
return -1;
|
|
|
|
} else if (title1 > title2) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2017-01-13 23:18:37 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
filename: function(fileInfos) {
|
2017-02-24 06:32:32 +01: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-01-13 23:18:37 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
propTypes: {
|
2017-01-17 11:19:09 +01:00
|
|
|
fileInfos: React.PropTypes.array.isRequired,
|
|
|
|
hidePrices: React.PropTypes.bool,
|
|
|
|
},
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
hidePrices: false,
|
|
|
|
};
|
2017-01-13 23:18:37 +01:00
|
|
|
},
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
sortBy: 'date',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
handleSortChanged: function(event) {
|
|
|
|
this.setState({
|
|
|
|
sortBy: event.target.value,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
var content = [],
|
|
|
|
seenUris = {};
|
|
|
|
|
|
|
|
const fileInfosSorted = this._sortFunctions[this.state.sortBy](this.props.fileInfos);
|
2017-04-13 22:35:40 +02:00
|
|
|
for (let {outpoint, name, channel_name, metadata, mime_type, claim_id, has_signature, signature_is_valid} of fileInfosSorted) {
|
|
|
|
if (seenUris[name] || !claim_id) {
|
2017-01-13 23:18:37 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-04-13 22:35:40 +02:00
|
|
|
let streamMetadata;
|
|
|
|
if (metadata) {
|
|
|
|
streamMetadata = metadata.stream.metadata;
|
|
|
|
} else {
|
|
|
|
streamMetadata = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-19 19:56:17 +02:00
|
|
|
const uri = lbryuri.build({contentName: name, channelName: channel_name});
|
2017-03-09 21:26:11 +01:00
|
|
|
seenUris[name] = true;
|
2017-04-18 21:14:42 +02:00
|
|
|
content.push(<FileTileStream key={outpoint} outpoint={outpoint} uri={uri} hideOnRemove={true}
|
2017-04-13 22:35:40 +02:00
|
|
|
hidePrice={this.props.hidePrices} metadata={streamMetadata} contentType={mime_type}
|
2017-04-11 06:21:02 +02:00
|
|
|
hasSignature={has_signature} signatureIsValid={signature_is_valid} />);
|
2017-01-13 23:18:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<section>
|
|
|
|
<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}
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|