Skip to content

Weather report -Sika#73

Open
sikasarpong wants to merge 11 commits intoAda-C18:mainfrom
sikasarpong:main
Open

Weather report -Sika#73
sikasarpong wants to merge 11 commits intoAda-C18:mainfrom
sikasarpong:main

Conversation

@sikasarpong
Copy link
Copy Markdown

No description provided.

Comment thread src/index.js
city: 'Seattle',
lat: '47.6038321',
long: '-122.330062',
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I love this! Building your own version of state will allow for you to better understand the inner workings of state in React!

Comment thread src/index.js
.catch((error) => {
console.log('Error in find the latitude and longitude!', error.response);
});
};
Copy link
Copy Markdown

@mikellewade mikellewade Jan 10, 2023

Choose a reason for hiding this comment

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

Very nice chain promising! A refactor that you could have made is something like this

const getLatAndLong = async () => {
try {
   const response = await axios.get('http://127.0.0.1:5000/location', {
      params: {
        q: state.city,
        format: 'json',
      }})
 
    state.lat = response.data[0].lat;
    state.long = response.data[0].lon;
    getWeather();
} catch (err) {
    console.log(err)
}
    
};

Making use of the async & await functionality in Javascript allows us to stop at the axios call and wait for it to finish that logic until the promise is fulfilled then continue! It is really nice for making out code concise! Then we can put this in a try catch block in order to do some error handling.

Comment thread src/index.js
// const cityForm = document.querySelector('form');
// const landscape = document.querySelector('.card');
// const card = document.querySelector('.details')

Copy link
Copy Markdown

@mikellewade mikellewade Jan 10, 2023

Choose a reason for hiding this comment

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

I don't think you needed to pass in the key param for the call to the backend. That should have been on server side. In general, you never want to store valuable information like API keys in your frontend.

Comment thread src/index.js
} else {
color = 'teal';
landscape = '🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲';
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I love this! This is exactly how it was solved in the solution!

Comment thread src/index.js

document.addEventListener('DOMContentLoaded', registerEventHandlers);


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Very very good code, Sika! There were not many things to correct or refactor in your code! A textbook example of weather report! Just keep in mind the async & await refractor that I commented earlier in the PR. Awesome work! ✨

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.

2 participants