-
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
Ruby- Samantha H #59
base: main
Are you sure you want to change the base?
Ruby- Samantha H #59
Changes from all commits
f57101a
47ef430
45b7e79
1e0f62e
3aedb58
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,16 +1,88 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<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 rel="preconnect" href="https://fonts.gstatic.com"> | ||
<link href="https://fonts.googleapis.com/css2?family=Rubik&display=swap" rel="stylesheet"> | ||
<link rel="stylesheet" href="styles/index.css" /> | ||
<link rel="stylesheet" href="styles/index.css"> | ||
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> | ||
</head> | ||
|
||
<body> | ||
<script src="./src/index.js"></script> | ||
|
||
<header> | ||
<h1 id="page-title">Your Weather ✨Fashion✨ Report</h1> | ||
</header> | ||
|
||
<main> | ||
<section id="grid_space_one" class="grid-item"> | ||
<section id="city-space"> | ||
<section id="city-name-section"> | ||
<h2 id="city_name">Seattle</h2> | ||
</section> | ||
|
||
<section class="search"> | ||
<input id="city_input" type="text" placeholder="enter city name" spellcheck="true"> | ||
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 usage of the placeholder and spellcheck attributes! |
||
</section> | ||
|
||
<section> | ||
<button id="reset-button"> Reset City</button> | ||
</section> | ||
|
||
</section> | ||
</section> | ||
|
||
<section id="grid_space_two" class="grid-item"> | ||
<section id="weather-and-buttons"> | ||
<button id="decrease_temp"><img id="arrow" src="assets/icons/arrow_point_left.png"></button> | ||
<h1 id="temp" class="temp_style"> | ||
<span id="temp_no">65</span> ° F | ||
</h1> | ||
<button id="increase_temp"><img id="arrow" src="assets/icons/arrow_point_right.png"></button> | ||
</section> | ||
|
||
<section> | ||
<button id="weather-button">Get Realtime Weather</button> | ||
</section> | ||
|
||
|
||
</section> | ||
|
||
|
||
<section id="grid_space_three" class="grid-item"> | ||
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. Make sure you're being consistent with your class and id naming conventions. Best practice is lowercase with hyphens (-) separating words when needed (unless you're using the BEM convention). |
||
<section id="landscape"> | ||
<h2>Fashion Landscape</h2> | ||
<h1> ✨Look Inspiration✨</h1> | ||
|
||
<section class="fashion-image-container"> | ||
<img id="fashion_landscape" src="assets/80_degree_outfit.jpeg"> | ||
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 this fashion landscape 🤩 💃🏾 |
||
</section> | ||
</section> | ||
</section> | ||
|
||
<section id="grid_space_four" class="grid-item"> | ||
<section> | ||
<h2> The Sky Today</h2> | ||
</section\> | ||
|
||
<select id="sky_selector"> | ||
<option selected disabled>Choose the Sky</option> | ||
<option value="skySunny">Sunny</option> | ||
<option value="skyCloudy">Cloudy</option> | ||
<option value="skyRainy">Rainy</option> | ||
<option value="skySnowy">Snowy</option> | ||
<option value="skyStarry">Starry</option> | ||
</select> | ||
<section class="sky"> | ||
<img id="pinterest-sky" src="assets/skies/sunny_sky.jpeg"> | ||
</section> | ||
</section> | ||
|
||
</main> | ||
|
||
<script src="./node_modules/axios/dist/axios.min.js"></script> | ||
<script src="./src/index.js"></script> | ||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,157 @@ | ||||||||||
const city = document.getElementById('city_name') | ||||||||||
let inputCity = document.getElementById('city_input') | ||||||||||
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.
Suggested change
Note these type of variables storing html elements can be declared as |
||||||||||
|
||||||||||
function changeCity(event) { | ||||||||||
if (event.key === 'Enter') { | ||||||||||
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 ✨ |
||||||||||
city.textContent = inputCity.value; | ||||||||||
} | ||||||||||
} | ||||||||||
inputCity.addEventListener('keydown', changeCity) | ||||||||||
inputCity.addEventListener('keydown', updateWeather) | ||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
const increaseTempButton = document.getElementById('increase_temp') | ||||||||||
const decreaseTempButton = document.getElementById('decrease_temp') | ||||||||||
|
||||||||||
|
||||||||||
function increaseTemp() { | ||||||||||
const temperature = document.getElementById('temp_no'); | ||||||||||
let current_temp = Number(temperature.textContent) | ||||||||||
|
||||||||||
temperature.textContent = current_temp + 1; | ||||||||||
tempColor(current_temp + 1); | ||||||||||
changeLandscape(current_temp + 1) | ||||||||||
} | ||||||||||
|
||||||||||
increaseTempButton.addEventListener('click', increaseTemp) | ||||||||||
|
||||||||||
function decreaseTemp() { | ||||||||||
const temperature = document.getElementById('temp_no'); | ||||||||||
let current_temp = Number(temperature.textContent) | ||||||||||
|
||||||||||
temperature.textContent = current_temp - 1; | ||||||||||
tempColor(current_temp - 1); | ||||||||||
changeLandscape(current_temp + 1) | ||||||||||
} | ||||||||||
decreaseTempButton.addEventListener('click', decreaseTemp) | ||||||||||
|
||||||||||
function changeLandscape(temp) { | ||||||||||
let landscape = document.getElementById('fashion_landscape'); | ||||||||||
if (temp < 60) { | ||||||||||
landscape.src = "assets/cold_outfit.jpeg" | ||||||||||
} else if (temp >= 60 && temp < 70) { | ||||||||||
landscape.src = "assets/60_degree_outfit.jpeg" | ||||||||||
} else if (temp >= 70 && temp < 80) { | ||||||||||
landscape.src = "assets/cardigan_and_jeans.jpeg" | ||||||||||
} else { | ||||||||||
landscape.src = "assets/80_degree_outfit.jpeg" | ||||||||||
} | ||||||||||
|
||||||||||
} | ||||||||||
|
||||||||||
function tempColor(temp) { | ||||||||||
let temperature = document.getElementById('temp'); | ||||||||||
if (temp <= 49) { | ||||||||||
temperature.className = 'freezing'; | ||||||||||
} else if (temp > 49 && temp < 60) { | ||||||||||
temperature.className = 'cold'; | ||||||||||
} else if (temp >= 60 && temp < 70) { | ||||||||||
temperature.className = 'chilly'; | ||||||||||
} else if (temp >= 70 && temp < 80) { | ||||||||||
temperature.className = 'hot'; | ||||||||||
} else { | ||||||||||
temperature.className = 'scorching'; | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
let skySelector = document.getElementById('sky_selector'); | ||||||||||
let skyImage = document.getElementById('pinterest-sky'); | ||||||||||
Comment on lines
+68
to
+69
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 are a lot of variable declarations scattered around this file so I'd recommend finding a way to organize these a little better:
I'd also recommend grouping the event handler functions in one section and then having the event listener registrations in another section. |
||||||||||
|
||||||||||
skySelector.addEventListener('change', changeSkyImage); | ||||||||||
|
||||||||||
function changeSkyImage() { | ||||||||||
let selectedSky = skySelector.value; | ||||||||||
switch(selectedSky) { | ||||||||||
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. Great usage of a switch statement here 👏🏾 |
||||||||||
case 'skySunny': | ||||||||||
skyImage.src = 'assets/skies/sunny_sky.jpeg'; | ||||||||||
break; | ||||||||||
|
||||||||||
case 'skyCloudy': | ||||||||||
skyImage.src = 'assets/skies/cloudy_sky.jpeg'; | ||||||||||
break; | ||||||||||
|
||||||||||
case 'skyRainy': | ||||||||||
skyImage.src = 'assets/skies/rainy_sky.jpeg'; | ||||||||||
break; | ||||||||||
|
||||||||||
case 'skySnowy': | ||||||||||
skyImage.src = 'assets/skies/snowy_sky.jpeg'; | ||||||||||
break; | ||||||||||
|
||||||||||
case 'skyStarry': | ||||||||||
skyImage.src = 'assets/skies/starry_sky_blue.jpeg'; | ||||||||||
break; | ||||||||||
Comment on lines
+88
to
+94
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. Note that there are some formatting issues for the For things like this, it's really good to restrict the maximum size of images, make all images the same size, and/or make the position of the header and dropdown menu fixed so they can't disappear. |
||||||||||
|
||||||||||
default: | ||||||||||
skyImage.src= 'assets/skies/starry_purple_sky.jpeg'; | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
async function getCoordinates(city) { | ||||||||||
try{ | ||||||||||
const response = await axios.get('http://127.0.0.1:5000/location', { | ||||||||||
params: {"q": city} | ||||||||||
}); | ||||||||||
|
||||||||||
latitude = response.data[0].lat; | ||||||||||
longitude = response.data[0].lon; | ||||||||||
Comment on lines
+107
to
+108
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.
Suggested change
|
||||||||||
return {latitude, longitude}; | ||||||||||
|
||||||||||
}catch (error){ | ||||||||||
Comment on lines
+102
to
+111
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. Great usage of async/await and try/catch statements here! ✨ Make sure you're paying attention to code style as some of your spacing/indentation is a bit off, making it look like lines 107-109 are outside of the try block |
||||||||||
console.error(error); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
async function getWeather(lat, lon) { | ||||||||||
try{ | ||||||||||
const response = await axios.get('http://127.0.0.1:5000/weather', { | ||||||||||
params: {"lat": lat, "lon": lon} | ||||||||||
}); | ||||||||||
|
||||||||||
const temp = Math.round(1.8 * (response.data.main.temp - 273) + 32) | ||||||||||
|
||||||||||
return temp; | ||||||||||
|
||||||||||
}catch (error){ | ||||||||||
console.error(error); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
async function updateWeather() { | ||||||||||
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. Similar to how you handled changing the city name, I'd recommend adding some logic to this function to have it only execute after the |
||||||||||
const city = inputCity.value; | ||||||||||
const { latitude, longitude } = await getCoordinates(city); | ||||||||||
const temperature = await getWeather(latitude, longitude); | ||||||||||
document.getElementById('temp_no').textContent = temperature; | ||||||||||
tempColor(temperature) | ||||||||||
changeLandscape(temperature) | ||||||||||
|
||||||||||
} | ||||||||||
|
||||||||||
function resetCity(){ | ||||||||||
const cityName = document.getElementById('city_name') | ||||||||||
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. Note that this |
||||||||||
cityName.textContent = 'Seattle'; | ||||||||||
inputCity.value = 'Seattle'; | ||||||||||
updateWeather() | ||||||||||
|
||||||||||
} | ||||||||||
|
||||||||||
const weather_button = document.getElementById('weather-button') | ||||||||||
weather_button.addEventListener('click', updateWeather); | ||||||||||
|
||||||||||
const reset_button = document.getElementById('reset-button') | ||||||||||
reset_button.addEventListener('click', resetCity) | ||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
|
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.
I'd recommend trying to consolidate some of these section tags so that you don't have as many tags to keep track of and maintain 😌 🧹