-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
650 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Link } from 'react-router-dom'; | ||
import unixTimeToDate from '../utils/dateFormatter'; | ||
import extractImageFromBody from '../utils/imageExtractor'; | ||
|
||
const AllArticles = ({ articles }) => (articles ? ( | ||
articles.map(article => ( | ||
<div key={article.id}> | ||
|
||
<div className="home-view-last"> | ||
<img | ||
src={extractImageFromBody(article.body)} | ||
alt="" | ||
/> | ||
|
||
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */} | ||
<h3><Link a href="#" className="title-link">{article.title}</Link></h3> | ||
|
||
<span className="description">{article.description}</span> | ||
<br /> | ||
<span className="author">{article.author.username}</span> | ||
<br /> | ||
<span className="meta"> | ||
{unixTimeToDate(article.created_at)} | ||
. | ||
{article.reading_time} | ||
read | ||
</span> | ||
</div> | ||
</div> | ||
)) | ||
) : ( | ||
<div>Loading...</div> | ||
)); | ||
|
||
AllArticles.propTypes = { | ||
articles: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, | ||
PropTypes.string, PropTypes.array])), | ||
}; | ||
|
||
AllArticles.defaultProps = { | ||
articles: [], | ||
}; | ||
export default AllArticles; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Link } from 'react-router-dom'; | ||
import unixTimeToDate from '../utils/dateFormatter'; | ||
import extractImageFromBody from '../utils/imageExtractor'; | ||
|
||
const ArticlesByCriteria = ({ articles, start, end }) => (articles ? ( | ||
articles.slice(start, end).map(article => ( | ||
<div key={article.id}> | ||
<img src={extractImageFromBody(article.body)} alt="" /> | ||
<h3> | ||
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */} | ||
<Link className="title-link"> | ||
{article.title} | ||
</Link> | ||
</h3> | ||
<span className="author">{article.author.username}</span> | ||
<br /> | ||
<span className="meta"> | ||
{unixTimeToDate(article.created_at)} | ||
. | ||
{article.reading_time} | ||
read | ||
</span> | ||
</div> | ||
)) | ||
) : ( | ||
<div>Loading...</div> | ||
)); | ||
|
||
ArticlesByCriteria.propTypes = { | ||
articles: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, | ||
PropTypes.string, PropTypes.array])), | ||
start: PropTypes.number, | ||
end: PropTypes.number, | ||
}; | ||
|
||
ArticlesByCriteria.defaultProps = { | ||
articles: [], | ||
start: 0, | ||
end: 0, | ||
}; | ||
export default ArticlesByCriteria; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,100 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
Container, Row, Col, Card, | ||
} from 'react-bootstrap'; | ||
import AllArticles from './AllArticles'; | ||
import ArticlesByCriteria from './ArticlesByCriteria'; | ||
|
||
const Home = () => ( | ||
<div className="main-container"> | ||
<h3>Home</h3> | ||
</div> | ||
const Home = ({ articles }) => ( | ||
<Container> | ||
<Row> | ||
<Col xs={3}> | ||
<ArticlesByCriteria articles={articles} start={0} end={1} /> | ||
</Col> | ||
|
||
<Col xs={{ offset: 1 }}> | ||
<Row> | ||
<Col> | ||
<div className="home-view"> | ||
<ArticlesByCriteria articles={articles} start={2} end={3} /> | ||
</div> | ||
</Col> | ||
</Row> | ||
|
||
<Row> | ||
<Col> | ||
<div className="home-view"> | ||
<ArticlesByCriteria articles={articles} start={1} end={2} /> | ||
</div> | ||
</Col> | ||
</Row> | ||
|
||
<Row> | ||
<Col> | ||
<div className="home-view"> | ||
<ArticlesByCriteria articles={articles} start={2} end={3} /> | ||
</div> | ||
</Col> | ||
</Row> | ||
</Col> | ||
|
||
<Col xs={3}> | ||
<ArticlesByCriteria articles={articles} start={0} end={1} /> | ||
</Col> | ||
</Row> | ||
|
||
{/* Start Second Section */} | ||
<Row> | ||
<Col> | ||
<Card className="welcome-card"> | ||
<Card.Body> | ||
<Row> | ||
<Col> | ||
<h2>Welcome to Author's Haven</h2> | ||
<br /> | ||
<span className="author"> | ||
We are community of like minded authors to foster | ||
inspiration and innovation by leveraging the modern web. | ||
Whatever your interest, you can always find fresh thinking | ||
and unique perspectives. | ||
</span> | ||
<br /> | ||
</Col> | ||
<Col xs={3}> | ||
<img | ||
src="https://images.unsplash.com/photo-1501504905252-473c47e087f8?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1867&q=80" | ||
alt="" | ||
/> | ||
</Col> | ||
</Row> | ||
</Card.Body> | ||
</Card> | ||
</Col> | ||
</Row> | ||
{/* End Second Section */} | ||
|
||
<Row> | ||
<Col> | ||
<AllArticles articles={articles} /> | ||
</Col> | ||
<Col xs={{ span: 3, offset: 1 }}> | ||
<Row> | ||
<Col> | ||
<h3>Popular on Author's Haven</h3> | ||
<hr /> | ||
</Col> | ||
</Row> | ||
</Col> | ||
</Row> | ||
</Container> | ||
); | ||
Home.propTypes = { | ||
articles: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, | ||
PropTypes.string, PropTypes.array])), | ||
}; | ||
|
||
Home.defaultProps = { | ||
articles: [], | ||
}; | ||
export default Home; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import Home from '../components/Home'; | ||
import { fetchAllArticles } from '../store/actions/articles'; | ||
|
||
export class HomeView extends Component { | ||
componentDidMount() { | ||
fetchAllArticles(); | ||
} | ||
|
||
render() { | ||
const { articles } = this.props; | ||
const items = articles.articles.results; | ||
return <Home articles={items} />; | ||
} | ||
} | ||
|
||
HomeView.propTypes = { | ||
articles: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, | ||
PropTypes.string, PropTypes.array])), | ||
|
||
}; | ||
|
||
HomeView.defaultProps = { | ||
articles: [], | ||
}; | ||
export const mapStateToProps = state => ({ articles: state.articles }); | ||
export const mapDispatchToProps = dispatch => ({ | ||
fetchAllArticles: () => dispatch(fetchAllArticles()), | ||
}); | ||
export default connect( | ||
mapStateToProps, | ||
fetchAllArticles(), | ||
)(HomeView); |
Oops, something went wrong.