-
Notifications
You must be signed in to change notification settings - Fork 34
responsive news website, fully functional with drop down options - Hamzah Kurdi #12
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
hamzah-kurdi
wants to merge
1
commit into
constructorlabs:master
Choose a base branch
from
hamzah-kurdi: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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| <!DOCTYPE html> | ||
|
|
||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewpoint" content="width=device-width, initial-scale=1.0"> | ||
| <title>News App</title> | ||
| <link rel="stylesheet" href="./stylesheet.css"> | ||
| <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Karla"> | ||
| </head> | ||
|
|
||
| <body> | ||
| <div class="wrapper"> | ||
| <header class="mainhead"> | ||
| <h1 class="mainhead__logo">📰 Good or Bad News First? 📰</h1> | ||
| <form class="form" id="newsform" action=""> | ||
| <input id="input" class="search__input" placeholder="Enter your search query here"> | ||
| <button id="news__submit" class="submit__button">Search</button> | ||
| </form> | ||
| </header> | ||
| <div id="results__holder" class="maincontent"> | ||
| <nav class="maincontent__nav"> | ||
| <h4 class="popularsearch" id="popular__links">Narrow Your Search</h4> | ||
| <div id="nav__links"> | ||
| <div class="li__nav" id=" nav__links "> | ||
| <li id="li__goodBad" class="li__goodBad"> | ||
| <select name="good__bad" id="good__bad"> | ||
| <option value="good">Good News</option> | ||
| <option value="bad">Bad News</option> | ||
| </select> | ||
| </li> | ||
| <li id="li__category" class="li__category"> | ||
| <select name="category " id="categories"> | ||
| <option value="business">Business</option> | ||
| <option value="entertainment">Entertainment</option> | ||
| <option value="spprts">Sports</option> | ||
| <option value="health">Health and Fitness</option> | ||
| <option value="technology">Technology</option> | ||
| <option value="science">Science</option> | ||
| </select> | ||
| </li> | ||
| <li id="li__country" class="li__country"> | ||
| <select name="country " id="countries"> | ||
| <option value="UK">UK</option> | ||
| <option value="america">USA</option> | ||
| <option value="australia">Australia</option> | ||
| <option value="canada">Canada</option> | ||
| <option value="russia">Russia</option> | ||
| <option value="middle east">Middle East</option> | ||
| <option value="china">China</option> | ||
| </select> | ||
| </li> | ||
| </div> | ||
| <div class="stored__search"> | ||
| <h4 class="storednav" id="stored__header">Your Recent Searches</h4> | ||
| <select name="stored__search" id="stored__search"> | ||
|
|
||
| </select> | ||
| </div> | ||
| </div> | ||
| </nav> | ||
| <main id="news__results__container" class="maincontent__body"> | ||
| </main> | ||
| </div> | ||
| <footer class="mainfooter"> | ||
| <div class="mainfooter__item mainfooter__item--link"> | ||
| <a href="https://newsapi.org"> Powered by News API</a> | ||
| </div> | ||
| </footer> | ||
| </div> | ||
|
|
||
| <script src="./index.js"></script> | ||
| </body> |
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,84 @@ | ||
| const form = document.querySelector("#newsform"); | ||
| const input = document.querySelector("#input"); | ||
| const results = document.querySelector("#news__results__container"); | ||
| const country = document.querySelector("#countries"); | ||
| const category = document.querySelector("#categories"); | ||
| const goodBad = document.querySelector("#good__bad"); | ||
| const storedSearch = document.querySelector("#stored__search"); | ||
|
|
||
| function fetchNews(search) { | ||
| fetch( | ||
| `https://newsapi.org/v2/everything?q=${search}&from=2018-06-15&sortBy=popularity&apiKey=4150b2f03a834ff68cffe0f3a011f41e` | ||
| ) | ||
| .then(function(response) { | ||
| return response.json(); | ||
| }) | ||
| .then(function(json) { | ||
| display(json); | ||
| console.log(json); | ||
| }) | ||
| .catch(function(error) { | ||
| console.log(error); | ||
| }); | ||
| } | ||
| function fetchNation(nation) { | ||
| fetch( | ||
| `https://newsapi.org/v2/sources?country=${nation}&apiKey=4150b2f03a834ff68cffe0f3a011f41e` | ||
| ) | ||
| .then(function(response) { | ||
| return response.json(); | ||
| }) | ||
| .then(function(nationJson) { | ||
| console.log(nationJson); | ||
| display(nationJson); | ||
| }) | ||
| .catch(function(error) { | ||
| console.log("No news is good news!"); | ||
| }); | ||
| } | ||
| function display(myJson) { | ||
| let newsResults = myJson.articles | ||
| .map(function(news) { | ||
| return ` | ||
| <div class="results__body"> | ||
|
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. indentation here would make HTML code easier to read |
||
| <ui> | ||
| <div class="results__body__block"> | ||
| <a href=${ | ||
| news.url | ||
| }><h3 class="news__title"><strong>${news.title}</strong></h3></a> | ||
| <p class="news__publication">Date Published: ${news.publishedAt}</p> | ||
| <p class="news__author"><i>${news.author}</i></p> | ||
| <p class="news__source">${news.source.name}</p> | ||
| <p class="news__description">${news.description}</p> | ||
| <div class="imageparent"> | ||
| <img class="news__image" src=${news.urlToImage}> | ||
| </div> | ||
| </div> | ||
| </ui> | ||
| </div> | ||
| `; | ||
| }) | ||
| .join(""); | ||
|
|
||
| results.innerHTML = newsResults; | ||
| } | ||
|
|
||
| form.addEventListener("submit", function(event) { | ||
| event.preventDefault(); | ||
| fetchNews(input.value); | ||
| }); | ||
|
|
||
| goodBad.addEventListener("change", function(event) { | ||
| event.preventDefault(); | ||
| fetchNews(goodBad.value); | ||
| }); | ||
|
|
||
| category.addEventListener("change", function(event) { | ||
| event.preventDefault(); | ||
| fetchNews(category.value); | ||
| }); | ||
|
|
||
| country.addEventListener("change", function(event) { | ||
| event.preventDefault(); | ||
| fetchNews(country.value); | ||
| }); | ||
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,145 @@ | ||
| * { | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| body { | ||
| margin: 0; | ||
| padding: 0; | ||
| font-family: Karla; | ||
| min-height: 100vh; | ||
| } | ||
|
|
||
| .wrapper { | ||
| display: flex; | ||
| flex-direction: column; | ||
|
|
||
| height: 100vh; | ||
| background: hotpink; | ||
| } | ||
|
|
||
| .mainhead { | ||
| display: flex; | ||
| flex-direction: row; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
|
|
||
| background: lightgreen; | ||
| } | ||
|
|
||
| .mainhead__links li { | ||
| float: left; | ||
| list-style: none; | ||
| margin-right: 10px; | ||
| } | ||
|
|
||
| .maincontent { | ||
| flex: 1; | ||
|
|
||
| display: flex; | ||
| flex-direction: column; | ||
|
|
||
| text-align: center; | ||
| background: lemonchiffon; | ||
| } | ||
|
|
||
| .maincontent__body { | ||
| background: whitesmoke; | ||
| overflow: auto; | ||
| } | ||
|
|
||
| .results__body { | ||
| flex: 1; | ||
|
|
||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .maincontent__nav { | ||
| list-style: none; | ||
| justify-content: space-between; | ||
| } | ||
|
|
||
| .li__nav { | ||
| margin: 10px 0; | ||
| } | ||
|
|
||
| .mainfooter { | ||
| display: flex; | ||
| justify-content: space-around; | ||
| } | ||
|
|
||
| .mainfooter__item { | ||
| flex: 1; | ||
|
|
||
| padding: 10px; | ||
| text-align: center; | ||
| } | ||
|
|
||
| .mainfooter__item--link { | ||
| background: yellow; | ||
| } | ||
|
|
||
| .news__image { | ||
| max-width: auto; | ||
| display: none; | ||
| } | ||
|
|
||
| @media (min-width: 768px) { | ||
| .maincontent { | ||
| flex-direction: row; | ||
| } | ||
| .maincontent__nav { | ||
| flex: 2; | ||
| } | ||
| .maincontent__body { | ||
| flex: 4; | ||
| } | ||
|
|
||
| .mainfooter__item { | ||
| padding: 20px; | ||
| } | ||
|
|
||
| .results__body { | ||
| flex: 2; | ||
|
|
||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: space-between; | ||
| text-align: center; | ||
| } | ||
|
|
||
| .news__image { | ||
| max-width: 400px; | ||
| display: block; | ||
| text-align: center; | ||
| } | ||
| } | ||
|
|
||
| @media (min-width: 960px) { | ||
| .maincontent { | ||
| flex-direction: row; | ||
| } | ||
| .maincontent__nav { | ||
| flex: 2; | ||
| } | ||
| .maincontent__body { | ||
| flex: 4; | ||
| } | ||
|
|
||
| .mainfooter__item { | ||
| padding: 30px; | ||
| } | ||
|
|
||
| .imageparent { | ||
| display: block; | ||
| align-content: center; | ||
| text-align: center; | ||
| } | ||
|
|
||
| .news__image { | ||
| max-width: 500px; | ||
| display: block; | ||
| } | ||
| } |
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.
Good re-use of display function