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

Connect to Weather API #28

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

Connect to Weather API #28

wants to merge 20 commits into from

Conversation

zkhing
Copy link

@zkhing zkhing commented Feb 21, 2023

Contributors, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with ISSUE NUMBER | ISSUE TITLE
  • I have linked my PR to the paired issue with #123
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the acceptance criteria

Changelist

Briefly explain your PR.

Context

Link to ticket with fixes #123

Questions

Ask any questions you have for your reviewer.

@LucyMac LucyMac changed the title Main Connect to Weather API Feb 25, 2023
src/App.js Outdated
Comment on lines 16 to 22
{/* <div>
<img
className="weather-img"
src="https://cdn2.iconfinder.com/data/icons/weather-flat-14/64/weather02-512.png"
alt="Current Weather"
/>
</div>
</div> */}
Copy link

Choose a reason for hiding this comment

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

You can delete this

Copy link
Author

Choose a reason for hiding this comment

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

Hi Lucy, sorry for late reply! yes, I have deleted it.

} else if (weatherId === 801) {
return images.partlyCloudy;
}
return images.mostlyCloudy;
Copy link

Choose a reason for hiding this comment

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

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.

Copy link

Choose a reason for hiding this comment

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

Please make this small change, then I will approve this PR, and we can merge it in.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you. Actually, my tech buddy kindly helped me with that part. :) And I added unknown.svg image now.

src/App.js Outdated
Comment on lines 16 to 30
{/* <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> */}
Copy link

Choose a reason for hiding this comment

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

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

Copy link

Choose a reason for hiding this comment

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

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

Copy link
Author

Choose a reason for hiding this comment

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

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

@LucyMac LucyMac mentioned this pull request Feb 25, 2023
4 tasks
@zkhing zkhing mentioned this pull request Mar 1, 2023
6 tasks
src/App.js Outdated
Comment on lines 44 to 51
{weatherData?.list?.map((current) => (
<CurrentWeather
description={current.weather.description}
temp={current.main.temp.toFixed()}
humidity={current.main.humidity}
pressure={current.main.pressure}
/>
))}
Copy link

Choose a reason for hiding this comment

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

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?

Copy link
Author

Choose a reason for hiding this comment

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

Hi Lucy, it makes sense not to use .map( ) but I couldn't fetch current weather from API for somehow.

src/App.js Outdated
Comment on lines 55 to 61
{weatherData?.list?.map((future) => (
<FutureWeather
time={future.dt_txt}
iconId={future.weather[0].id}
temp={future.main.temp.toFixed()}
/>
))}
Copy link

Choose a reason for hiding this comment

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

Here we do want more than one item, however:

  1. 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).
  2. It would be best to pass the future weather data to the FutureWeather component, and the component itself should .map() over it and display each item. Rather than mapping here inside App.js.

Copy link
Author

Choose a reason for hiding this comment

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

  1. 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.
  2. 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.

Copy link

@LucyMac LucyMac Mar 3, 2023

Choose a reason for hiding this comment

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

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

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

Copy link

@LucyMac LucyMac left a comment

Choose a reason for hiding this comment

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

Making good progress @zaw, a few more comments below.

Also, have you deployed this somewhere? It would be useful to have a link in your PR to see the deployed version of the app

Comment on lines 7 to 25
<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>
Copy link

Choose a reason for hiding this comment

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

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.

Copy link
Author

Choose a reason for hiding this comment

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

I see. I deleted some divs :) thank you

src/App.scss Outdated
justify-content: center;
align-items: center;
width: 100%;
border: 1px solid #fb8500;
Copy link

Choose a reason for hiding this comment

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

If you added this border to help you in your development that's fine, but don't commit it 😉

Copy link
Author

Choose a reason for hiding this comment

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

Sure.It's deleted now.

src/App.js Outdated
<Icon name="clear"/>

<section>
<WeatherIcon weatherId={weatherData?.list?.[0]?.weather?.[0]?.id} />
Copy link

Choose a reason for hiding this comment

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

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

Copy link
Author

Choose a reason for hiding this comment

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

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. :)

Copy link

Choose a reason for hiding this comment

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

Good luck with it all @zkhing 😊

@zkhing
Copy link
Author

zkhing commented Mar 8, 2023

Making good progress @zaw, a few more comments below.

Also, have you deployed this somewhere? It would be useful to have a link in your PR to see the deployed version of the app

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.

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