Show rule info when a category is selected

This commit is contained in:
sonny 2020-05-24 23:07:03 +02:00
parent 391cc98e35
commit b6b7ae3997
3 changed files with 14 additions and 4 deletions

View file

@ -1,8 +1,8 @@
import React from 'react'; import React from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { CATEGORY_TYPE, RULE_TYPE } from '../../constants.js';
import { selectPost } from '../../actions/posts.js'; import { selectPost } from '../../actions/posts.js';
import { formatDatetime } from '../../../../utils.js'; import { formatDatetime } from '../../../../utils.js';
class PostItem extends React.Component { class PostItem extends React.Component {
@ -28,6 +28,9 @@ class PostItem extends React.Component {
<span className="posts-info__date" title={publicationDate}> <span className="posts-info__date" title={publicationDate}>
{publicationDate} {post.author && `By ${post.author}`} {publicationDate} {post.author && `By ${post.author}`}
</span> </span>
{this.props.selected.type == CATEGORY_TYPE && (
<span className="badge">{this.props.rule.name}</span>
)}
<a <a
className="posts-info__link" className="posts-info__link"
href={post.url} href={post.url}
@ -42,8 +45,12 @@ class PostItem extends React.Component {
} }
} }
const mapStateToProps = state => ({
selected: state.selected.item,
});
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
selectPost: post => dispatch(selectPost(post)), selectPost: post => dispatch(selectPost(post)),
}); });
export default connect(null, mapDispatchToProps)(PostItem); export default connect(mapStateToProps, mapDispatchToProps)(PostItem);

View file

@ -9,12 +9,11 @@ class RuleItem extends React.Component {
}); });
const postItems = posts.map(post => { const postItems = posts.map(post => {
return <PostItem key={post.id} post={post} />; return <PostItem key={post.id} post={post} rule={this.props.rule} />;
}); });
return ( return (
<section className="posts-section"> <section className="posts-section">
<h3 className="posts-section__name">{this.props.rule.name}</h3>
<ul className="posts">{postItems}</ul> <ul className="posts">{postItems}</ul>
</section> </section>
); );

View file

@ -12,6 +12,10 @@
padding: 10px; padding: 10px;
&:first-child {
padding: 0 10px 10px 10px;
}
&:hover { &:hover {
cursor: pointer; cursor: pointer;
background-color: $gainsboro; background-color: $gainsboro;