-
Notifications
You must be signed in to change notification settings - Fork 34
Mel: Responsive News Reader #22
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
Open
LemonyDesign
wants to merge
16
commits into
constructorlabs:master
Choose a base branch
from
LemonyDesign:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
250b518
Publication object created
LemonyDesign 0fa549a
Filter publication array for fetched url
LemonyDesign d62014d
Working on fetch url
LemonyDesign 630a5d1
Function call confusion
LemonyDesign f627077
Function generateFetchUrl debug
LemonyDesign ed31de8
Adding stylesheet
LemonyDesign 86d7c06
Functions wrangling
LemonyDesign 8d60ec0
URL returned but filter not working
LemonyDesign d1506a5
Returning default URL, filter broken
LemonyDesign f4e6ff5
Filter working
LemonyDesign c1c31e6
Filter working - but need to reset content
LemonyDesign 5fdb5eb
Filter, Styles, Fallbacks
LemonyDesign 14395db
Update styles
LemonyDesign 728bab6
Red Card - in progress
LemonyDesign b45873c
Red card functionality added
LemonyDesign b9ddfaf
Red Card Functionality added
LemonyDesign File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
| <title>News Sorter</title> | ||
| <link rel="stylesheet" href="styles/normalize.css"> | ||
| <link rel="stylesheet" href="styles/styles.css"> | ||
|
|
||
| </head> | ||
| <body> | ||
| <h1 class="main-title">Eye on the Tabloids</h1> | ||
|
|
||
| <div class="container"> | ||
| <main> | ||
| <nav class="news--filter"> | ||
| <label><input type="checkbox" name="mail" value="daily-mail"> Daily Mail</label> | ||
| <label><input type="checkbox" name="mirror" value="mirror"> Mirror</label> | ||
| <label><input type="checkbox" name="metro" value="metro"> Metro</label> | ||
| </nav> | ||
| <section class="news--area"> | ||
| <div class="news--area--feed"></div> | ||
| </section> | ||
| </main> | ||
| </div> | ||
| <footer class="site--footer"><p>News Feed from <a href="https://newsapi.org/">newsapi.org</a></p></footer> | ||
| <script src="scripts/javascript.js"></script> | ||
| </body> | ||
| </html> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| const parentNode = document.querySelector(".news--area--feed"); | ||
|
|
||
| // compile this Url = "https://newsapi.org/v2/top-headlines?sources=bbc-news,daily-mail,mirror,&apiKey=93238bcda39e4404852697d364b77971"; | ||
| const baseUrl = "https://newsapi.org/v2/top-headlines?apiKey=93238bcda39e4404852697d364b77971"; | ||
|
|
||
|
|
||
| const publicationList = { | ||
| "bbc-news": true, | ||
| "daily-mail": true, | ||
| "mirror": true | ||
| } | ||
|
|
||
| // create an array from object using key values | ||
| let publicationArray = Object.keys(publicationList); | ||
|
|
||
|
|
||
| //console.log(defaultArray); | ||
| const sourceList = `&sources=${defaultArray}`; | ||
| const fullURL = `${baseUrl}${sourceList}`; | ||
|
|
||
| function displayDataOnPage(newsStories) { | ||
| const newsArray = newsStories.articles; | ||
| console.log(newsStories.articles); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are quite a few consol.logs left in. Once you are happy with the functionality, it's best to remove them to keep console output clean |
||
|
|
||
| // add news blocks (as articles) | ||
| newsArray.forEach(function(newsitem) { | ||
|
|
||
| const node = document.createElement("article"); | ||
| node.innerHTML = `${newsitem.source.name} (source logo) | ||
| <b>${newsitem.title}:</b> ${newsitem.description}`; | ||
| parentNode.appendChild(node); | ||
|
|
||
| }) | ||
|
|
||
|
|
||
|
|
||
| // filter | ||
| let checkboxArray = document.querySelectorAll(".news--filter input"); | ||
| console.log(checkboxArray) | ||
|
|
||
| checkboxArray.forEach(function(input) { | ||
| input.addEventListener("change", event => { | ||
| console.log(event.target.value); | ||
|
|
||
| if (publicationList[event.target.value]) { | ||
| publicationList[event.target.value] = false | ||
| filteredArray.push(event.target.value); | ||
| } | ||
|
|
||
| console.log(filteredArray) | ||
|
|
||
| }) | ||
| }) | ||
|
|
||
|
|
||
| } | ||
|
|
||
| function displayErrorToUser() {} | ||
|
|
||
| fetch(fullURL) // by default fetch makes a GET request | ||
| .then(function(response) { | ||
| return response.json(); | ||
| }) | ||
| .then(function(body) { | ||
| //console.log(body); | ||
| displayDataOnPage(body); | ||
| }) | ||
| .catch(function(error) { | ||
| displayErrorToUser("Server failed to return data"); | ||
|
|
||
| // need filter to NOT SHOW any news story with empty values | ||
| // if any value is empty do no show | ||
| }); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| const baseUrl = "https://newsapi.org/v2/top-headlines?apiKey=93238bcda39e4404852697d364b77971"; | ||
| const parentNode = document.querySelector(".news--area--feed"); | ||
|
|
||
| let checkboxArray = document.querySelectorAll(".news--filter input"); | ||
| let userOpted = false; | ||
| /* | ||
| -------------- | ||
| FETCH FUNCTION | ||
| -------------- | ||
| */ | ||
| const goFetch = function(fullURL) { | ||
|
|
||
| fetch(fullURL) // by default fetch makes a GET request | ||
| .then(function(response) { | ||
| return response.json(); | ||
| }) | ||
| .then(function(body) { | ||
| displayDataOnPage(body); | ||
| }) | ||
| .catch(function(error) { | ||
| displayErrorToUser("Server failed to return data"); | ||
| // need filter to NOT SHOW any news story with empty values. if any value is empty do no show | ||
| }); | ||
| } | ||
|
|
||
| /* | ||
| -------------------- | ||
| DISPLAY DATA ON PAGE | ||
| -------------------- | ||
| */ | ||
|
|
||
| function displayDataOnPage(newsStories) { | ||
|
|
||
| const newsArray = newsStories.articles; | ||
| // console.log(newsStories.articles); | ||
| // add news blocks (as articles) | ||
| newsArray.forEach(function(newsitem) { | ||
|
|
||
| const node = document.createElement("article"); | ||
| node.innerHTML = `<figure class="news--article-image"><img src="${newsitem.urlToImage}"></figure> | ||
| <section class="news--article-content"> | ||
| <header class="${newsitem.source.name}"><h2>${newsitem.title}</h2></header> | ||
| <h3>${newsitem.description}</h3> | ||
| <p>${newsitem.content}</p> | ||
| <p><a href="${newsitem.url}" title="Visit news article: ${newsitem.title}">Read full article</a> | ||
| </section>`; | ||
| parentNode.appendChild(node); | ||
|
|
||
| }) | ||
| } | ||
|
|
||
| /* | ||
| ------------------ | ||
| GENERATE FETCH URL | ||
| ------------------ | ||
| */ | ||
|
|
||
| // news sources object | ||
| let publicationList = { | ||
| "daily-mail": false, | ||
| "mirror": false, | ||
| "metro": false, | ||
| "the-telegraph": false, | ||
| "financial-times": false, | ||
| "bbc-news": false, | ||
| } | ||
|
|
||
| const generateFetchURL = function (publicationList) { | ||
| // baseUrl and default | ||
| const defaultArray = ["bbc-news","daily-mail","mirror"]; | ||
|
|
||
| // create an array from object using key values | ||
| let publicationArray = Object.keys(publicationList); | ||
| let filteredArray = publicationArray.filter(function(pub) { | ||
| return publicationList[pub] === true; | ||
| }); | ||
|
|
||
| // compile fetch url | ||
| let defaultArrayUrl = `&sources=${defaultArray}`; | ||
| let filteredPublicationUrl = `&sources=${filteredArray}`; | ||
| let fullURL = ""; | ||
|
|
||
| if (userOpted === true) { | ||
| // RETURN VALUES - fullURL | ||
| fullURL = `${baseUrl}${filteredPublicationUrl}`; | ||
| } else { | ||
| fullURL = `${baseUrl}${defaultArrayUrl}`; | ||
| } | ||
| goFetch(fullURL) | ||
| } | ||
|
|
||
| /* | ||
| ---------------------- | ||
| CREATE CHECKBOX FILTER | ||
| ---------------------- | ||
| */ | ||
| const createCheckboxFilter = function() { | ||
| // Reset UserOpted to false | ||
| userOpted = false; | ||
| checkboxArray.forEach(function(input) { | ||
| input.addEventListener("change", function(event) { | ||
| // new assigned value to match object key | ||
| // assign object value if checked is true | ||
| if (event.target.checked === true) { | ||
| publicationList[event.target.value] = true; | ||
| userOpted = true; | ||
| } | ||
| else { | ||
| publicationList[event.target.value] = false; | ||
| } | ||
| console.log(publicationList) | ||
| generateFetchURL(publicationList); | ||
| }) | ||
| }) | ||
| } | ||
| /* this function to run generateFetchURL() */ | ||
| createCheckboxFilter(); | ||
|
|
||
| /* | ||
| --------------------- | ||
| ERROR HANDLER - TO DO | ||
| --------------------- | ||
| */ | ||
| function displayErrorToUser() {} | ||
|
|
||
|
|
||
| // Initial call to fetch data | ||
| generateFetchURL(baseUrl); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| const baseUrl = "https://newsapi.org/v2/top-headlines?apiKey=93238bcda39e4404852697d364b77971"; | ||
| const parentNode = document.querySelector(".news--area--feed"); | ||
|
|
||
| let checkboxArray = document.querySelector(".news--filter"); | ||
| let userOpted = false; | ||
| /* | ||
| -------------- | ||
| FETCH FUNCTION | ||
| -------------- | ||
| */ | ||
| const goFetch = function(fullURL) { | ||
|
|
||
| fetch(fullURL) // by default fetch makes a GET request | ||
| .then(function(response) { | ||
| return response.json(); | ||
| }) | ||
| .then(function(body) { | ||
| displayDataOnPage(body); | ||
| }) | ||
| .catch(function(error) { | ||
| displayErrorToUser("Server failed to return data"); | ||
| // need filter to NOT SHOW any news story with empty values. if any value is empty do no show | ||
| }); | ||
| } | ||
|
|
||
| /* | ||
| -------------------- | ||
| DISPLAY DATA ON PAGE | ||
| -------------------- | ||
| */ | ||
|
|
||
| function displayDataOnPage(newsStories) { | ||
|
|
||
| const newsArray = newsStories.articles; | ||
| // console.log(newsStories.articles); | ||
| // add news blocks (as articles) | ||
| newsArray.forEach(function(newsitem) { | ||
|
|
||
| const node = document.createElement("article"); | ||
| node.innerHTML = `<figure class="news--article-image"><img src="${newsitem.urlToImage}"></figure> | ||
| <section class="news--article-content"> | ||
| <header class="${newsitem.source.name}"><h2>${newsitem.title}</h2></header> | ||
| <h3>${newsitem.description}</h3> | ||
| <p>${newsitem.content}</p> | ||
| <p><a href="${newsitem.url}" title="Visit news article: ${newsitem.title}">Read full article</a> | ||
| </section>`; | ||
| parentNode.appendChild(node); | ||
|
|
||
| }) | ||
| } | ||
|
|
||
| /* | ||
| ------------------ | ||
| GENERATE FETCH URL | ||
| ------------------ | ||
| */ | ||
|
|
||
| // news sources object | ||
| let publicationList = { | ||
| "daily-mail": false, | ||
| "mirror": false, | ||
| "metro": false, | ||
| "the-telegraph": false, | ||
| "financial-times": false, | ||
| "bbc-news": false, | ||
| } | ||
|
|
||
| const generateFetchURL = function (publicationList) { | ||
| // baseUrl and default | ||
| const defaultArray = ["bbc-news","daily-mail","mirror"]; | ||
|
|
||
| // create an array from object using key values | ||
| let publicationArray = Object.keys(publicationList); | ||
| let filteredArray = publicationArray.filter(function(pub) { | ||
| return publicationList[pub] === true; | ||
| }); | ||
|
|
||
| // compile fetch url | ||
| let defaultArrayUrl = `&sources=${defaultArray}`; | ||
| let filteredPublicationUrl = `&sources=${filteredArray}`; | ||
| let fullURL = ""; | ||
|
|
||
| if (userOpted === true) { | ||
| // RETURN VALUES - fullURL | ||
| fullURL = `${baseUrl}${filteredPublicationUrl}`; | ||
| } else { | ||
| fullURL = `${baseUrl}${defaultArrayUrl}`; | ||
| } | ||
| goFetch(fullURL) | ||
| } | ||
|
|
||
| /* | ||
| ---------------------- | ||
| CREATE CHECKBOX FILTER | ||
| ---------------------- | ||
| */ | ||
|
|
||
| // Attach change event on checkboxes. | ||
| checkboxArray.addEventListener("change", function(event) { | ||
|
|
||
| // new assigned value to match object key | ||
| // assign object value if checked is true | ||
| if (event.target.checked === true) { | ||
| publicationList[event.target.value] = true; | ||
| } else { | ||
| publicationList[event.target.value] = false; | ||
| } | ||
|
|
||
| // Verify if any of the options are being selected. | ||
| userOpted = Object.values(publicationList).reduce(function (val1, val2) { return val1 || val2 }) | ||
| generateFetchURL(publicationList) | ||
| }) | ||
|
|
||
| /* | ||
| --------------------- | ||
| ERROR HANDLER - TO DO | ||
| --------------------- | ||
| */ | ||
| function displayErrorToUser() {} | ||
|
|
||
|
|
||
| // Initial call to fetch data | ||
| generateFetchURL(baseUrl); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class name should be written using
__since it indicates an element rather than modifier