Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 3 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
66 changes: 66 additions & 0 deletions assets/index.js
Original file line number Diff line number Diff line change
@@ -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){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like the helper function use

return `https://newsapi.org/v2/top-headlines?category=technology&country=gb&apiKey=${newAPIKey}&pagesize=5`;
}

function display(newsData){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

display logic nicely broken out into own function

let newsArticles = newsData.articles.map(function(article){
return `
<div class="news-articles">
<a href='${article.url}' target='_blank'>
<h3>${article.title}</h3>
<p id="news-desc" class="news-desc">${article.description}</p>
<p>${article.publishedAt}</p>
</a>
</div>
`
}).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', '');
Copy link
Contributor

@dmitrigrabov dmitrigrabov Jul 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

})
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);
146 changes: 146 additions & 0 deletions assets/style.css
Original file line number Diff line number Diff line change
@@ -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%);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

}

.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;
}
}
42 changes: 42 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!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>Slacker News</title>
<link rel="stylesheet" href="./assets/style.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
</head>

<body>
<div class="app" id="app">

<div class="content">
<div class="content__nav"></div>
<main class="content__body">
<h2 class="content__body--title">Top Tech Stories</h2>
<hr>
<div class="thumbs" id="thumbs">
<!-- <p id="news-desc">Hello</p> -->
</div>
</main>
<div class="content__sidebar"></div>
</div>

<footer class="footer">
<header class="masthead">
<h1 class="masthead__logo"><i class="masthead__logo--title">Slacker</i> <i>News</i></h1>
<p class="masthead__logo--subtitle"><a href="newsapi.org">powered by newsapi.org</a></p>
</header>
<div class="masthead__icons">
<i class="fas fa-sync-alt fa-3x" id="content__nav--links" tooltiptext="Refresh" alt="refresh-button"></i>
<i class="fas fa-window-restore fa-3x" id="descrption-toggle" tooltiptext="Toggle Description" alt="toggle-description-button"></i>
<i class="fas fa-adjust fa-3x" id="invert-btn" tooltiptext="Invert Colours" alt="invert-colour-button"></i>
</div>
</footer>
</div>
<script src="./assets/index.js"></script>
</body>

</html>