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

Gwen and Whitney - Zoisite #56

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Gwen and Whitney - Zoisite #56

wants to merge 7 commits into from

Conversation

WhitShake
Copy link

No description provided.

Copy link

@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 job on weather-report, Gwen and Whitney!

Let me know if you have questions about my review comments.

Comment on lines +151 to +157
const onLoaded = () => {
loadControls();
setDefaultValues();
registerEventHandlers();
};

onLoaded();

Choose a reason for hiding this comment

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

We had to use the onLoaded approach when we were using codesandbox because by the time the UI had rendered and shown us the code editor for to write code the event called DOMContentLoaded had already fired. The act of rendering the web page makes DOMContentLoaded happen so we couldn't use it as an event to register loadControls().

When you're writing vanilla JS for event handling like, we should call register the function called registerEventHandlers on the event DOMContentLoaded, like this:

window.addEventListener("DOMContentLoaded", registerEventHandlers)

Then when your page loads registerEventHandlers will execute.

You could add loadControls() and setDefaultValues() inside registerEventHandlers()` so alll your 'start up' logic happens on page load.

sky : null,
};

const setDefaultValues = () => {

Choose a reason for hiding this comment

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

👍

sky.textContent = "";
};

const registerEventHandlers = () => {

Choose a reason for hiding this comment

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

👍

state.skySelect.addEventListener("change", changeSky);
};

const loadControls = () => {

Choose a reason for hiding this comment

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

👍

Comment on lines +53 to +65
const increaseTemp = () => {
state.tempDeg += 1;
tempValue.textContent = `${state.tempDeg}`
changeColor();
changeLandscape();
};

const decreaseTemp = () => {
state.tempDeg -= 1;
tempValue.textContent = `${state.tempDeg}`;
changeColor();
changeLandscape();
};

Choose a reason for hiding this comment

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

Notice that these two methods do essentially the same thing 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.tempDeg++;
    } else {
        state.tempDeg--;
    }
    tempValue.textContent = `${state.tempDeg}`;
    changeColor();
    changeLandscape();
};

}

const findLatAndLon= (query) => {
let latitude, longitude;

Choose a reason for hiding this comment

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

What if you initialized these variables in your state object? Then on lines 118 and 119, you could do:

state.latitude = response.data[0].lat;
state.longitude = response.data[0].lon;


const findLatAndLon= (query) => {
let latitude, longitude;
axios.get('http://localhost:5000/location',

Choose a reason for hiding this comment

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

Prefer to reference string literals like this url with a descriptively named variable

axios.get('http://localhost:5000/location',
{
params: {
q: `${state.cityNameOutput.textContent}`,

Choose a reason for hiding this comment

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

no need for string templating

Comment on lines +131 to +137
{
params: {
format: 'json',
lat: latitude,
lon: longitude
}
})

Choose a reason for hiding this comment

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

Prefer the object being sent along in the get request to be referenced with a variable to make this line of code more readable.

WEATHER_URL = "http://localhost:5000/weather";
request_data = {
            format: 'json',
            lat: latitude,
            lon: longitude
}
axios.get(WEATHER_URL, request_data)

Comment on lines +140 to +148
console.log('success in findWeather!', response.data.main.temp);
state.tempDeg = Math.round((response.data.main.temp - 273.15) * 9/5 + 32);
tempValue.textContent = `${state.tempDeg}`
changeColor();
changeLandscape();
})
.catch( (error) => {
console.log('error in findWeather!');
});

Choose a reason for hiding this comment

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

Nitpick - indentation needs to be fixed up.

While the JS still executes correctly since the language is not dependent on indentation, we should strive for correct indentation for sake of consistency and readability. When you open a PR for review when you're at work be sure to fix up your indentation/spacing and remove debugging print statements.

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.

3 participants