From 8bc13fb8a573365d5aa1dfb52e1db885a6173e32 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Fri, 23 Sep 2016 05:56:01 -0400 Subject: [PATCH] Filter My Files results based on tab chosen --- js/page/my_files.js | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/js/page/my_files.js b/js/page/my_files.js index 895806e15..2c896cd61 100644 --- a/js/page/my_files.js +++ b/js/page/my_files.js @@ -134,6 +134,8 @@ var MyFilesRow = React.createClass({ var MyFilesPage = React.createClass({ _fileTimeout: null, _fileInfoCheckNum: 0, + _filesOwnership: {}, + _filesOwnershipLoaded: false, getInitialState: function() { return { @@ -141,10 +143,16 @@ var MyFilesPage = React.createClass({ filesAvailable: {}, }; }, + getDefaultProps: function() { + return { + show: null, + }; + }, componentDidMount: function() { document.title = "My Files"; }, componentWillMount: function() { + this.getFilesOwnership(); this.updateFilesInfo(); }, componentWillUnmount: function() { @@ -153,6 +161,27 @@ var MyFilesPage = React.createClass({ clearTimeout(this._fileTimeout); } }, + getFilesOwnership: function() { + lbry.getFilesInfo((filesInfo) => { + var ownershipLoadedCount = 0; + for (let i = 0; i < filesInfo.length; i++) { + let fileInfo = filesInfo[i]; + lbry.call('get_my_claim', {name: fileInfo.lbry_uri}, (claim) => { + this._filesOwnership[fileInfo.lbry_uri] = false; + ownershipLoadedCount++; + if (ownershipLoadedCount >= filesInfo.length) { + this._filesOwnershipLoaded = true; + } + }, (err) => { + this._filesOwnership[fileInfo.lbry_uri] = true; + ownershipLoadedCount++; + if (ownershipLoadedCount >= filesInfo.length) { + this._filesOwnershipLoaded = true; + } + }); + } + }); + }, updateFilesInfo: function() { lbry.getFilesInfo((filesInfo) => { if (!filesInfo) { @@ -196,7 +225,7 @@ var MyFilesPage = React.createClass({ }); }, render: function() { - if (this.state.filesInfo === null) { + if (this.state.filesInfo === null || !this._filesOwnershipLoaded) { return (
@@ -214,7 +243,8 @@ var MyFilesPage = React.createClass({ let {completed, written_bytes, total_bytes, lbry_uri, file_name, download_path, stopped, metadata} = fileInfo; - if (!metadata || seenUris[lbry_uri]) + if (!metadata || seenUris[lbry_uri] || (this.props.show == 'downloaded' && this._filesOwnership[lbry_uri]) || + (this.props.show == 'published' && !this._filesOwnership[lbry_uri])) { continue; }