-
Notifications
You must be signed in to change notification settings - Fork 88
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
base: main
Are you sure you want to change the base?
Poppy-shark #64
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} |
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); | ||||||||||
// }); | ||||||||||
const state = { | ||||||||||
degree:60, | ||||||||||
isF: true, | ||||||||||
cityName: 'Poppy City, USA', | ||||||||||
|
||||||||||
}; | ||||||||||
Comment on lines
+37
to
+42
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. 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
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. 👍 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
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. Always good practice to add spaces around operators.
Suggested change
|
||||||||||
} | ||||||||||
// 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
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. 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
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. 👍 |
||||||||||
|
||||||||||
// 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
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. 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
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'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;
} 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. 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); | ||||||||||
|
||||||||||
|
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 { | ||
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. 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; | ||
} | ||
|
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.
Commented out code should be removed from PRs.