-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Consuning API) Getting articles from an endpoint to display on t…
…he landing page (#22) - User shoukd be able to view sample articles and trending articles [Finishes #165909011]
- Loading branch information
1 parent
b74be53
commit e6abc07
Showing
31 changed files
with
863 additions
and
1,395 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,13 @@ | ||
import axios from 'axios'; | ||
import GET_ARTICLES from './types'; | ||
|
||
const fetchArticles = () => dispatch => ( | ||
axios.get(`${process.env.baseURL}/articles/`) | ||
.then((response) => { | ||
dispatch({ | ||
type: GET_ARTICLES, | ||
payload: response.data.results, | ||
}); | ||
}) | ||
); | ||
export default fetchArticles; |
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,2 @@ | ||
const GET_ARTICLES = 'GET_ARTICLES'; | ||
export default GET_ARTICLES; |
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,19 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import SampleArticles from './index'; | ||
import TrendingArticles from './TrendingArticles'; | ||
|
||
const ArticleContainer = ({ articles }) => ( | ||
<div className="wrapper"> | ||
<SampleArticles articles={articles} /> | ||
<TrendingArticles articles={articles} /> | ||
</div> | ||
); | ||
|
||
ArticleContainer.defaultProps = { | ||
articles: [], | ||
}; | ||
ArticleContainer.propTypes = { | ||
articles: PropTypes.arrayOf(PropTypes.object), | ||
}; | ||
export default ArticleContainer; |
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,42 @@ | ||
|
||
import React from 'react'; | ||
import PropTypes, { shape } from 'prop-types'; | ||
import ArticleImage from '../../assets/images/article_image.jpeg'; | ||
|
||
|
||
const DisplaySampleArticles = ({ sampleArticle, articleDate }) => ( | ||
<div className="sample-articles"> | ||
<div className="article-image"> | ||
<img src={ArticleImage} alt="Article" /> | ||
</div> | ||
<div className="trending-articles"> | ||
<h4>{sampleArticle.title}</h4> | ||
<h6 className="sample_article_start"> | ||
{sampleArticle.description} | ||
</h6> | ||
<p className="author_name"> | ||
Created By | ||
{' '} | ||
<b>{sampleArticle.author.username}</b> | ||
</p> | ||
<h6> | ||
{ articleDate } | ||
{' '} | ||
- | ||
{sampleArticle.article_read_time} | ||
</h6> | ||
</div> | ||
</div> | ||
); | ||
|
||
DisplaySampleArticles.defaultProps = { | ||
sampleArticle: shape(PropTypes.object.isRequired), | ||
articleDate: '', | ||
}; | ||
DisplaySampleArticles.propTypes = { | ||
sampleArticle: shape(PropTypes.object.isRequired), | ||
articleDate: PropTypes.string, | ||
}; | ||
|
||
|
||
export default DisplaySampleArticles; |
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,46 @@ | ||
|
||
import React from 'react'; | ||
import PropTypes, { shape } from 'prop-types'; | ||
import BookmarkImage from '../../assets/images/bookmark.png'; | ||
|
||
|
||
const DisplayTrendingArticles = ({ trendingArticles, articleDate }) => ( | ||
<div className="trending"> | ||
<div className="trending-articles"> | ||
<h4>{trendingArticles.title}</h4> | ||
<p className="author_name"> | ||
|
||
<b> | ||
{' '} | ||
Created By | ||
{' '} | ||
{trendingArticles.author.username} | ||
</b> | ||
</p> | ||
<h6> | ||
{ articleDate } | ||
- | ||
{trendingArticles.article_read_time} | ||
</h6> | ||
</div> | ||
<div className="book-mark-holder"> | ||
<img | ||
src={BookmarkImage} | ||
alt="article-bookmark-icon" | ||
className="bookmark-image" | ||
/> | ||
</div> | ||
<br /> | ||
</div> | ||
); | ||
|
||
DisplayTrendingArticles.defaultProps = { | ||
trendingArticles: shape(PropTypes.object.isRequired), | ||
articleDate: '', | ||
}; | ||
DisplayTrendingArticles.propTypes = { | ||
trendingArticles: shape(PropTypes.object.isRequired), | ||
articleDate: PropTypes.string, | ||
}; | ||
|
||
export default DisplayTrendingArticles; |
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,44 @@ | ||
import React from 'react'; | ||
import moment from 'moment'; | ||
import PropTypes from 'prop-types'; | ||
import DisplayTrendingArticles from './DisplayTrendingArticles'; | ||
import getRandomArticles from '../../helpers/randomArticles'; | ||
|
||
const TrendingArticles = ({ articles }) => { | ||
const randomArray = getRandomArticles(5, articles); | ||
return ( | ||
<div> | ||
<h1>Trending</h1> | ||
<br /> | ||
<hr /> | ||
<br /> | ||
{articles.length > 0 ? ( | ||
randomArray.map((article) => { | ||
const articleDate = moment( | ||
article.createdAt.slice(0, 10), | ||
).format('LL'); | ||
return ( | ||
<div key={article.id}> | ||
<DisplayTrendingArticles | ||
articleID={article.id} | ||
trendingArticles={article} | ||
articleDate={articleDate} | ||
/> | ||
</div> | ||
); | ||
}) | ||
) : ( | ||
<div>No Trending Articles where Found !!!!</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
TrendingArticles.defaultProps = { | ||
articles: [], | ||
}; | ||
TrendingArticles.propTypes = { | ||
articles: PropTypes.arrayOf(PropTypes.object), | ||
}; | ||
|
||
export default TrendingArticles; |
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,38 @@ | ||
import React from 'react'; | ||
import moment from 'moment'; | ||
import PropTypes from 'prop-types'; | ||
import DisplaySampleArticles from './DisplaySampleArticles'; | ||
|
||
|
||
const SampleArticles = ({ articles }) => ( | ||
<div> | ||
{ | ||
articles.length > 0 ? ( | ||
articles.map((article) => { | ||
const articleDate = moment(article.createdAt.slice(0, 10)).format( | ||
'LL', | ||
); | ||
return ( | ||
<div key={article.id}> | ||
<DisplaySampleArticles | ||
sampleArticle={article} | ||
articleDate={articleDate} | ||
/> | ||
</div> | ||
|
||
); | ||
}) | ||
) : ( | ||
<div>No Posts where Found !!!!</div> | ||
)} | ||
</div> | ||
); | ||
|
||
SampleArticles.defaultProps = { | ||
articles: [], | ||
}; | ||
SampleArticles.propTypes = { | ||
articles: PropTypes.arrayOf(PropTypes.object), | ||
}; | ||
|
||
export default SampleArticles; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.