-
Notifications
You must be signed in to change notification settings - Fork 34
Kate news reader #16
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
KateMhq
wants to merge
9
commits into
constructorlabs:master
Choose a base branch
from
KateMhq: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
Kate news reader #16
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a0c94de
basic exercise
KateMhq 4494669
styling
KateMhq 5468952
strech exercise
KateMhq 8486950
scroll to top
KateMhq 32ba4e1
heroku setup
KateMhq fd7b381
bug fix
KateMhq be3b4e6
update link
KateMhq 190865d
search function
KateMhq fd38c9d
fetch fixed; code tidied up
KateMhq 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
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
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 @@ | ||
| {} |
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,35 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <link rel="stylesheet" href="newsReader.css"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
| <title>News Reader</title> | ||
| </head> | ||
| <body> | ||
| <div class="header"> | ||
| <h1>News Reader</h1> | ||
| <p>Here is your daily news feed</p> | ||
| </div> | ||
| <div class="topHeadlines"> | ||
| <form class="searchForm"> | ||
| <input type="text" class="keyword" placeholder="Search a keyword"> | ||
| <input type="submit" value="Go"> | ||
| </form> | ||
| <h2>Top headlines</h2> | ||
|
|
||
| <div class="articleList"> | ||
| </div> | ||
| </div> | ||
| <button type="button" class="nextPage">Next page</button> | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| <script src="newsReader.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 @@ | ||
| <?php include_once("index.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,89 @@ | ||
| * { | ||
| box-sizing: inherit; | ||
| } | ||
|
|
||
| body { | ||
| display: flex; | ||
| box-sizing: border-box; | ||
| margin: 20px; | ||
| font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif; | ||
| flex-direction: column; | ||
| justify-content: space-around; | ||
| padding: 10%; | ||
| padding-top: 5%; | ||
| } | ||
|
|
||
|
|
||
| .header{ | ||
| font-size: 2.5vh; | ||
| } | ||
|
|
||
|
|
||
| input[type=text]{ | ||
| font-size: 16px; | ||
| border-color: #e7e7e7; | ||
| border-radius: 22px; | ||
| border-style: solid; | ||
| padding: 12px; | ||
| width: 70%; | ||
| } | ||
|
|
||
| input[type=submit]{ | ||
| font-size: 16px; | ||
| background-color: #e7e7e7; | ||
| color: black; | ||
| border-radius: 20px; | ||
| padding: 12px; | ||
| border-color: #e7e7e7; | ||
| width: 25%; | ||
| } | ||
|
|
||
| h2{ | ||
| font-size: 2.5vh; | ||
| } | ||
| .articleList{ | ||
| flex-direction: column; | ||
| justify-content: center; | ||
| height: 100vh; | ||
| display: flex; | ||
| flex-flow: row wrap; | ||
| } | ||
|
|
||
| ul{ | ||
| list-style-type: none; | ||
| margin: 0; | ||
| padding: 0; | ||
| padding-bottom:40px; | ||
|
|
||
| } | ||
|
|
||
| li{ | ||
| padding: 0; | ||
| padding-bottom: 8px; | ||
| } | ||
| .title{ | ||
| font-size: 2.5vh; | ||
| } | ||
| .description{ | ||
| font-size: 2.3vh; | ||
| } | ||
|
|
||
| button{ | ||
| background-color: #4CAF50; | ||
| border: none; | ||
| color: white; | ||
| padding: 15px 32px; | ||
| text-align: center; | ||
| text-decoration: none; | ||
| display: inline-block; | ||
| font-size: 25px; | ||
| position: fixed; | ||
| bottom: 0px; | ||
| right: 0px; | ||
| } | ||
|
|
||
| @media(max-width:768px){ | ||
| img{ | ||
| display: none; | ||
| } | ||
| } |
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,152 @@ | ||
| // const news=document.createElement("p"); | ||
| const topHeadlines=document.querySelector(".topHeadlines"); | ||
| const articleList=document.querySelector(".articleList"); | ||
| const nextPageButton=document.querySelector(".nextPage"); | ||
| const searchForm=document.querySelector(".searchForm"); | ||
| const keyword=document.querySelector(".keyword"); | ||
| const body=document.querySelector("body"); | ||
| let p=1; | ||
|
|
||
| const urlBase = 'https://newsapi.org/v2/' | ||
| let queries = 'top-headlines?' + | ||
| 'country=gb&' | ||
| let page = `page=${p}&`; | ||
| const pageSize = 'pageSize=5&'; | ||
| const apiKey = 'apiKey=84e1f3efc2a148dca439f1b5ad3cd201'; | ||
| let url = urlBase + queries + pageSize + page + apiKey; | ||
| const newsDetail=document.createElement("ul"); | ||
| newsDetail.classList.add("onePieceofNews"); | ||
| articleList.appendChild(newsDetail); | ||
|
|
||
|
|
||
| function getNews(piece){ | ||
| const newsContent=document.createElement("li") | ||
| if(piece.description!==null){ | ||
| newsContent.innerHTML=` | ||
| <h3 class="title">${piece.title}</h3> | ||
| <img src=${piece.urlToImage} width=100% alt="image"> | ||
| <p class="description">${piece.description}</p> | ||
| <p class="source">${piece.source.name}</p> | ||
| <p class="date">${piece.publishedAt}</p> | ||
| <a href=${piece.url}>Read more</a> | ||
| `; | ||
| newsDetail.appendChild(newsContent); | ||
|
|
||
|
|
||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| function fetchNews(){ | ||
|
|
||
| return fetch(url) | ||
| .then(response => response.json()) | ||
| .then(response => { | ||
| newsDetail.innerHTML=""; | ||
| response.articles.forEach(piece => getNews(piece)) | ||
| }) | ||
| .catch(error => console.log(error)); | ||
|
|
||
| } | ||
|
|
||
| fetchNews(); | ||
|
|
||
| function fetchNewsNextPage(pageNumber){ | ||
| page = `page=${pageNumber}&` | ||
| url = urlBase + queries + pageSize + page + apiKey; | ||
| return fetch(url) | ||
| .then(response => response.json()) | ||
| .then(response => { | ||
| newsDetail.innerHTML=""; | ||
| return response.articles.forEach(piece => getNews(piece)) | ||
| }) | ||
| .catch(error => console.log(error)); | ||
| } | ||
|
|
||
| body.addEventListener("click", event => { | ||
|
|
||
| if(event.target.matches(".nextPage")){ | ||
| p++; | ||
| fetchNewsNextPage(p) | ||
| } | ||
| }) | ||
| // nextPageButton.onclick=function(event) { | ||
| // p++; | ||
| // page = `page=${p}&` | ||
| // url = urlBase + queries + pageSize + page + apiKey; | ||
| // console.log("url: ", url); | ||
| // | ||
| // req = new Request(url); | ||
| // fetch(req) | ||
| // .then(response => { | ||
| // return response.json() | ||
| // }) | ||
| // .then(response => { | ||
| // console.log(response); | ||
| // | ||
| // i=1; | ||
| // response.articles.forEach(function(item){ | ||
| // | ||
| // if(item.description!==null){ | ||
| // newsDetail=document.getElementById(`${i}`) | ||
| // newsDetail.innerHTML=`<li class=title >${item.title}</li> | ||
| // <img src=${item.urlToImage} width=100% alt="image"> | ||
| // <li class=description>${item.description}</li> | ||
| // <li class=source>${item.source.name}</li> | ||
| // <li class=date>${item.publishedAt}</li> | ||
| // <a href=${item.url}>Read more</a> | ||
| // `; | ||
| // | ||
| // | ||
| // | ||
| // i++; | ||
| // document.documentElement.scrollTop = 0; | ||
| // } | ||
| // return; | ||
| // }) | ||
| // | ||
| // }) | ||
| // .catch(error => console.log(error)); | ||
| // } | ||
|
|
||
| searchForm.addEventListener('submit', function(event){ | ||
| event.preventDefault(); | ||
| p=1; | ||
| page = `page=${p}&` | ||
| queries = `everything?q=${keyword.value}&from=2018-09-16&to=2018-09-16&sortBy=popularity&`; | ||
| url = urlBase + queries + pageSize + page + apiKey; | ||
| console.log("url: ", url); | ||
|
|
||
| req = new Request(url); | ||
| fetch(req) | ||
| .then(response => { | ||
| // console.log(response.json()); | ||
| return response.json() | ||
| }) | ||
| .then(response => { | ||
| console.log(response); | ||
|
|
||
| i=1; | ||
| response.articles.forEach(function(item){ | ||
|
|
||
| if(item.description!==null){ | ||
| newsDetail=document.getElementById(`${i}`) | ||
| newsDetail.innerHTML=`<li class=title >${item.title}</li> | ||
| <img src=${item.urlToImage} width=100% alt="image"> | ||
| <li class=description>${item.description}</li> | ||
| <li class=source>${item.source.name}</li> | ||
| <li class=date>${item.publishedAt}</li> | ||
| <a href=${item.url}>Read more</a> | ||
| `; | ||
|
|
||
| i++; | ||
| document.documentElement.scrollTop = 0; | ||
| } | ||
| return; | ||
|
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. return is not needed |
||
| }) | ||
|
|
||
| }) | ||
| .catch(error => console.log(error)); | ||
|
|
||
| }) | ||
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.
Same comments as before regarding use of
iand wrapping display logic in function