From d05e122a8ac640307aef900a9b23e21e1c81715d Mon Sep 17 00:00:00 2001 From: HTLuff Date: Sun, 17 Jun 2018 09:37:41 +0100 Subject: [PATCH 1/3] basic news app api calls working --- assets/index.js | 37 +++++++++++++++++++ assets/style.css | 96 ++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 54 +++++++++++++++++++++++++++ 3 files changed, 187 insertions(+) create mode 100644 assets/index.js create mode 100644 assets/style.css create mode 100644 index.html diff --git a/assets/index.js b/assets/index.js new file mode 100644 index 0000000..046a7ed --- /dev/null +++ b/assets/index.js @@ -0,0 +1,37 @@ +/* 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'); + +function createURL(indvCategory){ + const search = indvCategory.textContent; + return `https://newsapi.org/v2/top-headlines?category=${search}&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 newsSearch(e){ + e.preventDefault(); + fetch(createURL(e.target)) + .then(function(response){ + return response.json(); + }).then(function(newsData){ + return display(newsData); + }) +} + +categorySearch.addEventListener("click", newsSearch); \ No newline at end of file diff --git a/assets/style.css b/assets/style.css new file mode 100644 index 0000000..a44b549 --- /dev/null +++ b/assets/style.css @@ -0,0 +1,96 @@ +* { + 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; +} + +.masthead { + flex: 0; + padding: 10px; + text-align: center; + background: mediumpurple; +} + +.masthead__logo--title { + font-family: fantasy; +} + +.content { + flex: 1; + text-align: center; + background: white; +} + +.content__body { + padding: 2%; +} + +.content__sidebar { + display: none; + background: darkcyan; + padding: 2%; +} + +.content__nav { + background: mediumpurple; + padding: 2%; + list-style: none; +} + +.content__nav a { + color: inherit; + text-decoration: none; +} + +.content__nav a:hover { + color: white; +} + +.footer { + text-align: center; + background: mediumpurple; + padding: 1%; + position: fixed; + height: 60px; + bottom: 0; + left: 0; + right: 0; + overflow: hidden; +} + +@media (min-width: 768px){ + .content { + display: flex; + } + .content__nav { + flex: 2; + } + + .content__body { + flex: 4; + } +} + +@media (min-width: 993px) { + .content__nav { + flex: 1; + } + .content__body { + flex: 9; + } + .content__sidebar { + flex: 2; + display: block; + padding: 2%; + } +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..be76fd5 --- /dev/null +++ b/index.html @@ -0,0 +1,54 @@ + + + + + + + Ultimate News + + + + +
+ +
+

Ultimate News

+
+ +
+ + + +
+
+ +
+
+ +
+ +
+ +
+
+ + + + \ No newline at end of file From 4ec74d1dc2e7a7262c10a213a2de7d70974ce293 Mon Sep 17 00:00:00 2001 From: HTLuff Date: Mon, 18 Jun 2018 09:33:20 +0100 Subject: [PATCH 2/3] working app with two added features change colour and toggle desc --- assets/index.js | 39 ++++++++++++++--- assets/style.css | 110 ++++++++++++++++++++++++++++++++++------------- index.html | 48 ++++++++------------- 3 files changed, 132 insertions(+), 65 deletions(-) diff --git a/assets/index.js b/assets/index.js index 046a7ed..fe4595b 100644 --- a/assets/index.js +++ b/assets/index.js @@ -3,10 +3,12 @@ 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){ - const search = indvCategory.textContent; - return `https://newsapi.org/v2/top-headlines?category=${search}&country=gb&apiKey=${newAPIKey}&pagesize=5`; + return `https://newsapi.org/v2/top-headlines?category=technology&country=gb&apiKey=${newAPIKey}&pagesize=5`; } function display(newsData){ @@ -14,8 +16,8 @@ function display(newsData){ return ` @@ -24,6 +26,31 @@ function display(newsData){ 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)) @@ -34,4 +61,6 @@ function newsSearch(e){ }) } -categorySearch.addEventListener("click", newsSearch); \ No newline at end of file +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 index a44b549..46f80b0 100644 --- a/assets/style.css +++ b/assets/style.css @@ -14,17 +14,47 @@ body { height: 100vh; } +.clicked { + filter: invert(100%); +} + +.content__body--title { + font-size: 3em; +} + .masthead { - flex: 0; - padding: 10px; - text-align: center; + /* 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; @@ -33,64 +63,84 @@ body { .content__body { padding: 2%; + color: black; } + .content__sidebar { display: none; - background: darkcyan; + background: white; padding: 2%; } .content__nav { - background: mediumpurple; + display: none; + background: white; padding: 2%; - list-style: none; -} - -.content__nav a { - color: inherit; - text-decoration: none; -} - -.content__nav a:hover { - color: white; } .footer { text-align: center; background: mediumpurple; - padding: 1%; + padding: 0; position: fixed; - height: 60px; + height: auto; bottom: 0; left: 0; right: 0; overflow: hidden; } +.toggle-on { + display: none; +} + @media (min-width: 768px){ .content { display: flex; } .content__nav { - flex: 2; + flex: 1; + display: block; + } + .content__sidebar{ + flex: 1; + display: block; } - .content__body { flex: 4; } -} - -@media (min-width: 993px) { - .content__nav { - flex: 1; + .footer { + display: flex; + flex-direction: row; + flex-wrap: nowrap; + justify-content: space-between; + padding-bottom: 15px; + padding-top: 15px } - .content__body { - flex: 9; + .masthead__logo { + justify-content: flex-start; + padding-top: 5px; + /* padding-bottom: 5px; */ + padding-left: 30px; + align-items: center; } - .content__sidebar { - flex: 2; - display: block; - padding: 2%; + .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 index be76fd5..711159c 100644 --- a/index.html +++ b/index.html @@ -4,48 +4,36 @@ - Ultimate News + Slacker News + -
- -
-

Ultimate News

-
- +
+
- - - +
+

Top Tech Stories

+
- +
- +
From d18ab34ac3fe6744b14b284e5cd3ab427ec5014f Mon Sep 17 00:00:00 2001 From: HTLuff Date: Mon, 18 Jun 2018 09:38:11 +0100 Subject: [PATCH 3/3] new README added --- README.md | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) 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