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

PR to review Jackie's weather-report submission #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yangashley
Copy link
Contributor

No description provided.

Copy link
Contributor Author

@yangashley yangashley left a comment

Choose a reason for hiding this comment

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

Nice work on weather-report! Let me know if you have questions about my review comments

Comment on lines +1 to +2
import 'regenerator-runtime/runtime';
import axios from 'axios';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were necessary for deployment, but when these imports run locally it breaks the site. When you have conditional code needed for one environment, but not another, you can create a separate branch for deployment that has these specific values and deploy the separate branch. That way you have a main branch that works locally and a deployment branch that has everything it needs to get deployed

Comment on lines +14 to +22
if (sky === "sunny") {
skyText.innerHTML = "☁️ ☁️ ☁️ ☀️ ☁️ ☁️"
} else if (sky === "cloudy") {
skyText.innerHTML = "☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️"
} else if (sky === "rainy") {
skyText.innerHTML = "🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧"
} else if (sky === "snowy") {
skyText.innerHTML = "🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨"
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another way to format this method would be to have an object that has sky options as keys and and emojis as values, like:

const skyObject = {"sunny": "☁️ ☁️ ☁️ ☀️ ☁️ ☁️", "cloudy": "☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️"} // etc

When you have an object, you don't need to do if/else if/else if/ else which can introduce bugs and also adds complexity to the method. If you have an object, than you can iterate over the object and check the keys with sky and then get the correct values to set the sky

Comment on lines +30 to +33
const increaseTemp = () => {
state.temperature += 1;
updateTempUi();
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Notice that this method does essentially the same thing as decreaseTemp but the difference is -= 1 or += 1 (also in JS you can use ++ or -- which is short hand for doing the same thing).

How could you combine the logic of these two methods into one event handler called handleTempChange()?

What if you pass in the event object as an argument and you check if the event's target has an id increaseTempControl or decreaseTempControl and depending on the id then you could ++ or --

const handleTempChange = (event) => {
    if (event.target.id === 'increaseTempControl') {
        state.temperature++;
    } else {
        state.temperature--;
    }
    updateTempUi();
};

};

const updateTempUi = () => {
tempText.innerHTML = `${state.temperature}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

You don't need to use string templating here. You'd use string templating for concatenating strings, like:

const baseUrl = "localhost:500";
axios.get(`${baseUrl}/cats`)

Comment on lines +37 to +54
if (state.temperature >= 80) {
landscapeText.innerHTML = "🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂";
tempText.style.color = "red";
} else if (state.temperature <= 79 && state.temperature > 69) {
landscapeText.innerHTML = "🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷";
tempText.style.color = "orange";
} else if (state.temperature <=69 && state.temperature > 59) {
landscapeText.innerHTML = "🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃";
tempText.style.color = "yellow";
} else if (state.temperature <=59 && state.temperature > 49) {
landscapeText.innerHTML = "🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲";
tempText.style.color = "green";
} else if (state.temperature <=49) {
landscapeText.innerHTML = "🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲";
tempText.style.color = "teal";
}
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same comment here about using an object to store these values (see above inchangeSky()).

You could have an object like:
const tempAndLandscapeObject = {
80: ["🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂", "red"],
70: ["🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷", "orange"],
}

Then you could iterate over the object and check the keys with `state.temperature` and get the array that has the two values you need to set a new landscape and temperature color

Comment on lines +82 to +84
const latitude = response.data[0].lat;
const longitude = response.data[0].lon;
findLocationTemp(latitude, longitude)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

};

const findLocationTemp = (latitude, longitude) => {
axios.get('https://weather-proxy-s44a.onrender.com/weather', {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use a constant variable to reference the URL instead of a string literal

Comment on lines +100 to +104
const tempInKelvin = response.data.main.temp;
let tempInFahrenheit = (tempInKelvin - 273) * 9/5 + 32;
tempInFahrenheit = Math.floor(tempInFahrenheit);
state.temperature = tempInFahrenheit;
updateTempUi();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Comment on lines +110 to +130
const registerEventHandlers = () => {
const increaseTempButton = document.querySelector("#increaseTempControl");
increaseTempButton.addEventListener("click", increaseTemp);

const decreaseTempButton = document.querySelector("#decreaseTempControl");
decreaseTempButton.addEventListener("click", decreaseTemp);

const updateCity = document.querySelector("#cityNameInput");
updateCity.addEventListener("input", updateCityHeader);

const cityReset = document.querySelector("#cityNameReset");
cityReset.addEventListener("click", resetCityName);

const updateTemp = document.querySelector("#currentTempButton");
updateTemp.addEventListener("click", updateCurrentTemp);

const updateSky = document.querySelector("#skySelect");
updateSky.addEventListener("change", changeSkyValue);
};

document.addEventListener("DOMContentLoaded", registerEventHandlers);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

};

const updateCityHeader = () => {
let currentCityInput = cityText.value;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this variable isn't reassigned we should use const instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant