diff --git a/nc-news/src/App.css b/nc-news/src/App.css index 97009a5..464ffee 100644 --- a/nc-news/src/App.css +++ b/nc-news/src/App.css @@ -93,24 +93,8 @@ p { min-width: 100%; } -.TopicCard { - box-shadow: 2px 2px 5px 2px gray; - - border-radius: 5px; - margin: 10px; - padding: 5px; - height: 25%; - min-height: 25%; - max-height: 25%; - width: 95%; - - display: flex; - align-items: center; - justify-content: center; - flex-wrap: nowrap; -} .ArticlePage-Header { - font-size: medium; + font-size: x-large; display: flex; align-items: center; justify-content: center; @@ -134,6 +118,15 @@ p { display: flex; } +.ArticlePage-VotesDiv { + padding: 10px; + margin: 10px; + font-size: medium; + display: flex; + align-items: center; + justify-content: center; +} + .ArticlePage-Body { text-align: justify; padding: 10px; @@ -144,6 +137,23 @@ p { justify-content: center; } +.TopicCard { + box-shadow: 2px 2px 5px 2px gray; + + border-radius: 5px; + margin: 10px; + padding: 5px; + height: 25%; + min-height: 25%; + max-height: 25%; + width: 95%; + + display: flex; + align-items: center; + justify-content: center; + flex-wrap: nowrap; +} + .TopicCard-Slug { text-decoration: underline red solid 2px; font-size: x-large; diff --git a/nc-news/src/api.js b/nc-news/src/api.js index 077d5bc..8a20d0f 100644 --- a/nc-news/src/api.js +++ b/nc-news/src/api.js @@ -6,7 +6,6 @@ export function fetchArticles(params) { url = `https://callums-be-project.herokuapp.com/api/articles?topic=${params}` } - console.log(url) return axios.get(url) .then(({ data: { articles } }) => { @@ -28,4 +27,12 @@ export function fetchTopics() { return topics; }) -}; \ No newline at end of file +}; + +export function patchArticle(article_id, patchData) { + return axios.patch(`https://callums-be-project.herokuapp.com/api/articles/${article_id}`, patchData) + .then(({ data: { article } }) => { + + return article; + }) +} \ No newline at end of file diff --git a/nc-news/src/components/ArticleList.js b/nc-news/src/components/ArticleList.js index ed11f24..ac046e5 100644 --- a/nc-news/src/components/ArticleList.js +++ b/nc-news/src/components/ArticleList.js @@ -11,7 +11,6 @@ export default function ArticleList() { const params = useParams(); - console.log(params) useEffect(() => { fetchArticles(params.topic) .then((articles) => { @@ -30,8 +29,8 @@ export default function ArticleList() {
{articlesState.map(article => { return ( - - + + ) })} diff --git a/nc-news/src/components/ArticlePage.js b/nc-news/src/components/ArticlePage.js index 407dc26..3b14c19 100644 --- a/nc-news/src/components/ArticlePage.js +++ b/nc-news/src/components/ArticlePage.js @@ -1,11 +1,25 @@ import { useState, useEffect } from "react"; -import { fetchArticle } from "../api"; +import { fetchArticle, patchArticle } from "../api"; export default function ArticlePage({ article_id }) { const [articleState, setArticleState] = useState({}); const [loadingState, setLoadingState] = useState(true); + const changeVotes = (voteChange) => { + let newArticleState = { ...articleState } + newArticleState.votes += voteChange + setArticleState(newArticleState) + + patchArticle(article_id, { votes: voteChange }) + .then((article) => { + return article; + }) + .catch(error => { + window.alert('Could not communicate with server, please try again later.') + }) + } + useEffect(() => { fetchArticle(article_id) .then((article) => { @@ -13,23 +27,30 @@ export default function ArticlePage({ article_id }) { setLoadingState(false) }) }, - []) - - return ( -
-

{articleState.topic}

-

{articleState.title}

-
-

{articleState.author}

-
+ [article_id]) + + + if (loadingState) { + return

Loading...

+ } else { + return ( +
+

{articleState.topic}

+

{articleState.title}

+
+

{articleState.author}

+
-

{articleState.votes}


-

{articleState.comment_count}


+
+

{articleState.votes}


+
+

{articleState.comment_count}


{articleState.body}

-
- ) -} \ No newline at end of file +
+ ) + } +}