Remove duplicate code

This commit is contained in:
LordMathis 2020-01-11 16:11:41 +01:00
parent e2be492667
commit 46143b832f
No known key found for this signature in database
GPG Key ID: 575849FD91CE470C
1 changed files with 24 additions and 35 deletions

View File

@ -21,28 +21,23 @@ export default class Blog extends Component {
render () { render () {
const md = MarkdownIt() const md = MarkdownIt()
let postsHTML
if (this.props.isLoading) { if (this.props.isLoading) {
return ( postsHTML = <Spinner />
<div className={`${contentStyle.content}`} id="blog" role="region" aria-label="Blog posts"> } else {
<div className={styles.headerContainer}>
<Header header={'Blog'} role="heading" aria-level="2"/>
<SearchBox searchString={this.props.searchString}
expanded={this.props.expanded}
handleChange={this.props.handleChange}
handleFocus={this.props.handleFocus}
handleBlur={this.props.handleBlur}
handleSearch={this.props.handleSearch} />
</div>
<Spinner />
</div>
)
}
const posts = this.props.posts.sort((a, b) => { const posts = this.props.posts.sort((a, b) => {
return new Date(b.published) - new Date(a.published) return new Date(b.published) - new Date(a.published)
}) })
let postsHTML = posts.map((post) =>
if (posts.length < 1) {
postsHTML = (
<div>
<span>No posts found</span>
</div>
)
} else {
postsHTML = posts.map((post) =>
<div key={post.title} className={styles.postListItem} role="listitem"> <div key={post.title} className={styles.postListItem} role="listitem">
<div className={styles.postHeader} > <div className={styles.postHeader} >
<a href={post.link} className={styles.postTitle}>{post.title}</a> <a href={post.link} className={styles.postTitle}>{post.title}</a>
@ -52,13 +47,7 @@ export default class Blog extends Component {
</div> </div>
</div> </div>
) )
}
if (postsHTML.length < 1) {
postsHTML = (
<div>
<span>No posts found</span>
</div>
)
} }
return ( return (