-
Notifications
You must be signed in to change notification settings - Fork 85
redux-weather #79
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
Open
kelseyb55
wants to merge
6
commits into
projectshft:master
Choose a base branch
from
kelseyb55:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
redux-weather #79
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
80dcff0
inital commit with folders/files
kelseyb55 1cd6743
fetch API
kelseyb55 036a4bc
create containers and order
kelseyb55 e0c8fa9
created header table
kelseyb55 41147c0
finish weather-display
kelseyb55 111777f
fix errors
kelseyb55 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,30 @@ | ||
| import logo from './logo.svg'; | ||
| import './App.css'; | ||
| import React from 'react'; | ||
| import { Container } from 'react-bootstrap'; | ||
| import Row from 'react-bootstrap/Row'; | ||
| import Col from 'react-bootstrap/Col'; | ||
| import Header from './components/header'; | ||
| import CitySearch from './components/city-search'; | ||
| import CreateDisplay from './components/weather-display'; | ||
| import 'bootstrap/dist/css/bootstrap.min.css'; | ||
|
|
||
| function App() { | ||
| return ( | ||
| <div className="App"> | ||
| <header className="App-header"> | ||
| <img src={logo} className="App-logo" alt="logo" /> | ||
| <p> | ||
| Edit <code>src/App.js</code> and save to reload. | ||
| </p> | ||
| <a | ||
| className="App-link" | ||
| href="https://reactjs.org" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| > | ||
| Learn React | ||
| </a> | ||
| </header> | ||
| </div> | ||
| ); | ||
|
|
||
| <Container className='align-item-center'> | ||
| <Row className='ms-5'> | ||
| <Col> | ||
| <CitySearch /> | ||
| <Header /> | ||
| <CreateDisplay/> | ||
| </Col> | ||
| </Row> | ||
| </Container> | ||
| ) | ||
|
|
||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| export default App; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import axios from "axios"; | ||
|
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. axios is missing from your package.json |
||
|
|
||
| export const FETCH_WEATHER = "FETCH_WEATHER"; | ||
| export const FETCH_AVERAGE = "FETCH_AVERAGE"; | ||
|
|
||
| export function fetchWeather(city) { | ||
| return async (dispatch) => { | ||
| try { | ||
| const response = await axios.get(`https://api.openweathermap.org/data/2.5/forecast?q=${city}&appid=40a22fcb01995614a7b68804376359eb`); | ||
| dispatch({ | ||
| type: FETCH_WEATHER, | ||
| payload: response.data | ||
| }); | ||
| } catch (error) { | ||
| // Handle error here | ||
| console.log(error); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| export function fetchAvg(math) { | ||
| return { | ||
| type: FETCH_AVERAGE, | ||
| payload: math | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { fetchWeather } from "../actions/actions"; | ||
| import { useState } from "react"; | ||
| import { useDispatch } from "react-redux"; | ||
| import { Container } from 'react-bootstrap'; | ||
| import Row from 'react-bootstrap/Row'; | ||
| import Col from 'react-bootstrap/Col'; | ||
|
|
||
|
|
||
| const CitySearch = () => { | ||
| const [city, citySet] = useState(''); | ||
| const dispatch = useDispatch(''); | ||
|
|
||
| const handleWeatherDisplay = () => { | ||
| dispatch(fetchWeather(city)) | ||
| } | ||
|
|
||
| return ( | ||
| <Container> | ||
| <Row> | ||
| <Col> | ||
| <input className="form-control" type="text" placeholder="City" aria-label="City" value={city} onChange={(e) => citySet(e.target.value)}/> | ||
| <button type="button" onClick={handleWeatherDisplay} class="btn btn-primary">Submit</button> | ||
| </Col> | ||
| </Row> | ||
| </Container> | ||
| ) | ||
|
|
||
| } | ||
|
|
||
|
|
||
| export default CitySearch; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import React from 'react' | ||
| import { Container } from 'react-bootstrap'; | ||
| import Row from 'react-bootstrap/Row'; | ||
| import Col from 'react-bootstrap/Col'; | ||
|
|
||
|
|
||
|
|
||
| const Header = () => { | ||
| return ( | ||
| <Container> | ||
| <Row className='table table-bordered align-items-center my-5 mx-5'> | ||
| <Col><h5 style={{textAlign: "center"}}>City</h5></Col> | ||
| <Col><h5 style={{textAlign: "center"}}>Temperature(F)</h5></Col> | ||
| <Col><h5 style={{textAlign: "center"}}>Pressure(hPa)</h5></Col> | ||
| <Col><h5 style={{textAlign: "center"}}>Humidity(%)</h5></Col> | ||
| </Row> | ||
| </Container> | ||
| ); | ||
| }; | ||
|
|
||
| export default Header; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { useSelector } from "react-redux"; | ||
| import { Sparklines, SparklinesLine, SparklinesReferenceLine } from 'react-sparklines'; | ||
| import Container from 'react-bootstrap/Container'; | ||
| import Row from 'react-bootstrap/Row'; | ||
| import Col from 'react-bootstrap/Col'; | ||
|
|
||
| const WeatherDisplay = () => { | ||
| const weather = useSelector((state) => state.weather); | ||
|
|
||
| const handleAvg = (data, measurement) => { | ||
| const average = array => array.reduce((a, b) => a + b) / array.length; | ||
| let correct = 0; | ||
|
|
||
| if (measurement === 'temperature') { | ||
| correct = Math.round(average(data)); | ||
| return <h6>{correct}°F</h6>; | ||
| } else if (measurement === 'pressure') { | ||
| correct = Math.round(average(data)); | ||
| return <h6>{correct} <small>hPa</small></h6>; | ||
| } else if (measurement === 'humidity') { | ||
| correct = Math.round(average(data)); | ||
| return <h6>{correct}%</h6>; | ||
| } | ||
| }; | ||
|
|
||
| const handleWeatherDisplay = () => { | ||
| let data = []; | ||
| let cityName = ''; | ||
|
|
||
| if (weather.length >= 1) { | ||
| weather.forEach((city) => { | ||
| let cityInfo = []; | ||
| for (const key in city) { | ||
| if (key === 'name') { | ||
| cityName = <Col key={key} style={{ textAlign: 'center' }}>{city[key]}</Col>; | ||
| } else { | ||
| cityInfo.push( | ||
| <Col key={key}> | ||
| <Sparklines data={city[key]}> | ||
| <SparklinesLine /> | ||
| <SparklinesReferenceLine type="avg" /> | ||
| </Sparklines> | ||
| <div key={`${city.name}-${key}`} style={{ textAlign: 'center' }}> | ||
| {handleAvg(city[key], key)} | ||
| </div> | ||
| </Col> | ||
| ); | ||
| } | ||
| } | ||
| data.push( | ||
| <Row key={city.name} className="align-items-center mt-4 ms-4"> | ||
| {cityName} | ||
| {cityInfo} | ||
| </Row> | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| return data; | ||
| }; | ||
|
|
||
| return ( | ||
| <Container> | ||
| {handleWeatherDisplay()} | ||
| </Container> | ||
| ); | ||
| }; | ||
|
|
||
| export default WeatherDisplay; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { FETCH_WEATHER } from "../actions/actions"; | ||
|
|
||
| const cityReducer = function (state = [], action) { | ||
| switch (action.type) { | ||
| case FETCH_WEATHER: | ||
| let temperature = []; | ||
| let humidity = []; | ||
| let pressure = []; | ||
| let cityName = ''; | ||
|
|
||
| action.payload.data.list.forEach((section) => { | ||
| temperature.push(section.main.temp); | ||
| humidity.push(section.main.humidity); | ||
| pressure.push(section.main.pressure); | ||
| cityName = action.payload.data.cityName; | ||
| }); | ||
|
|
||
| temperature = temperature.map((day) => Math.round((day - 273) * (9 / 5) + 32)); | ||
| humidity = humidity.map((day) => Math.round(day)); | ||
| pressure = pressure.map((day) => Math.round(day)); | ||
|
|
||
| return [ | ||
| { | ||
| cityName, | ||
| temperature, | ||
| humidity, | ||
| pressure | ||
| }, | ||
| ...state | ||
| ]; | ||
|
|
||
| default: | ||
| return state; | ||
| } | ||
| }; | ||
|
|
||
| export default cityReducer; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
lots of packages missing