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

Ruby- Samantha H #59

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/60_degree_outfit.jpeg
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/80_degree_outfit.jpeg
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/cardigan_and_jeans.jpeg
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/cold_outfit.jpeg
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/icons/arrow_point_left.png
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/icons/arrow_point_right.png
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/icons/moon_icon_two.png
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/icons/search_icon.png
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/icons/spring_outfit.jpeg
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/icons/weather_icon.jpeg
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/icons/winter_outfit.jpeg
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/skies/cloudy_sky.jpeg
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/skies/rainy_sky.jpeg
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/skies/snowy_sky.jpeg
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/skies/starry_purple_sky.jpeg
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/skies/starry_sky_blue.jpeg
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/skies/sunny_sky.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 76 additions & 4 deletions index.html
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">
Comment on lines +20 to +22

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 😌 🧹

<h2 id="city_name">Seattle</h2>
</section>

<section class="search">
<input id="city_input" type="text" placeholder="enter city name" spellcheck="true">

Choose a reason for hiding this comment

The 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">

Choose a reason for hiding this comment

The 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">

Choose a reason for hiding this comment

The 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>
110 changes: 110 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"dependencies": {
"axios": "^1.2.1"
"axios": "^1.4.0"
}
}
157 changes: 157 additions & 0 deletions src/index.js
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')

Choose a reason for hiding this comment

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

Suggested change
let inputCity = document.getElementById('city_input')
const inputCity = document.getElementById('city_input')

Note these type of variables storing html elements can be declared as const variables since under the hood they're just objects, so you'll still be able to modify the data inside the object. This just ensures the variable itself can't be reassigned.


function changeCity(event) {
if (event.key === 'Enter') {

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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:

  • Declaring variables at the smallest scope necessary, so initializing variables like skyImage inside of the function they're used in instead of at the global scope
  • Declaring variables that are globally scoped because they're used in more than one place at the top of the file
  • Declaring variables that are globally scoped but only used once directly above the line of code that uses the variable

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) {

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

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

Note that there are some formatting issues for the Starry and Snowy options where the section header The Sky Today and the dropdown menu for sky selection get pushed out of the visible area of the box due to the images being too large. This makes a page refresh required to get the selection box back.

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

Choose a reason for hiding this comment

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

Suggested change
latitude = response.data[0].lat;
longitude = response.data[0].lon;
const latitude = response.data[0].lat;
const longitude = response.data[0].lon;

return {latitude, longitude};

}catch (error){
Comment on lines +102 to +111

Choose a reason for hiding this comment

The 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() {

Choose a reason for hiding this comment

The 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 Enter key is pressed. At the moment, it executes after every single character that's entered into the input box which is causing a lot of unnecessary API calls and errors.

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')

Choose a reason for hiding this comment

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

Note that this city_name element is already available for use in the global variable city. I think I prefer this locally scoped variable better though so I'd probably recommend moving the global variable inside the changeCity function too.

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)




Loading