-
Notifications
You must be signed in to change notification settings - Fork 85
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
Wilson-Munson-Amethyst-Weather-Report-C19 #60
base: main
Are you sure you want to change the base?
Changes from all commits
bf8c75f
60f7987
7d7b05c
2019e37
e496407
6d94ab4
7af4365
a6f66f9
a83ac8c
d42d748
9e47cd9
79219c0
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,5 @@ | ||
{ | ||
"dependencies": { | ||
"axios": "^1.2.1" | ||
"axios": "^1.4.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
"use strict"; | ||
const state = { | ||
tempEl: document.getElementById("temp"), | ||
tempConEl: document.getElementById("temp-container"), | ||
tempIncrease: document.getElementById("temp-increase"), | ||
tempDecrease: document.getElementById("temp-decrease"), | ||
tempVal: parseInt(document.getElementById("temp").textContent), | ||
landscapeEl: document.getElementById("landscape"), | ||
mainTitle: document.getElementById("city"), | ||
inputField: document.getElementById("city-choice"), | ||
getTempButton: document.getElementById("get-current-temp"), | ||
skyDropdown: document.getElementById("sky-dropdown"), | ||
skyEl: document.getElementById("sky"), | ||
resetCityButton: document.getElementById("reset-city"), | ||
} | ||
Comment on lines
+3
to
+15
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. Pieces of code like this are usually found in an event handler that runs on the event DOMContentLoaded, basically once the page is html is loaded on the webpage you will run a bunch of initial logic such as grabbing elements and adding event handlers to them. It will look something like this: document.addEventListener("DOMContentLoaded", function () {
state.increaseTemp = document.querySelector("#increase-temp");
state.decreaseTemp = document.querySelector("#decrease-temp");
state.displayTemp = document.querySelector("#display-temp");
state.resetButton = document.querySelector("#reset-button");
state.searchButton = document.querySelector("#search-button");
state.increaseTemp.addEventListener("click", increaseTemperature);
state.decreaseTemp.addEventListener("click", decreaseTemperature);
...
} This is also usually found at the bottom of the file too, that way you can put all your function definitions for event handlers above it! This also just adds an extra layer of protection when it comes to things loading in order. |
||
|
||
// Wave2 | ||
const changeTempColor = () => { | ||
if (state.tempVal > 80) { | ||
state.tempEl.className = 'above80Temp'; | ||
state.tempConEl.className = 'above80Bk'; | ||
} else if (state.tempVal < 80 && state.tempVal > 69) { | ||
state.tempEl.className = 'temp69To80'; | ||
state.tempConEl.className = 'temp69To80Bk'; | ||
} else if (state.tempVal < 70 && state.tempVal > 59) { | ||
state.tempEl.className = 'temp59To70'; | ||
state.tempConEl.className = 'temp59To70Bk'; | ||
} else if (state.tempVal < 60 && state.tempVal > 49) { | ||
state.tempEl.className = 'temp49To60'; | ||
state.tempConEl.className = 'temp49To60Bk'; | ||
} else if (state.tempVal < 50) { | ||
state.tempEl.className = 'blow50'; | ||
state.tempConEl.className = 'blow50Bk'; | ||
}; | ||
} | ||
|
||
const changeLandscape = () => { | ||
const landscapeImage = document.getElementById("landscape-img"); | ||
if (state.tempVal >= 80) { | ||
landscapeImage.src = 'assets/landscapes/dunes.jpg'; | ||
landscapeImage.alt = 'Desert dunes landscape'; | ||
} else if (state.tempVal < 80 && state.tempVal >= 70) { | ||
landscapeImage.src = 'assets/landscapes/grass.jpg'; | ||
landscapeImage.alt = 'Happy cow in lush grassy green hills landscape'; | ||
} else if (state.tempVal < 70 && state.tempVal >= 33) { | ||
landscapeImage.src = 'assets/landscapes/forest.jpg'; | ||
landscapeImage.alt = 'Foggy dense forest landscape'; | ||
} else { | ||
landscapeImage.src = 'assets/landscapes/tundra.jpg'; | ||
landscapeImage.alt = 'Icy expansive landscape'; | ||
} | ||
} | ||
|
||
state.tempIncrease.addEventListener('click', (event) => { | ||
event.preventDefault() | ||
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. Usually you want to use the |
||
state.tempVal += 1; | ||
state.tempEl.textContent = state.tempVal; | ||
changeTempColor(); | ||
changeLandscape(); | ||
}) | ||
|
||
state.tempDecrease.addEventListener('click', (event) => { | ||
event.preventDefault() | ||
state.tempVal -= 1; | ||
state.tempEl.textContent = state.tempVal; | ||
changeTempColor(); | ||
changeLandscape(); | ||
}) | ||
|
||
//Wave 3 | ||
state.inputField.addEventListener('keyup', (event) => { | ||
state.mainTitle.textContent = state.inputField.value | ||
}) | ||
|
||
//Wave 4 | ||
let lat; | ||
let lon; | ||
const getLocation = () => { | ||
// console.log(state.mainTitle); | ||
const url = `http://127.0.0.1:5000/location`; | ||
axios.get(url, { | ||
params: { | ||
q: state.mainTitle.textContent, | ||
}}) | ||
.then((response) => { | ||
console.log(response.data[0].lat, response.data[0].lon) | ||
getWeather(response.data[0].lat, response.data[0].lon); | ||
} | ||
) | ||
.catch((error) => { | ||
console.log(error); | ||
}) | ||
}; | ||
Comment on lines
+76
to
+93
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. Here's an alternative to promise chaining! You can use the const findCityLocation = async () => {
let lat;
let lon;
const resp = await axios.get('http://127.0.0.1:5000/location', {
params: {
q: document.getElementById("city").value
}
})
try {
[lat, lon] = resp.data[0]
getWeather({ lat: lat, lon: lon});
} catch (error) {
console.log(error)
}
}; |
||
|
||
const getWeather = (lat, lon) => { | ||
return (axios.get('http://127.0.0.1:5000/weather', { | ||
params: { | ||
lat: lat, | ||
lon: lon, | ||
}}) | ||
.then((response) => { | ||
|
||
console.log(response.data.main.temp) | ||
const tempInF = (response.data.main.temp - 273.15) * (9/5) + 32; | ||
state.tempVal = parseInt(tempInF); | ||
// console.log(state.tempVal) | ||
state.tempEl.textContent = state.tempVal; | ||
changeTempColor(); | ||
changeLandscape(); | ||
}) | ||
.catch((error)=> { | ||
console.log(error); | ||
}) | ||
) | ||
} | ||
state.getTempButton.addEventListener('click', getLocation); | ||
|
||
// WAVE 55555 | ||
const changeSky = () => { | ||
const skyValue = state.skyDropdown.value; | ||
console.log(skyValue); | ||
if (skyValue === 'puffy-cloud') { | ||
state.skyEl.className = 'puffy-clouds'; | ||
} else if (skyValue === 'cloudy') { | ||
state.skyEl.className = 'cloudy'; | ||
} else if (skyValue === 'storm-cloud') { | ||
state.skyEl.className = 'storm-cloud'; | ||
} else if (skyValue === 'sunny') { | ||
state.skyEl.className = 'sunny'; | ||
} | ||
}; | ||
|
||
state.skyDropdown.addEventListener('change', changeSky) | ||
|
||
// WAVE 6 | ||
state.resetCityButton.addEventListener('click', () => { | ||
state.mainTitle.textContent = 'Anamosa'; | ||
state.inputField.value = 'Anamosa'; | ||
}) | ||
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. Awesome job everyone! You really ate this one up! Please feel free to reach out to me if you have any questions about the comments I left or if you want to discuss anything in greater detail! ⭐️ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
* { | ||
font-family:'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif | ||
} | ||
#city { | ||
color:black | ||
} | ||
|
||
.above80Temp { | ||
color: red; | ||
} | ||
|
||
.above80Bk { | ||
background-color: salmon; | ||
/* opacity: 50%; */ | ||
} | ||
|
||
.temp69To80 { | ||
color: teal; | ||
} | ||
|
||
.temp69To80Bk { | ||
background-color: lightblue; | ||
} | ||
|
||
.temp59To70 { | ||
color: chocolate; | ||
} | ||
|
||
.temp59To70Bk { | ||
background-color: bisque; | ||
} | ||
|
||
.temp49To60 { | ||
color: green; | ||
} | ||
|
||
.temp49To60Bk { | ||
background-color: yellowgreen; | ||
} | ||
|
||
.blow50 { | ||
color:teal; | ||
} | ||
|
||
.blow50Bk { | ||
background-color: lightcyan; | ||
} | ||
|
||
#city-container { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
} | ||
|
||
main { | ||
height: 100vh; | ||
flex:auto; | ||
/* width: 50%; */ | ||
} | ||
|
||
#sky-dropdown { | ||
height: 1.5rem; | ||
} | ||
|
||
#city-container { | ||
align-items: center; | ||
padding:1rem; | ||
} | ||
#content-container { | ||
display: flex; | ||
/* flex-direction: row; */ | ||
justify-content: space-between; | ||
padding: 1rem; | ||
} | ||
|
||
#temp-container { | ||
display: flex; | ||
} | ||
|
||
#temp { | ||
padding: .25rem; | ||
} | ||
#temp-buttons { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
gap: 25%; | ||
padding: .5rem; | ||
} | ||
|
||
#change-content-container { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
img { | ||
max-width: 100%; | ||
} | ||
|
||
.puffy-clouds { | ||
background-image: url("../assets/clouds/puffyclouds.jpg"); | ||
} | ||
.storm-cloud { | ||
background-image: url("../assets/clouds/rainclouds.jpg"); | ||
} | ||
.sunny { | ||
background-image: url("../assets/clouds/sunny.jpg"); | ||
} | ||
.cloudy { | ||
background-image: url("../assets/clouds/clouds.jpg"); | ||
} |
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.
Love how you all chose to use this psuedostate! I think that it is great practice for what you will see in React though it will be utilized differently!