diff --git a/README.md b/README.md index 9ff48dd..78fb9f8 100644 --- a/README.md +++ b/README.md @@ -49,9 +49,9 @@ Edit this document to include your answers after each question. Make sure to lea Your finished project must include all of the following requirements: -* [ ] Look through the HTML code and familiarize yourself with the different sections. Some of them already exist, but some need to be filled it. DO NOT add any code to the HTML file itself. +* [x] Look through the HTML code and familiarize yourself with the different sections. Some of them already exist, but some need to be filled it. DO NOT add any code to the HTML file itself. -* [ ] Following the instructions in the `Header/index.js` file, create the Header component. +* [x] Following the instructions in the `Header/index.js` file, create the Header component. * [ ] Following the instructions in the `Tabs/index.js` file, create individual Tabs components. diff --git a/components/Cards/index.js b/components/Cards/index.js index 1482e60..6691ac4 100644 --- a/components/Cards/index.js +++ b/components/Cards/index.js @@ -17,3 +17,51 @@ // // // Create a card for each of the articles and add the card to the DOM. + +const cardsContainer = document.querySelector('.cards-container'); + +axios.get('https://lambda-times-backend.herokuapp.com/articles') + .then(x => { + articlesByTopic = x.data.articles; + topicsCom(articlesByTopic); + }) + + .catch(error => { + console.log('There is an error in your Cards/index.js file', error) + }) + + +function topicsCom(objectArticlesByTopic) { + + Object.keys(objectArticlesByTopic).forEach(topic => { + let articles = objectArticlesByTopic[topic]; + articles.forEach(article => cardsContainer.append(cardComponent(article, topic))); + }) +} + +function cardComponent(articleObj, topic) { + const card = document.createElement('div'), + headline = document.createElement('div'), + author = document.createElement('div'), + imgContainer = document.createElement('div'), + imgSrc = document.createElement('img'), + authorName = document.createElement('span'); + + + headline.textContent = articleObj.headline; + imgSrc.src = articleObj.authorPhoto; + authorName.textContent = articleObj.authorName; + + card.append(author); + card.append(headline); + author.append(authorName); + author.append(imgContainer); + imgContainer.append(imgSrc); + + card.classList.add('card'); + headline.classList.add('headline'); + author.classList.add('author'); + imgContainer.classList.add('img-container'); + + return card; +} \ No newline at end of file diff --git a/components/Header/index.js b/components/Header/index.js index c41ba8c..b4050e4 100644 --- a/components/Header/index.js +++ b/components/Header/index.js @@ -7,6 +7,37 @@ //