Skip to content

Wilson-Munson-Amethyst-Weather-Report-C19#60

Open
lindsaybolz wants to merge 12 commits intoAda-C19:mainfrom
lindsaybolz:main
Open

Wilson-Munson-Amethyst-Weather-Report-C19#60
lindsaybolz wants to merge 12 commits intoAda-C19:mainfrom
lindsaybolz:main

Conversation

@lindsaybolz
Copy link
Copy Markdown

No description provided.

Comment thread src/index.js
@@ -0,0 +1,139 @@
"use strict";
const state = {
Copy link
Copy Markdown

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!

Comment thread src/index.js
Comment on lines +3 to +15
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"),
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread src/index.js
}

state.tempIncrease.addEventListener('click', (event) => {
event.preventDefault()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Usually you want to use the preventDefault method to prevent the default behavior of an event, however I don't see the reasoning for doing it here. Is there a reason as to why you want to prevent it from happening?

Comment thread src/index.js
Comment on lines +76 to +93
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);
})
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here's an alternative to promise chaining! You can use the async/await keywords to have your function wait until a promise is fulfilled and then you pass the results of that promise to other pieces of your function like assigning your return values as variables or other things like that. It looks something like this:

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)
    }
};

Comment thread src/index.js
state.resetCityButton.addEventListener('click', () => {
state.mainTitle.textContent = 'Anamosa';
state.inputField.value = 'Anamosa';
}) No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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! ⭐️

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