diff --git a/src/newsreader/js/pages/homepage/components/PostModal.js b/src/newsreader/js/pages/homepage/components/PostModal.js index ee1c983..09867c9 100644 --- a/src/newsreader/js/pages/homepage/components/PostModal.js +++ b/src/newsreader/js/pages/homepage/components/PostModal.js @@ -49,30 +49,40 @@ class PostModal extends React.Component { render() { const post = this.props.post; + const token = Cookies.get('csrftoken'); const publicationDate = formatDatetime(post.publicationDate); const titleClassName = post.read ? 'post__title post__title--read' : 'post__title'; - let ruleUrl = ''; + const readButtonDisabled = post.read || this.props.isMarkingPost; - if (this.props.rule.type === SUBREDDIT) { - ruleUrl = `${this.props.subredditUrl}/${this.props.rule.id}/`; - } else if (this.props.rule.type === TWITTER_TIMELINE) { - ruleUrl = `${this.props.timelineUrl}/${this.props.rule.id}/`; - } else { - ruleUrl = `${this.props.feedUrl}/${this.props.rule.id}/`; + let ruleUrl = ''; + switch (this.props.rule.type) { + case SUBREDDIT: + ruleUrl = `${this.props.subredditUrl}/${this.props.rule.id}/`; + break; + case TWITTER_TIMELINE: + ruleUrl = `${this.props.timelineUrl}/${this.props.rule.id}/`; + break; + default: + ruleUrl = `${this.props.feedUrl}/${this.props.rule.id}/`; + break; } return (
- {/* TODO: make button functional */} - Mark as read - !readButtonDisabled && this.props.markPostRead(post, token)} + > + Mark as read + +

{`${post.title} `}

@@ -121,4 +131,7 @@ const mapDispatchToProps = dispatch => ({ markPostRead: (post, token) => dispatch(markPostRead(post, token)), }); -export default connect(null, mapDispatchToProps)(PostModal); +// TODO use different boolean for saving mark post as read state +const mapStateToProps = state => ({ isMarkingPost: state.posts.isFetching }); + +export default connect(mapStateToProps, mapDispatchToProps)(PostModal);