-
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
create button and add the style #22
base: main
Are you sure you want to change the base?
Changes from 3 commits
9d5528e
bb3ef93
85fdb97
d117478
426b1ae
7f5a1c5
c15a499
c430b48
a0b8c33
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,2 @@ | ||
REACT_APP_SITE_TITLE="CYF Weather App" | ||
REACT_APP_API_KEY="f1423eabd2681d82efee065160102eae" |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,25 @@ | ||
@use "theme/utilities.scss"; | ||
@use "theme/global.scss"; | ||
|
||
|
||
:root { | ||
--theme-color--paper: #9CCEF4 ; | ||
--theme-color--ink: #141A5B; | ||
--theme-color--highlight: #fff ; | ||
--theme-color--block: #759EDA; | ||
--theme-color--button: #5879C7; | ||
//speculative / guessed weather colours please update values | ||
--weather--storm: #888; | ||
--weather--drizzle: #efefef; | ||
--weather--rain: #555; | ||
--weather--snow: #bbb; | ||
--weather--fog: #333; | ||
--weather--clear: #3257ea; | ||
--weather--partlycloudy: #4259b8; | ||
--weather--mostlycloudy: #888; | ||
} | ||
|
||
|
||
.weather-container { | ||
background-color: var(--theme-color--paper); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react' | ||
import WeatherImg from "../img/weather-icons/clear.svg" | ||
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" | ||
const WeatherImages = ({infWeather}) => { | ||
return ( | ||
<> | ||
{ | ||
infWeather < 300 ? <img src={Storm} /> | ||
: infWeather >= 300 && infWeather <= 499 ? <img | ||
src={Drizzle} /> : infWeather >= 500 && infWeather <= 599 ? <img | ||
src={Rain} /> : infWeather >= 600 && infWeather <= 699 ? <img | ||
src={Snow} /> : infWeather >= 700 && infWeather <= 799 ? <img | ||
src={Fog} /> : infWeather === 800 ? <img | ||
src={Clear} /> : infWeather === 801 ? <img | ||
src={PartlyCloudy} /> : infWeather >= 802 && infWeather <= 805 ? <img | ||
src={MostlyCloudy} /> : | ||
<p>No Image Found</p> | ||
} | ||
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. Good logic here. As a side note on best practices, when there is a complex conditional statement like this one, it's best to move it outside the component's JSX because it makes it hard to read. You could move this to a function (inside the component but before the return) like for example:
|
||
</> | ||
) | ||
} | ||
|
||
export default WeatherImages |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react' | ||
import "./CurrentWeather.scss" | ||
// Importing Image | ||
import WeatherImages from '../../WeatherImages/WeatherImages' | ||
|
||
const CurrentWeather = ({weatherInfo}) => { | ||
|
||
if(weatherInfo.length > 0){ | ||
|
||
const infWeather = weatherInfo[0].weather[0].id | ||
Comment on lines
+6
to
+10
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. As mentioned in my comment in |
||
|
||
// const WeatherIcons = (infWeather)=>{ | ||
// return ( | ||
// infWeather < 300 ? <img src={Storm} /> | ||
// : infWeather >= 300 && infWeather <= 499 ? <img | ||
// src={Drizzle} /> : infWeather >= 500 && infWeather <= 599 ? <img | ||
// src={Rain} /> : infWeather >= 600 && infWeather <= 699 ? <img | ||
// src={Snow} /> : infWeather >= 700 && infWeather <= 799 ? <img | ||
// src={Fog} /> : infWeather === 800 ? <img | ||
// src={Clear} /> : infWeather === 801 ? <img | ||
// src={PartlyCloudy} /> : infWeather >= 802 && infWeather <= 805 ? <img | ||
// src={MostlyCloudy} /> : | ||
// <p>No Image Found</p> | ||
// )} | ||
Comment on lines
+12
to
+24
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. It's best not to commit commented out code like this. I would delete it. Especially because your |
||
return ( | ||
|
||
<div className='current-weather-container'> | ||
<div className='weather-details'> | ||
<WeatherImages infWeather={infWeather}/> | ||
|
||
<h2>{weatherInfo[0].weather[0].description}</h2> | ||
<h3>Temperature {weatherInfo[0].main.temp_min} to {weatherInfo[0].main.temp_max} C</h3> | ||
<p>Humidity {weatherInfo[0].main.humidity} Pressure {weatherInfo[0].main.pressure}</p> | ||
</div> | ||
</div> | ||
|
||
|
||
)} else { | ||
return (<p>Not data found</p>) | ||
} | ||
} | ||
|
||
export default CurrentWeather |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
|
||
.current-weather-container { | ||
display: flex; | ||
justify-content: center; | ||
|
||
.weather-details { | ||
margin: 10px 0; | ||
justify-content: center; | ||
text-align: center; | ||
} | ||
|
||
h2 { | ||
color: white; | ||
text-align: center; | ||
font-size: 1.5rem; | ||
font-family: Raleway; | ||
|
||
} | ||
h3{ | ||
|
||
text-align: center; | ||
color: var(--theme-color-ink); | ||
} | ||
p{ | ||
color: var(--theme-color-ink); | ||
text-align: center; | ||
font-size: 1.5rem; | ||
} | ||
|
||
|
||
img { | ||
width: 200px; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react' | ||
import "./FutureWeather.scss" | ||
|
||
import SingleFutureWeather from './SingleFutureWeather' | ||
|
||
|
||
const FutureWeather = (props) => { | ||
const {weatherInfo} = props | ||
|
||
console.log('Future Weather Info:', weatherInfo); | ||
// const newArr = weatherInfo.slice(0, 7) | ||
// console.log(newArr); | ||
|
||
// Create a Child Comp, WeatherCard. Pass Item as a prop, and sdisplay there | ||
return ( | ||
<div className='FutureWeather'> | ||
<p>FutureWeather</p> | ||
<div className="weather-container" style={{display: "flex", justifyContent:"center"}}> | ||
{ | ||
weatherInfo.length > 0 ? | ||
weatherInfo.slice(1, 7).map((item) => { | ||
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. Good that you're slicing the data here 👍🏼 |
||
console.log(item); | ||
return ( | ||
<SingleFutureWeather item={item}/> | ||
) | ||
}) : <p>No Data</p> | ||
} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default FutureWeather |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.FutureWeather { | ||
background-color: var(--theme-color--paper); | ||
margin-bottom: 10rem; | ||
text-align: center; | ||
margin-top: 2rem; | ||
padding-bottom: 1rem; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react' | ||
import WeatherImages from '../../WeatherImages/WeatherImages' | ||
|
||
const SingleFutureWeather = ({item}) => { | ||
let infWeather = item.weather[0].id | ||
return ( | ||
<div> | ||
<p>{item.dt_txt}</p> | ||
<WeatherImages infWeather={infWeather}/> | ||
<p>{(item.main.temp).toFixed(2)} C</p> | ||
</div> | ||
) | ||
} | ||
|
||
export default SingleFutureWeather |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, {useState} from "react"; | ||
import axios from "axios" | ||
import './Search.scss' | ||
|
||
const Search = ({title, setWeatherInfo}) => { | ||
const [city, setCity] = useState("") | ||
|
||
const API_KEY = process.env.REACT_APP_API_KEY | ||
console.log('API Key:', API_KEY); | ||
const API_URL = `http://api.openweathermap.org/data/2.5/forecast?q=${city}&cnt=8&units=metric&appid=${API_KEY}` | ||
const handleSubmit = (e) => { | ||
e.preventDefault() | ||
|
||
//API Request using Axios | ||
getWeatherInfo() | ||
console.log(city); | ||
} | ||
|
||
// This function sends an API Request via Axios | ||
const getWeatherInfo = async () => { | ||
// axios request | ||
// try { | ||
|
||
// } | ||
// catch(err){ | ||
|
||
// } | ||
Comment on lines
+21
to
+27
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. Avoid committing comments like this, unless they are particularly useful to the other developers working on the project with you. |
||
try { | ||
|
||
|
||
const resp = await axios.get(API_URL) | ||
console.log('Response:', resp); | ||
setWeatherInfo(resp.data.list) | ||
} | ||
catch(err){ | ||
console.log('We have An Error'); | ||
console.log(err.message); | ||
setWeatherInfo([]) | ||
alert("Something went wrong!") | ||
} | ||
} | ||
|
||
return ( | ||
<header className="c-site-header"> | ||
<h1 className="c-site-header__title">{title}</h1> | ||
<form onSubmit={(e) => handleSubmit(e)}> | ||
{/* */} | ||
<input type="text" value={city} onChange={(e) => setCity(e.target.value)} /> | ||
<button>Search</button> | ||
</form> | ||
|
||
</header> | ||
) | ||
|
||
|
||
} | ||
export default Search; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@use "../../theme/utilities.scss"; | ||
|
||
|
||
.c-site-header { | ||
background-color: var(--theme-color--block); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
button { | ||
appearance: none; | ||
background-color: var(--theme-color--button); | ||
color: var(--theme-color--ink); | ||
padding: var(--theme-spacing--2); | ||
text-transform: uppercase; | ||
Comment on lines
+3
to
+7
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. Try and make this button looks as much like the design provided as possible. Replicating designs into CSS is a key front-end developer skill. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ | |
//global html styles | ||
@import "./base.scss"; | ||
@import "./invisible.scss"; | ||
@import "./button.scss"; |
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.
Do you need to pass ALL the data to both these components? It's always best to pass down just what a component needs.
In this case:
CurrentWeather
only needs one item from the array of weather in the API response. AndFutureWeather
needs 7 items (according to the design which is our source of truth here), so you need to make a small array of 7 items here, and pass down that small array toFutureWeather
instead of the whole thing