From da98d02fb1f468621a603f44a6f4478c12782798 Mon Sep 17 00:00:00 2001 From: 6ea86b96 <6ea86b96@gmail.com> Date: Mon, 1 May 2017 13:26:09 +0700 Subject: [PATCH] Published files working --- ui/js/actions/content.js | 6 +++ ui/js/component/fileCardStream/view.jsx | 8 ++-- ui/js/constants/action_types.js | 1 + ui/js/page/fileListPublished/view.jsx | 52 ++++++++++++++++++++++--- ui/js/reducers/claims.js | 17 ++++++++ ui/js/reducers/file_info.js | 21 ++++++++++ ui/js/selectors/claims.js | 24 ++++++++++++ ui/js/selectors/file_info.js | 21 ++++++++++ 8 files changed, 141 insertions(+), 9 deletions(-) diff --git a/ui/js/actions/content.js b/ui/js/actions/content.js index f1b756491..510b5d028 100644 --- a/ui/js/actions/content.js +++ b/ui/js/actions/content.js @@ -100,6 +100,12 @@ export function doFetchPublishedContent() { }) lbry.claim_list_mine().then((claimInfos) => { + dispatch({ + type: types.FETCH_MY_CLAIMS_COMPLETED, + data: { + claims: claimInfos, + } + }) lbry.file_list().then((fileInfos) => { const myClaimOutpoints = claimInfos.map(({txid, nout}) => txid + ':' + nout) diff --git a/ui/js/component/fileCardStream/view.jsx b/ui/js/component/fileCardStream/view.jsx index a3b6d9b56..c3954d9b7 100644 --- a/ui/js/component/fileCardStream/view.jsx +++ b/ui/js/component/fileCardStream/view.jsx @@ -56,9 +56,9 @@ class FileCardStream extends React.Component { return null; } - if (!this.props.metadata) { - return null - } + // if (!this.props.metadata) { + // return null + // } const uri = lbryuri.normalize(this.props.uri); const metadata = this.props.metadata; @@ -78,7 +78,9 @@ class FileCardStream extends React.Component { hasSignature={this.props.hasSignature} signatureIsValid={this.props.signatureIsValid} /> + {metadata &&
+ }
{isConfirmed diff --git a/ui/js/constants/action_types.js b/ui/js/constants/action_types.js index 91c2593dc..80eecab79 100644 --- a/ui/js/constants/action_types.js +++ b/ui/js/constants/action_types.js @@ -56,6 +56,7 @@ export const FETCH_AVAILABILITY_STARTED = 'FETCH_AVAILABILITY_STARTED' export const FETCH_AVAILABILITY_COMPLETED = 'FETCH_AVAILABILITY_COMPLETED' export const DELETE_FILE_STARTED = 'DELETE_FILE_STARTED' export const DELETE_FILE_COMPLETED = 'DELETE_FILE_COMPLETED' +export const FETCH_MY_CLAIMS_COMPLETED = 'FETCH_MY_CLAIMS_COMPLETED' // Search export const SEARCH_STARTED = 'SEARCH_STARTED' diff --git a/ui/js/page/fileListPublished/view.jsx b/ui/js/page/fileListPublished/view.jsx index 70d170079..56d00003b 100644 --- a/ui/js/page/fileListPublished/view.jsx +++ b/ui/js/page/fileListPublished/view.jsx @@ -9,13 +9,53 @@ import lbryio from 'lbryio.js'; import {BusyMessage, Thumbnail} from 'component/common.js'; import FileList from 'component/fileList' -const FileListPublished = (props) => { - // - return ( -
published content
- ) -} +class FileListPublished extends React.Component { + componentDidUpdate() { + if(this.props.publishedContent.length > 0) this._requestPublishReward() + } + _requestPublishReward() { + 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(() => {}) + } + }) + } + + render() { + const { + publishedContent, + fetching, + navigate, + } = this.props + + if (fetching) { + return ( +
+ +
+ ); + } else if (!publishedContent.length) { + return ( +
+ You haven't downloaded anything from LBRY yet. Go navigate('discover')} label="search for your first download" />! +
+ ); + } else { + return ( +
+ +
+ ); + } + } +} // const FileListPublished = React.createClass({ // _isMounted: false, diff --git a/ui/js/reducers/claims.js b/ui/js/reducers/claims.js index 3fbf181d6..c758052bc 100644 --- a/ui/js/reducers/claims.js +++ b/ui/js/reducers/claims.js @@ -18,6 +18,23 @@ reducers[types.RESOLVE_URI_COMPLETED] = function(state, action) { }) } +reducers[types.FETCH_MY_CLAIMS_COMPLETED] = function(state, action) { + const { + claims, + } = action.data + const newMine = Object.assign({}, state.mine) + const newById = Object.assign({}, newMine.byId) + + claims.forEach(claim => { + newById[claim.claim_id] = claim + }) + newMine.byId = newById + + return Object.assign({}, state, { + mine: newMine, + }) +} + export default function reducer(state = defaultState, action) { const handler = reducers[action.type]; if (handler) return handler(state, action); diff --git a/ui/js/reducers/file_info.js b/ui/js/reducers/file_info.js index 0023df8f1..292508a2b 100644 --- a/ui/js/reducers/file_info.js +++ b/ui/js/reducers/file_info.js @@ -178,6 +178,27 @@ reducers[types.FETCH_DOWNLOADED_CONTENT_COMPLETED] = function(state, action) { }) } +reducers[types.FETCH_PUBLISHED_CONTENT_COMPLETED] = function(state, action) { + const { + fileInfos + } = action.data + const newByUri = Object.assign({}, state.byUri) + + fileInfos.forEach(fileInfo => { + const uri = lbryuri.build({ + channelName: fileInfo.channel_name, + contentName: fileInfo.name, + }) + + newByUri[uri] = fileInfo + }) + + return Object.assign({}, state, { + byUri: newByUri + }) +} + + export default function reducer(state = defaultState, action) { const handler = reducers[action.type]; if (handler) return handler(state, action); diff --git a/ui/js/selectors/claims.js b/ui/js/selectors/claims.js index 3b35ce92f..45007b94e 100644 --- a/ui/js/selectors/claims.js +++ b/ui/js/selectors/claims.js @@ -63,3 +63,27 @@ export const makeSelectSourceForUri = () => { (source) => source ) } + +export const selectMyClaims = createSelector( + _selectState, + (state) => state.mine || {} +) + +export const selectMyClaimsById = createSelector( + selectMyClaims, + (mine) => mine.byId || {} +) + +export const selectMyClaimsOutpoints = createSelector( + selectMyClaimsById, + (byId) => { + const outpoints = [] + Object.keys(byId).forEach(key => { + const claim = byId[key] + const outpoint = `${claim.txid}:${claim.nout}` + outpoints.push(outpoint) + }) + + return outpoints + } +) diff --git a/ui/js/selectors/file_info.js b/ui/js/selectors/file_info.js index 0a114ba0f..7c9439495 100644 --- a/ui/js/selectors/file_info.js +++ b/ui/js/selectors/file_info.js @@ -5,6 +5,9 @@ import { selectCurrentUri, selectCurrentPage, } from 'selectors/app' +import { + selectMyClaimsOutpoints, +} from 'selectors/claims' export const _selectState = state => state.fileInfo || {} @@ -149,3 +152,21 @@ export const selectDownloadedFileInfo = createSelector( return fileInfoList } ) + +export const selectPublishedFileInfo = createSelector( + selectAllFileInfoByUri, + selectMyClaimsOutpoints, + (byUri, outpoints) => { + const fileInfos = [] + outpoints.forEach(outpoint => { + Object.keys(byUri).forEach(key => { + const fileInfo = byUri[key] + if (fileInfo.outpoint == outpoint) { + fileInfos.push(fileInfo) + } + }) + }) + + return fileInfos + } +)