diff --git a/README.md b/README.md index f2e0c4a..17fc9a4 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,5 @@ -# Responsive News Reader +# Responsive news reader -Let's create a responsive news reader website. To get the latest news the app will display we are going to use [News API](https://newsapi.org/). As with the Weather and Unsplash APIs, you will need to register with the service to obtain an API key. +This is a simple tech news app which displays the top 5 news stories when the reload button is pressed. -## Objectives - -- [ ] Create a responsive layout that works well and looks good at mobile, tablet and desktop screen sizes. Please create the mobile version first, then tablet and then desktop. - -- [ ] Fetch news articles from News API and display them including title, image, description, publication, date and link to article. - -- [ ] Display images for tablet and desktop screens only - -- [ ] Implement a feature of your choice - -## Stretch goals - -- [ ] Implement pagination which allows you to get the next 20 results and display them - -- [ ] Add search functionality which allows the user to retrieve news about a particular topic - -## Instructions - -- Fork and clone this repo -- Commit your changes frequently with short and descriptive commit messages -- Create a pull request when complete -- We want to see great looking webpages -- Your code should have consistent indentation and sensible naming -- Use lots of concise functions with a clear purpose -- Add code comments where it is not immediately obvious what your code does -- Your code should not throw errors and handle edge cases gracefully. For example not break if server fails to return expected results - -## README.md - -When finished, include a README.md in your repo. This should explain what the project is, how to run it and how to use it. Someone who is not familiar with the project should be able to look at it and understand what it is and what to do with it. +The user can also change the colours by pressing the invert colour button & can toggle whether they see the description or not. \ No newline at end of file diff --git a/assets/index.js b/assets/index.js new file mode 100644 index 0000000..fe4595b --- /dev/null +++ b/assets/index.js @@ -0,0 +1,66 @@ +/* News App CSS file */ +const newAPIKey = 'd05cdaa1109d496ebc3443d5ea54ba16'; +const categorySearch = document.querySelector('#content__nav--links'); +const indvCategory = document.querySelector('#category-link'); +const newsArticleArea = document.querySelector('#thumbs'); +const invertButton = document.querySelector('#invert-btn'); +const appScreen = document.querySelector('#app'); +const descriptionToggle = document.querySelector('#descrption-toggle'); + +function createURL(indvCategory){ + return `https://newsapi.org/v2/top-headlines?category=technology&country=gb&apiKey=${newAPIKey}&pagesize=5`; +} + +function display(newsData){ + let newsArticles = newsData.articles.map(function(article){ + return ` +
+ +

${article.title}

+

${article.description}

+

${article.publishedAt}

+
+
+ ` + }).join(''); + newsArticleArea.innerHTML = newsArticles; +} + +function invertColor(){ + if(invertButton.className.match(/(?:|\s) clicked(?!\S)/)){ + appScreen.className = appScreen.className.replace(' clicked', ''); + invertButton.className = invertButton.className.replace(' clicked', ''); + } else { + appScreen.className += ' clicked'; + invertButton.className += ' clicked'; + } +} + +function toggleDesc(){ + const newsDesc = Array.from(document.getElementsByClassName('news-desc')); + if(descriptionToggle.className.match(/(?:|\s) toggle-on(?!\s)/)){ + newsDesc.forEach(function(el){ + el.className = el.className.replace(' toggle-on', ''); + }) + descriptionToggle.className = descriptionToggle.className.replace(' toggle-on', ''); + } else { + newsDesc.forEach(function(el){ + el.className += ' toggle-on'; + }) + descriptionToggle.className += ' toggle-on'; + } +} + +function newsSearch(e){ + e.preventDefault(); + fetch(createURL(e.target)) + .then(function(response){ + return response.json(); + }).then(function(newsData){ + return display(newsData); + }) +} + +categorySearch.addEventListener("click", newsSearch); +invertButton.addEventListener('click', invertColor); +descriptionToggle.addEventListener('click', toggleDesc); \ No newline at end of file diff --git a/assets/style.css b/assets/style.css new file mode 100644 index 0000000..46f80b0 --- /dev/null +++ b/assets/style.css @@ -0,0 +1,146 @@ +* { + box-sizing: inherit; +} + +body { + box-sizing: border-box; + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; +} + +.app { + display: flex; + flex-direction: column; + height: 100vh; +} + +.clicked { + filter: invert(100%); +} + +.content__body--title { + font-size: 3em; +} + +.masthead { + /* flex: 2; */ + justify-content: flex-start; + background: mediumpurple; +} + +.masthead__logo { + font-size: 1em; +} + +.masthead__logo--subtitle { + padding-top: 0; + margin-top: 0; + font-size: 0.7em; +} + +.masthead__logo--subtitle a { + text-decoration: none; +} + +.masthead__logo--title { + font-family: fantasy; +} + +.masthead__icons { + order: -1; + padding-bottom: 15px; +} + +.masthead__icons i:hover { + color: white; +} + +.content { + flex: 1; + text-align: center; + background: white; +} + +.content__body { + padding: 2%; + color: black; +} + + +.content__sidebar { + display: none; + background: white; + padding: 2%; +} + +.content__nav { + display: none; + background: white; + padding: 2%; +} + +.footer { + text-align: center; + background: mediumpurple; + padding: 0; + position: fixed; + height: auto; + bottom: 0; + left: 0; + right: 0; + overflow: hidden; +} + +.toggle-on { + display: none; +} + +@media (min-width: 768px){ + .content { + display: flex; + } + .content__nav { + flex: 1; + display: block; + } + .content__sidebar{ + flex: 1; + display: block; + } + .content__body { + flex: 4; + } + .footer { + display: flex; + flex-direction: row; + flex-wrap: nowrap; + justify-content: space-between; + padding-bottom: 15px; + padding-top: 15px + } + .masthead__logo { + justify-content: flex-start; + padding-top: 5px; + /* padding-bottom: 5px; */ + padding-left: 30px; + align-items: center; + } + .masthead__logo--subtitle { + padding-left: 30px; + } + .masthead__icons { + justify-content: flex-start; + flex-flow: row-reverse; + order: 0; + padding-top: 10px; + padding-right: 30px; + + } + .fas { + padding: 0 10px; + } + + .thumbs { + margin-bottom: 200px; + } +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..711159c --- /dev/null +++ b/index.html @@ -0,0 +1,42 @@ + + + + + + + Slacker News + + + + + +
+ +
+
+
+

Top Tech Stories

+
+
+ +
+
+ +
+ + +
+ + + + \ No newline at end of file