Connect to Weather API#28
Conversation
| {/* <div> | ||
| <img | ||
| className="weather-img" | ||
| src="https://cdn2.iconfinder.com/data/icons/weather-flat-14/64/weather02-512.png" | ||
| alt="Current Weather" | ||
| /> | ||
| </div> | ||
| </div> */} |
There was a problem hiding this comment.
Hi Lucy, sorry for late reply! yes, I have deleted it.
| } else if (weatherId === 801) { | ||
| return images.partlyCloudy; | ||
| } | ||
| return images.mostlyCloudy; |
There was a problem hiding this comment.
Nice code here @zkhing 🙌🏼
mostlycloudy should really be shown between 802 and 805. There is also an icon called unknown.svg so you could show this as your final 'else' condition.
There was a problem hiding this comment.
Please make this small change, then I will approve this PR, and we can merge it in.
There was a problem hiding this comment.
Thank you. Actually, my tech buddy kindly helped me with that part. :) And I added unknown.svg image now.
| {/* <div> | ||
| <img | ||
| className="weather-img" | ||
| src="https://cdn2.iconfinder.com/data/icons/weather-flat-14/64/weather02-512.png" | ||
| alt="Current Weather" | ||
| /> | ||
| </div> */} | ||
|
|
||
|
|
||
| {/* {FakeWeatherData.list.map((data) => ( | ||
| <div key={data.dt}>Temp : {data && data.main.temp}</div> | ||
| ))} */} | ||
|
|
||
| {/* <div>{location}</div> */} | ||
| {/* <div>{temp && temp.list[0].main.temp}</div> */} |
There was a problem hiding this comment.
This is the main wrapper of all your other components. It should look something like this:
<Header />
<main>
<CurrentWeather />
<FutureWeather />
</main>
You currently have all the weather icon and weather data being displayed inside your Header component. This needs to be fetched in the Header component (as you have done), but it needs to be displayed inside of <main>, in a specific component (something like CurrentWeather).
There was a problem hiding this comment.
Let's get this merged in though and I'll create a ticket to move this logic to the right place in a different PR @zkhing
There was a problem hiding this comment.
I have improved some changes Lucy but I am stuck and it is still incomplete yet. Please have a look at the changes that I've made and suggest me how to improve when you have time. I do not know how to slice data from API for current and future weather. Many thanks
| {weatherData?.list?.map((current) => ( | ||
| <CurrentWeather | ||
| description={current.weather.description} | ||
| temp={current.main.temp.toFixed()} | ||
| humidity={current.main.humidity} | ||
| pressure={current.main.pressure} | ||
| /> | ||
| ))} |
There was a problem hiding this comment.
Let's think about this @zkhing
<CurrentWeather /> is just one item of weather. The weather at a specific time.
Unlike FutureWeather which is a list of several items of weather.
So does it makes sense to .map() over the data here? When all we want is one item?
There was a problem hiding this comment.
Hi Lucy, it makes sense not to use .map( ) but I couldn't fetch current weather from API for somehow.
| {weatherData?.list?.map((future) => ( | ||
| <FutureWeather | ||
| time={future.dt_txt} | ||
| iconId={future.weather[0].id} | ||
| temp={future.main.temp.toFixed()} | ||
| /> | ||
| ))} |
There was a problem hiding this comment.
Here we do want more than one item, however:
- We don't want all the data available. There are 40 items in the API data, but we only want to display 7 items (we know this because we are following the design. Always use the design to decide what your code needs to do).
- It would be best to pass the future weather data to the
FutureWeathercomponent, and the component itself should.map()over it and display each item. Rather than mapping here inside App.js.
There was a problem hiding this comment.
- I could mange to display 7 items. But positioning is incorrect and I am not sure whether I should use CSS grid instead of flexbox.
- I tried to pass the future weather data to the FutureWeather component as you suggested but again I couldn't fetch data from API in child component.
There was a problem hiding this comment.
-
You can use grid but you should be able to achieve the layout with just flexbox. It's up to you. The flex container should be full width but have some padding on the sides, so it won't actually look completely full width which is what we want.
The flex items should be placed in a row, centered and with space-between.
Then within each item, you should use flexbox again, this time to place the time, icon and temperature in a column. Again centered. -
You do not need to call the API again! The whole point is to call it once in the parent, and then pass the array of 7 weather items to the FutureWeather component as a prop.
So you should add a prop called for example 'weatherItems' to the FutureWeather component, with your array of 7 items as the value.
Then inside FutureWeather you will receive props.weatherItems and .map() over it (since it is an array). And for each item in the map you can display your weather item with time, icon and temp.
Hope this makes sense! Give it a go and I'll have a look when you're ready.
| <div className="description"> | ||
| <h2>{description}</h2> | ||
| </div> | ||
|
|
||
| <div className="temp"> | ||
| <h3> | ||
| Temperature : {temp_min}° to {temp_max}°C | ||
| </h3> | ||
| </div> | ||
|
|
||
| <div className="box"> | ||
| <div className="sub-box"> | ||
| <h4>Humidity : {humidity}%</h4> | ||
| </div> | ||
|
|
||
| <div className="sub-box"> | ||
| <h4>Pressure : {pressure}</h4> | ||
| </div> | ||
| </div> |
There was a problem hiding this comment.
Do you need to wrap each heading inside a div? What is the intention here? Could you not put the CSS class (description, temp, sub-box etc) on the heading element itself?
Remember we only want the minimum amount of markup to make a cohesive, semantic structure for our content.
There was a problem hiding this comment.
I see. I deleted some divs :) thank you
| justify-content: center; | ||
| align-items: center; | ||
| width: 100%; | ||
| border: 1px solid #fb8500; |
There was a problem hiding this comment.
If you added this border to help you in your development that's fine, but don't commit it 😉
| <Icon name="clear"/> | ||
|
|
||
| <section> | ||
| <WeatherIcon weatherId={weatherData?.list?.[0]?.weather?.[0]?.id} /> |
There was a problem hiding this comment.
Why is this WeatherIcon component not part of CurrentWeather? It displays information about the current weather so it should appear in the same component that displays the temp, pressure etc.
Move it down one level inside the CurrentWeather component
There was a problem hiding this comment.
I moved it down inside the CurrentWeather component.
I ended with the design like that. I know it should not be like that and this is not how I wanted. I couldn't do the exact design due to my poor CSS skill.
Thank you so much Lucy all along the way for teaching and guiding me!! I have learned a lot from you. I started final project on last Saturday therefore, I will focus on final project now. :)
Hi Lucy, I haven't deployed anywhere. This is the branch and I don't know how to make deployed version in this PR. There is a deployed site in main but not updated version. |
Contributors, PR Template
Self checklist
Changelist
Briefly explain your PR.
Context
Link to ticket with
fixes #123Questions
Ask any questions you have for your reviewer.