Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shaelie raby #265

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/components/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,32 @@ const Card = (article) => {
// </div>
// </div>
//
const cardWrap = document.createElement("div");
const headline = document.createElement("div");
const author = document.createElement("div");
const imgContainer = document.createElement("div");
const img = document.createElement("img");
const authorName = document.createElement("span");

cardWrap.classList.add("card");
headline.classList.add("headline");
author.classList.add("author");
imgContainer.classList.add("img-container");

imgContainer.appendChild(img);
author.appendChild(imgContainer);
author.appendChild(authorName);
cardWrap.appendChild(headline)
cardWrap.appendChild(author);

headline.textContent = article.headline;
img.src = article.authorPhoto;
authorName.textContent = `BY ${article.authorName}`;
cardWrap.addEventListener("click", () => {
console.log(article.headline)
})
//what
return cardWrap;
}

const cardAppender = (selector) => {
Expand All @@ -28,6 +54,24 @@ const cardAppender = (selector) => {
// Create a card from each and every article object in the response, using the Card component.
// Append each card to the element in the DOM that matches the selector passed to the function.
//
const cardContainer = document.querySelector(selector);

fetch('http://localhost:5001/api/articles')
.then(response => response.json())
.then(data => {
for (const category in data) {
if(Array.isArray(data[category])) {
data[category].forEach(article => {
const card = Card(article);
cardContainer.appendChild(card);
});
}
}
})
.catch(error => {
console.log('Error', error);
});
}


export { Card, cardAppender }
35 changes: 33 additions & 2 deletions src/components/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,28 @@ const Header = (title, date, temp) => {
// <span class="temp">{ temp }</span>
// </div>
//
}
const headingWrap = document.createElement("div");
const dateSpan = document.createElement("span");
const tempSpan = document.createElement("span");
const titleHead = document.createElement("h1");

dateSpan.textContent = date;
tempSpan.textContent = temp;
titleHead.textContent = title;

headingWrap.classList.add("header");
dateSpan.classList.add("date");
tempSpan.classList.add("temp");

headingWrap.appendChild(dateSpan);
headingWrap.appendChild(titleHead);
headingWrap.appendChild(tempSpan);


return headingWrap;

}

const headerAppender = (selector) => {
// TASK 2
// ---------------------
Expand All @@ -26,6 +46,17 @@ const headerAppender = (selector) => {
// We are taking care of passing in the correct selector on line 16,
// so all that you need to do is pass it into the querySelector method
// for the tests to work!
}

const headerContainer = document.querySelector(selector);
const existingHeader = headerContainer.querySelector('.header');
if(existingHeader){
headerContainer.removeChild(existingHeader);
}
const header = Header();
headerContainer.appendChild(header);
};
window.addEventListener("DOMContentLoaded", () => {
headerAppender(".header-container")
})

export { Header, headerAppender }
23 changes: 23 additions & 0 deletions src/components/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ const Tabs = (topics) => {
// <div class="tab">technology</div>
// </div>
//
const topicWrap = document.createElement("div");

topicWrap.classList.add("topics");

topics.forEach(tab => {
const tabs = document.createElement("div");
tabs.classList.add("tab");
tabs.textContent = tab;
topicWrap.appendChild(tabs);

});
return topicWrap
}

const tabsAppender = (selector) => {
Expand All @@ -23,6 +35,17 @@ const tabsAppender = (selector) => {
// Find the array of topics inside the response, and create the tabs using the Tabs component.
// Append the tabs to the element in the DOM that matches the selector passed to the function.
//
fetch(`http://localhost:5001/api/topics`)
.then(response => response.json())
.then(data => {
const topics = data.topics;
const tabs = Tabs(topics)
const container = document.querySelector(selector);
container.appendChild(tabs)
})
.catch(error => {
console.error("Error grabbing the gudstuff", error)
})
}

export { Tabs, tabsAppender }