-
Notifications
You must be signed in to change notification settings - Fork 12
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
base: main
Are you sure you want to change the base?
Changes from 14 commits
08fa292
dac08f8
87d8e92
a18dd57
be36012
85d523f
ebb724f
accfe59
544ee29
2cbd25e
8b2d947
fa398df
dc4e844
f47a206
925f7de
7c3b35c
050e635
4a6f098
b458d4b
42f58a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,83 @@ | ||
@use "theme/utilities.scss"; | ||
@use "theme/global.scss"; | ||
|
||
|
||
.App{ | ||
background-color: #8ecae6; | ||
} | ||
|
||
.c-site-header{ | ||
padding: 20px; | ||
} | ||
|
||
.heading{ | ||
background-color: #219ebc; | ||
padding: 10px; | ||
} | ||
|
||
.c-site-header__title{ | ||
color: #023047; | ||
padding: 20px; | ||
} | ||
|
||
.city{ | ||
margin: 15px; | ||
padding: 15px; | ||
} | ||
|
||
.search-btn{ | ||
background-color: #023047; | ||
color: white; | ||
margin-left: 15px; | ||
padding: 15px; | ||
} | ||
|
||
.weather-img{ | ||
margin: auto; | ||
width: 200px; | ||
height: 200px; | ||
object-fit: cover; | ||
} | ||
|
||
.description{ | ||
display: flex; | ||
justify-content: center; | ||
color: white; | ||
} | ||
|
||
.temp { | ||
display: flex; | ||
justify-content: center; | ||
margin: 20px; | ||
} | ||
|
||
.box{ | ||
display: flex; | ||
justify-content: center; | ||
} | ||
|
||
.sub-box{ | ||
padding: 30px; | ||
} | ||
|
||
|
||
// -----------future weather------ | ||
|
||
.container{ | ||
display: flex; | ||
width: 100%; | ||
padding: 0px 2em 0px 2em; | ||
} | ||
|
||
.items{ | ||
display: flex; | ||
background-color: #023047; | ||
justify-content: center; | ||
align-items: center; | ||
width: 100%; | ||
border: 1px solid #fb8500; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 😉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure.It's deleted now. |
||
} | ||
|
||
.time,.temperature{ | ||
color: white; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react' | ||
|
||
|
||
function CurrentWeather({ description, temp_min, temp_max, humidity, pressure }) { | ||
return ( | ||
<> | ||
<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. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. I deleted some divs :) thank you |
||
</> | ||
); | ||
} | ||
|
||
export default CurrentWeather |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from "react"; | ||
import WeatherIcon from "./Picture/WeatherIcon"; | ||
|
||
|
||
function FutureWeather({ time, iconId, temp }) { | ||
const formattedTime = time.split(" ")[1].slice(0,5) | ||
|
||
return ( | ||
<div className="container"> | ||
<div className="items time">{formattedTime}</div> | ||
<div className="items"> | ||
<WeatherIcon weatherId={iconId} /> | ||
</div> | ||
<div className="items temperature">{temp}°C</div> | ||
</div> | ||
); | ||
} | ||
export default FutureWeather; | ||
|
||
|
||
// function FutureWeather({ getNewWeather, weatherData }) { | ||
|
||
// return ( | ||
// <div> | ||
// {weatherData?.list?.map((future) => ( | ||
// <div> | ||
// <p>{future?.dt_txt?.split(" ")[1].slice(0, 5)}</p> | ||
// <WeatherIcon>{future.weather[0].id}</WeatherIcon> | ||
// <p>{future.main.temp.toFixed()}</p> | ||
// </div> | ||
// ))} | ||
// </div> | ||
// ); | ||
// } | ||
|
||
// export default FutureWeather; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
import React from "react"; | ||
import './Header.scss' | ||
import "./Header.scss"; | ||
import React, { useState } from "react"; | ||
|
||
const Header = ({title}) => | ||
const Header = ({ title, getNewWeather }) => { | ||
const [city, setCity] = useState(""); | ||
|
||
return ( | ||
<header className="c-site-header"> | ||
<h1 className="c-site-header__title o-type__invisible">{title}</h1> | ||
{/* look up component */} | ||
<div className="heading"> | ||
<h1 className="c-site-header__title">{title}</h1> | ||
<input | ||
className="city" | ||
type="text" | ||
placeholder="Type in a city name" | ||
value={city} | ||
onChange={(event) => setCity(event.target.value)} | ||
/> | ||
<button className="search-btn" onClick={() => getNewWeather(city)}> | ||
FIND WEATHER | ||
</button> | ||
</div> | ||
|
||
</header> | ||
); | ||
}; | ||
|
||
|
||
export default Header; | ||
export default Header; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from "react"; | ||
import storm from "../../img/weather-icons/storm.svg"; | ||
import drizzle from "../../img/weather-icons/drizzle.svg"; | ||
import rain from "../../img/weather-icons/rain.svg"; | ||
import snow from "../../img/weather-icons/snow.svg"; | ||
import fog from "../../img/weather-icons/fog.svg"; | ||
import clear from "../../img/weather-icons/clear.svg"; | ||
import partlyCloudy from "../../img/weather-icons/partlycloudy.svg"; | ||
import mostlyCloudy from "../../img/weather-icons/mostlycloudy.svg"; | ||
import unknown from "../../img/weather-icons/unknown.svg" | ||
|
||
const images = { | ||
storm: { src: storm, alt: "storm" }, | ||
drizzle: { src: drizzle, alt: "drizzle" }, | ||
rain: { src: rain, alt: "rain" }, | ||
snow: { src: snow, alt: "snow" }, | ||
fog: { src: fog, alt: "fog" }, | ||
clear: { src: clear, alt: "clear" }, | ||
partlyCloudy: { src: partlyCloudy, alt: "partly cloudy" }, | ||
mostlyCloudy: { src: mostlyCloudy, alt: "mostly cloudy" }, | ||
unknown: { src: unknown, alt: "unknown" }, | ||
}; | ||
|
||
|
||
function selectImage(weatherId){ | ||
if (weatherId < 300) { | ||
return images.storm; | ||
} else if (weatherId < 499) { | ||
return images.drizzle; | ||
} else if (weatherId < 599) { | ||
return images.rain; | ||
} else if (weatherId < 699) { | ||
return images.snow; | ||
} else if (weatherId < 799) { | ||
return images.fog; | ||
} else if (weatherId === 800) { | ||
return images.clear; | ||
} else if (weatherId === 801) { | ||
return images.partlyCloudy; | ||
} else if (weatherId < 805 && weatherId > 801) { | ||
return images.mostlyCloudy; | ||
} | ||
return images.unknown; | ||
} | ||
|
||
const WeatherIcon = ({weatherId}) =>{ | ||
|
||
const image = selectImage(weatherId) | ||
|
||
return ( | ||
<div className="weather-img"> | ||
<img src={image.src} alt={image.alt} /> | ||
</div> | ||
); | ||
} | ||
|
||
export default WeatherIcon; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. :)
There was a problem hiding this comment.
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 😊