diff --git a/src/App.js b/src/App.js index 392ed1f..9fa061f 100644 --- a/src/App.js +++ b/src/App.js @@ -16,9 +16,21 @@ import SortUsers from "./components/SortUsers"; import ScaleVideo from "./components/ScaleVideo"; import Modal from "./components/Modal"; import ShowModal from "./components/ShowModal"; +import store from "./store"; -function App() { - return ( +class App extends React.Component { + + componentDidMount() { + fetch('https://jsonplaceholder.typicode.com/users ') + .then(res => res.json()) + .then(data => { + store.dispatch({type: "LOAD_USERS", value: data}) + }) + .catch(err => console.log(`Error: ${err}`)) + } + + render() { + return (
@@ -28,7 +40,7 @@ function App() {
-
+

@@ -60,6 +72,7 @@ function App() {
- ); + ); + } } export default App; \ No newline at end of file diff --git a/src/components/ChangeTemperature.js b/src/components/ChangeTemperature.js index fa894bc..a5102ba 100644 --- a/src/components/ChangeTemperature.js +++ b/src/components/ChangeTemperature.js @@ -1,4 +1,5 @@ import React from "react"; +import store from '../store' function ChangeTemperature(props){ return( @@ -6,7 +7,7 @@ function ChangeTemperature(props){
diff --git a/src/components/CityDropDown.js b/src/components/CityDropDown.js index d43df20..b0b966f 100644 --- a/src/components/CityDropDown.js +++ b/src/components/CityDropDown.js @@ -1,4 +1,5 @@ import React from 'react'; +import store from '../store'; function CityDropDown(props) { return ( @@ -6,7 +7,7 @@ function CityDropDown(props) { CurrentCity: { - + store.dispatch({type:"SET_VIDEO_SCALE", value: e.target.value}) } } type="range" min="1" max="10" step="1" /> diff --git a/src/components/SearchTextBox.js b/src/components/SearchTextBox.js index 43f3416..80ef822 100644 --- a/src/components/SearchTextBox.js +++ b/src/components/SearchTextBox.js @@ -1,11 +1,12 @@ import React from 'react'; +import store from '../store'; function SearchTextBox(props) { return (
Search Users on First Name: { - + store.dispatch({type:"SET_SEARCH_TEXT", value: e.target.value}) }} />
); diff --git a/src/components/ShowModal.js b/src/components/ShowModal.js index 1e73950..fc16399 100644 --- a/src/components/ShowModal.js +++ b/src/components/ShowModal.js @@ -1,11 +1,12 @@ import React from 'react'; +import store from '../store'; function ShowModal(props) { return (
diff --git a/src/components/SortUsers.js b/src/components/SortUsers.js index fd6cb04..429f776 100644 --- a/src/components/SortUsers.js +++ b/src/components/SortUsers.js @@ -1,4 +1,5 @@ import React from 'react'; +import store from '../store'; function SortUsers(props) { return ( @@ -6,7 +7,7 @@ function SortUsers(props) { Sort Users On: { - + store.dispatch({type:"SET_SPECIAL_TEXT", value:e.target.value}) }} />
); diff --git a/src/components/Thermostat.js b/src/components/Thermostat.js index 2e43fbe..c1d54a5 100644 --- a/src/components/Thermostat.js +++ b/src/components/Thermostat.js @@ -1,9 +1,14 @@ import React from "react"; import DonutChart from "./ignore/DonutChart"; +import store from '../store'; class Thermostat extends React.Component { state={temp:""} - + componentDidMount() { + store.subscribe(()=> { + this.setState({temp: store.getState().currentTemp}) + }); + } render() { const { props, diff --git a/src/components/UserButtons.js b/src/components/UserButtons.js index f857369..bfdbafd 100644 --- a/src/components/UserButtons.js +++ b/src/components/UserButtons.js @@ -1,4 +1,5 @@ import React from 'react'; +import store from '../store'; function UserButtons(props) { return ( @@ -13,12 +14,12 @@ function UserButtons(props) { "occupation": "father", "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/calebogden/128.jpg" }; - + store.dispatch({type:"ADD_USER", value:user}) } }>Add User diff --git a/src/components/Users.js b/src/components/Users.js index 79bfbef..51aa4bf 100644 --- a/src/components/Users.js +++ b/src/components/Users.js @@ -1,4 +1,5 @@ import React from 'react'; +import store from '../store'; class Users extends React.Component { @@ -8,6 +9,15 @@ class Users extends React.Component { firstNameFilter:"" } + componentDidMount() { + this.setState({users: store.getState().users}) + store.subscribe(()=>{ + this.setState({users: store.getState().users}); + this.setState({firstNameFilter: store.getState().searchText}); + this.setState({sortOn: store.getState().currentUserSort}) + }) + } + render() { let {users,sortOn,firstNameFilter} = this.state; var usersDivs = null; diff --git a/src/components/VideoPlayer.js b/src/components/VideoPlayer.js index f4fc08b..aaf6b10 100644 --- a/src/components/VideoPlayer.js +++ b/src/components/VideoPlayer.js @@ -1,8 +1,18 @@ import React from 'react'; +import store from '../store'; class VideoPlayer extends React.Component { state={scale:0,URL:""} + componentDidMount() { + store.subscribe(()=>{ + this.setState({ + URL: store.getState().videoURL, + scale: store.getState().videoScale + }) + }) + } + render() { const { props, diff --git a/src/components/VideoTextBox.js b/src/components/VideoTextBox.js index 62cb230..6e51c44 100644 --- a/src/components/VideoTextBox.js +++ b/src/components/VideoTextBox.js @@ -1,4 +1,5 @@ import React from 'react'; +import store from '../store'; function VideoTextBox(props) { return ( @@ -6,7 +7,7 @@ function VideoTextBox(props) { Enter URL of YouTube video { - + store.dispatch({type:"SET_VIDEO_URL", value: e.target.value}) }} type="text" /> diff --git a/src/reducers/index.js b/src/reducers/index.js index e4e85c8..da234ab 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -2,25 +2,27 @@ import { combineReducers } from 'redux' function currentCount(state=0, action){ if(action.type === "INCREASE_COUNTER"){ - + return state + 1 } if(action.type === "DECREASE_COUNTER"){ - + return state - 1 } return state; } function users(state =[], action){ if(action.type === "ADD_USER"){ - + return [...state, action.value] } if(action.type === "REMOVE_USER"){ - + return state.slice(1) + } + if(action.type === "LOAD_USERS"){ + return action.value; } return state; } - function specialText(state = "", action){ if(action.type === "SET_SPECIAL_TEXT"){ return action.value; @@ -28,8 +30,64 @@ function specialText(state = "", action){ return state; } +function currentCity(state = "", action) { + if(action.type === "SET_CURRENT_CITY") { + return action.value + } + return state; +} + +function searchText(state = "", action) { + if(action.type === "SET_SEARCH_TEXT") { + return action.value + } + return state; +} + +function currentTemp(state = 0, action) { + if(action.type === "SET_TEMP") { + return action.value + } + return state; +} + +function isLoading(state = false , action) { + if(action.type === "SET_IS_LOADING") { + return action.value + } + return state; +} + +function videoURL(state = "", action) { + if(action.type === "SET_VIDEO_URL") { + return action.value + } + return state; +} + +function currentUserSort(state = "", action) { + if(action.type === "SET_CURRENT_USER_SORT") { + return action.value + } + return state; +} + +function videoScale(state = 1, action) { + if(action.type === "SET_VIDEO_SCALE") { + return action.value + } + return state; +} + export default combineReducers({ currentCount, users, - specialText + specialText, + currentCity, + searchText, + currentTemp, + isLoading, + videoURL, + currentUserSort, + videoScale }) \ No newline at end of file