Skip to content

Commit

Permalink
Add authFetching check to PostRecommendation component
Browse files Browse the repository at this point in the history
  • Loading branch information
jm90m committed Oct 19, 2017
1 parent 0809d4e commit e95a28f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/app/Sidebar/RightSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getIsAuthenticated,
getAuthenticatedUser,
getFollowingList,
getIsAuthFetching,
} from '../../reducers';

import InterestingPeople from '../../components/Sidebar/InterestingPeople';
Expand All @@ -20,13 +21,15 @@ import PostRecommendation from '../../components/Sidebar/PostRecommendation';
authenticated: getIsAuthenticated(state),
authenticatedUser: getAuthenticatedUser(state),
followingList: getFollowingList(state),
isAuthFetching: getIsAuthFetching(state),
}),
)
export default class RightSidebar extends React.Component {
static propTypes = {
authenticated: PropTypes.bool.isRequired,
authenticatedUser: PropTypes.shape().isRequired,
followingList: PropTypes.arrayOf(PropTypes.string).isRequired,
isAuthFetching: PropTypes.bool.isRequired,
showPostRecommendation: PropTypes.bool,
};

Expand Down Expand Up @@ -58,7 +61,7 @@ export default class RightSidebar extends React.Component {
});

render() {
const { authenticated, authenticatedUser, showPostRecommendation } = this.props;
const { authenticated, authenticatedUser, showPostRecommendation, isAuthFetching } = this.props;
const InterestingPeopleWithData = () => (
<InterestingPeople
users={this.state.randomPeople}
Expand All @@ -82,7 +85,7 @@ export default class RightSidebar extends React.Component {
/>
</Switch>
: <SignUp />}
{showPostRecommendation && <PostRecommendation />}
{showPostRecommendation && <PostRecommendation isAuthFetching={isAuthFetching} />}
</div>
);
}
Expand Down
15 changes: 13 additions & 2 deletions src/components/Sidebar/PostRecommendation.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class PostRecommendation extends Component {
location: PropTypes.shape().isRequired,
intl: PropTypes.shape().isRequired,
history: PropTypes.shape().isRequired,
isAuthFetching: PropTypes.bool.isRequired,
};

state = {
Expand All @@ -22,8 +23,8 @@ class PostRecommendation extends Component {
};

componentWillMount() {
const { location } = this.props;
if (location.pathname !== '/') {
const { location, isAuthFetching } = this.props;
if (!isAuthFetching && location.pathname !== '/') {
const currentAuthor = location.pathname.split('/')[2].replace('@', '');
this.setState({
loading: true,
Expand All @@ -32,6 +33,16 @@ class PostRecommendation extends Component {
}
}

componentWillReceiveProps(nextProps) {
if (this.props.isAuthFetching !== nextProps.isAuthFetching) {
const currentAuthor = this.props.location.pathname.split('/')[2].replace('@', '');
this.setState({
loading: true,
});
this.getPostsByAuthor(currentAuthor);
}
}

getPostsByAuthor = (author) => {
steemAPI
.getDiscussionsByBlogAsync({
Expand Down

0 comments on commit e95a28f

Please sign in to comment.