Skip to content
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

Poppy-shark #64

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
Binary file added assets/cloudy.webp
Binary file not shown.
Binary file added assets/rainy.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/snow.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sunny.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 41 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,48 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weather Report</title>
<link href="styles/index.css" rel="stylesheet" type="text/css" />
</head>
<body>
<body id="body">
<h1><span >Poppy's Weather App</span> </h1>
<h2><span id='cityDisplay'>Showing weather for: Poppy City, USA</span> </h2>
<section>
<div id="temperature" class="box">
<div class="flex3">
<button class='button' id="plus">+</button>
<p> <span id="degree">60</span></p>

<button class='button'id="minus">-</button>
</div>

<div >
<button class='button1' id="c-button">C</button>
<button class='button1' id="f-button">F</button>
</div>

</div>

<div class="box1">
<label class="cityName">Choose a sky:
<select class='select-sky' id='select-sky'>
<option value= "sunny" id="sunny">sunny</option>;
<option value= "rainy" id="'rainy">rainy</option>
<option value= "cloudy" id="'cloudy">cloudy</option>
<option value= "snowy" id="snowy">snowy</option>
</select>
</label>
<div class="skyResult"></div>

<label class='cityName' for="name">Get a city's real weather:</label>
<input class ='cityName' type="text" id="name" name="name" required/>
<button id="s">Search</button>
<button id="resetbutton">Reset</button>
</div>

</section>

<script src="./node_modules/axios/dist/axios.min.js"></script>
<script src="/src/index.js"></script>
</body>

</html>
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"dependencies": {
"axios": "^0.27.2"
}
"-": "^0.0.1",
"axios": "^0.27.2",
"global": "^4.4.0",
"react-scripts": "^5.0.1",
"surge": "^0.23.1"
},
"private": true
}
197 changes: 197 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
"use strict";


// let map;
// let service;
// function callback(place, status) {
// if (status == google.maps.places.PlacesServiceStatus.OK) {
// createMarker(place);
// }
// }
// let place= //input city
// let config = {
// method: 'get',
// url: 'https://maps.googleapis.com/maps/api/place/textsearch/json?query=place&key=YOUR_API_KEY'

// };

// axios(config)

// .then((response)=>{
// const place = response.data[results][0];
// request={
// placeId: place.place_id
// }
// service = new google.maps.places.PlacesService(map);
// service.getDetails(request, callback);
// });
// .then((response)=>{
// PlacePhoto=response.photos[0];
// URL=PlacePhoto.getUrl();
// parameters={
// maxwidth=400,
// key=YOUR_API_KEY
// }
// return axios.get(URL, parameters);
// });
Comment on lines +4 to +36

Choose a reason for hiding this comment

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

Commented out code should be removed from PRs.

const state = {
degree:60,
isF: true,
cityName: 'Poppy City, USA',

};
Comment on lines +37 to +42

Choose a reason for hiding this comment

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

Nice working setting up state as an object. Many frontend frameworks store 'global' data like this in an object as well.

//let theText = myTextInput.value;
const showCityName=()=>{
const cityContainer = document.getElementById("cityDisplay");
const city= document.getElementById('name')
const cityName= city.value;
cityContainer.textContent = `Showing weather for: ${cityName}`;
}
const changeToC=()=>{
const degreeCountContainer = document.getElementById("degree");
if (state.isF){
state.isF=false;
degreeCountContainer.textContent = Math.floor((state.degree -32)/1.8);
}

}
const changeToF=()=>{
const degreeCountContainer = document.getElementById("degree");
if (! state.isF){
state.isF=true;
}
degreeCountContainer.textContent=state.degree;
Comment on lines +50 to +63

Choose a reason for hiding this comment

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

👍 Nice work doing the temperature conversion.

}
const changeTemp=(e)=> { //refactor 2 functions together to change temp
const degreeCountContainer = document.getElementById("degree");
e.target.id ==='plus'? state.degree++: state.degree--;
degreeCountContainer.textContent=state.degree;
Comment on lines +67 to +68

Choose a reason for hiding this comment

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

Always good practice to add spaces around operators.

Suggested change
e.target.id ==='plus'? state.degree++: state.degree--;
degreeCountContainer.textContent=state.degree;
e.target.id === 'plus'? state.degree++ : state.degree--;
degreeCountContainer.textContent = state.degree;

}
// const plusTemp = (e) => {
// const degreeCountContainer = document.getElementById("degree");
// state.degree += 1;
// degreeCountContainer.textContent=state.degree;

// const temperature = document.querySelector("#degree");
// if (temperature > 80) {
// temperature.style.color = 'red';

// }
// state.clickCount=0;
// };
// const minusTemp = () => {
// const degreeCountContainer = document.getElementById("degree");
// state.degree -= 1;
// degreeCountContainer.textContent = state.degree;

// const temperature = document.querySelector("#degree");
// if (temperature < 40) {
// temperature.style.color = 'blue';
// }
// state.clickCount=0;
// };
Comment on lines +70 to +92

Choose a reason for hiding this comment

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

Remove commented out code.

const resetTemp = () => {
const degreeCountContainer = document.getElementById("degree");
state.degree = 60;
state.isF=true;

degreeCountContainer.textContent=state.degree;

}

const getTemp=() => {
//console.log(loc)
const loc= document.getElementById('name');

return axios
.get('http://127.0.0.1:5000/location', {
params:{
q: loc.value,
},
})
.then((response) => {
console.log(response);
const lat=response.data[0].lat;
const lon=response.data[0].lon;
return axios.get('http://127.0.0.1:5000/weather', {
params:{
lat: lat,
lon: lon,
},
})
})

.then((response) => {

const temp=response.data.current.temp;
state.degree=Math.floor((temp-273.15)*1.8+32)
document.getElementById("degree").textContent=state.degree;
return state.degree;
})
.catch((response)=>{
console.log(response);
console.log('ERROR');
})
}
Comment on lines +102 to +135

Choose a reason for hiding this comment

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

👍


// const showRealWeather = ()=> {
// const degreeCountContainer = document.getElementById("degree");
// let theText = document.getElementById("name").value;

// // let temp=getTemp(theText);
// // state.isF=true;
// // degreeCountContainer.textContent=temp;
// }
Comment on lines +137 to +144

Choose a reason for hiding this comment

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

Remove commented-out code.

const selectSky= (event)=>{
const result = document.querySelector('.result');
result.textContent = event.target.value;

}

const changeBackground=() =>{
const sky = document.getElementById('select-sky');
if (sky.value == 'sunny'){
document.getElementById("body").style.backgroundImage= "url('/assets/sunny.gif')";
}else if (sky.value == 'rainy'){

document.getElementById("body").style.backgroundImage ="url('/assets/rainy.gif')";
}else if (sky.value == 'snowy'){
document.getElementById("body").style.backgroundImage='url("/assets/snow.gif")';
}else if (sky.value == 'cloudy'){
document.getElementById("body").style.backgroundImage="url('/assets/cloudy.webp')";
}
console.log('changeBackgroundCalled')

}
Comment on lines +151 to +165

Choose a reason for hiding this comment

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

There's a lot of repetitive syntax in the conditionals. We can dry up our code by changing the value of a variable in the conditionals and THEN setting that variable to the body's background image.

const changeBackground = () => { 
    const sky = document.getElementById('select-sky');
    let image = '';
    if (sky.value == 'sunny'){
        image = "url('./assets/sunny.gif')";
    } else if (sky.value == 'rainy'){
        image = "url('./assets/rainy.gif')";
    } else if (sky.value == 'snowy'){
        image = "url('./assets/snow.gif')";
    } else if (sky.value == 'cloudy'){
        image = "url('./assets/cloudy.webp')";
    }
    document.getElementById("body").style.backgroundImage = image;    
}

Choose a reason for hiding this comment

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

Love the gifs as a background!

const registerEventHandlers = () => {

const realWeather=document.getElementById("s");
realWeather.addEventListener("click", getTemp);
realWeather.addEventListener('click', showCityName);


const plusDegree = document.getElementById("plus");
plusDegree.addEventListener("click", changeTemp);

const minusDegree = document.getElementById("minus");
minusDegree.addEventListener("click", changeTemp);

const cButton = document.getElementById("c-button");
cButton.addEventListener("click", changeToC);
const fButton = document.getElementById("f-button");
fButton.addEventListener("click", changeToF);

const resetDegree = document.getElementById("resetbutton");
resetDegree.addEventListener("click", resetTemp);

const sky= document.getElementById("select-sky");
//sky.addEventListener('change', selectSky);
sky.addEventListener('change', changeBackground);

}


// DOM listener
document.addEventListener("DOMContentLoaded", registerEventHandlers);


125 changes: 125 additions & 0 deletions styles/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@

#body{
/* background-image: url(src/index.js/state.image); */
background-image: url('/assets/sunny.gif');
background-repeat: no-repeat;
background-size: 100%;
background-position: center; /* Center the image */
font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

}
h1{
font-size: 3em;

}
h2{
font-size: 2em;

}
section{
width: 35em;
height: 55em;
border: 2px;
border-radius: 15%;
position: center;
margin-left: auto;
margin-right: auto;
background: white;
padding: 5em;
opacity: .6;
}
.box {
width: 30em;
height: 25em;
display: grid;
justify-content: center;
flex-wrap: wrap;
border: 2px solid black;
border-radius: 20%;
position: center;
margin-left: auto;
margin-right: auto;


}
.box1{
width: 25em;
height: 10em;
font-size: 1em;
display: grid;
justify-content: center;

margin-top: 2em;
margin: auto;
}

.sky{
font-size: 1.5em;
}
#div1 {

Choose a reason for hiding this comment

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

Use more descriptive names for ids.

width:100px;
height:30px;
background-image:url(images/blue.gif);
}

.button{
height: 2em;
width: 2em;
font-size: 1.5em;
border-radius: 15%;
}
#resetbutton {
height: 2em;
width: 4em;
border-radius: 15%;
justify-content: center;
font-size: 1em;
margin: auto;
margin-top: 2em;
}
#s {
height: 2em;
width: 4em;
border-radius: 15%;
justify-content: center;
font-size: 1em;
margin: auto;
margin-top: 2em;
}

.select-sky{
font-size: 1em;
}
#degree{
font-size: 10em;
align-items: top;
margin: 0;
}
.flex3{
display: flex;
align-items: top;
margin-top: 3em;
}
#plus {
margin-top: 3.5em;
margin-right: 30px;
border-radius: 15%;
}
#minus{
margin-top: 3.5em;
margin-left: 30px;
border-radius: 15%;
}
.button1{
height: 2em;
width: 2em;
font-size: 1.5em;
margin-left: 3em;
margin-right: 2em;
border-radius: 15%;
}
.cityName{
margin-top: 1em;
font-size: 1.5em;
}

Loading