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,44 +21,33 @@ export default class Blog extends Component {
render () {
const md = MarkdownIt()
let postsHTML
if (this.props.isLoading) {
return (
<div className={`${contentStyle.content}`} id="blog" role="region" aria-label="Blog posts">
<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} />
postsHTML = <Spinner />
} else {
const posts = this.props.posts.sort((a, b) => {
return new Date(b.published) - new Date(a.published)
})
if (posts.length < 1) {
postsHTML = (
<div>
<span>No posts found</span>
</div>
<Spinner />
</div>
)
}
const posts = this.props.posts.sort((a, b) => {
return new Date(b.published) - new Date(a.published)
})
let postsHTML = posts.map((post) =>
<div key={post.title} className={styles.postListItem} role="listitem">
<div className={styles.postHeader} >
<a href={post.link} className={styles.postTitle}>{post.title}</a>
<span className={styles.postDate}>{post.published}</span>
</div>
<div dangerouslySetInnerHTML={{ __html: md.render(post.summary) }}>
</div>
</div>
)
if (postsHTML.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 className={styles.postHeader} >
<a href={post.link} className={styles.postTitle}>{post.title}</a>
<span className={styles.postDate}>{post.published}</span>
</div>
<div dangerouslySetInnerHTML={{ __html: md.render(post.summary) }}>
</div>
</div>
)
}
}
return (