diff --git a/src/client/components/Sidebar/UlogGamesExchanges.js b/src/client/components/Sidebar/UlogGamesExchanges.js index d1c7d019e8..7391234c3c 100644 --- a/src/client/components/Sidebar/UlogGamesExchanges.js +++ b/src/client/components/Sidebar/UlogGamesExchanges.js @@ -80,62 +80,100 @@ class UlogGamesExchanges extends React.Component { this.state = { users: [], loading: true, - noUsers: false, allUsers: [], + ulogGames: [], showUlogsGames: true, }; - this.getCertifiedUloggers = this.getCertifiedUloggers.bind(this); + this.getUlogGames = this.getUlogGames.bind(this); this.getUloggersTVVideaos = this.getUloggersTVVideaos.bind(this); } componentDidMount() { if (!this.props.isFetchingFollowingList) { - this.getCertifiedUloggers(); + this.getUlogGames(); this.getUloggersTVVideaos(); } } componentWillReceiveProps(nextProps) { if (!nextProps.isFetchingFollowingList) { - this.getCertifiedUloggers(); + this.getUlogGames(); this.getUloggersTVVideaos(); } } - getCertifiedUloggers() { + getUlogGames() { steemAPI - .sendAsync('call', ['follow_api', 'get_following', ['uloggers', '', 'blog', 1000]]) + .sendAsync('call', ['follow_api', 'get_following', ['uloggers', '', 'blog', 100]]) .then(result => { - const users = _.shuffle(result) - // .slice(0, 5) + + // get certified ulogger names + const certifiedUloggerNames = _.sortBy(result, 'following') .map(user => { let name = _.get(user, 0); if (_.isEmpty(name)) { name = _.get(user, 'following'); } - return { - name, - }; - }); - if (users.length > 0) { - this.setState({ - users, - allUsers: result, - loading: false, - noUsers: false, + return name; }); - } else { - this.setState({ - noUsers: true, + + // if there are certified uloggers + if (certifiedUloggerNames.length > 0) { + // get the latest posts from each certified ulogger + certifiedUloggerNames.forEach(userName => { + var query = { + tag: userName, // Filter the results by a specific post author + limit: 5, // Limit the number of posts returned + }; + this.setState({ + loading: true, + }); + + // call STEEM API to get the latest posts from certified ulogger + steemAPI + .sendAsync('call', ['condenser_api', 'get_discussions_by_blog', [query]]) + .then(result => { + const posts = Array.isArray(result) ? result : []; + const post = posts[0]; + this.setState({ + loading: false, + }); + + // filter-out posts from non-certified users + if(certifiedUloggerNames.indexOf(post.author) < 0) return; + + // filter posts that have been created more than 7 days ago + const today = new Date(); + const sevenDaysAgo = new Date(); + sevenDaysAgo.setDate(today.getDate() - 7); + const created = new Date(post.created); + if(created < sevenDaysAgo) return; + + // filter posts that do not contain #ulog-games tag + const tags = JSON.parse(post.json_metadata).tags; + if (tags.indexOf("ulog-games") < 0) return; + + // push post to array + let { ulogGames } = this.state; + ulogGames.push( + { + author: post.author, + permlink: post.permlink, + created: post.created + } + ); + + // set array to state + this.setState({ + ulogGames, + }); + }); + }); + } - }) - .catch(() => { - this.setState({ - noUsers: true, - }); }); } @@ -154,11 +192,8 @@ class UlogGamesExchanges extends React.Component { } render() { - const { users, loading, noUsers, uloggersTvVideos } = this.state; + const { loading, ulogGames, uloggersTvVideos } = this.state; const { authenticated } = this.props; - if (noUsers) { - return
; - } if (loading) { return