diff --git a/package-lock.json b/package-lock.json index ee9a1d2..d7bb883 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3187,12 +3187,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3207,17 +3209,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -3334,7 +3339,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -3346,6 +3352,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -3360,6 +3367,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -3367,12 +3375,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -3391,6 +3401,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -3471,7 +3482,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -3483,6 +3495,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -3604,6 +3617,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -7113,12 +7127,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -7133,17 +7149,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -7260,7 +7279,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -7272,6 +7292,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -7286,6 +7307,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -7293,12 +7315,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -7317,6 +7341,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -7397,7 +7422,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -7409,6 +7435,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -7530,6 +7557,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", diff --git a/src/App.js b/src/App.js index 392ed1f..4412fb1 100644 --- a/src/App.js +++ b/src/App.js @@ -1,21 +1,21 @@ import React from 'react'; -import CounterButton from "./components/CounterButton"; -import SpecialTextBox from "./components/SpecialTextBox"; -import Counter from "./components/Counter"; -import SpecialText from "./components/SpecialText"; -import UserButtons from "./components/UserButtons"; -import Thermostat from "./components/Thermostat"; -import Users from "./components/Users"; -import ChangeTemperature from "./components/ChangeTemperature"; -import VideoPlayer from "./components/VideoPlayer"; -import VideoTextBox from "./components/VideoTextBox"; -import CurrentCity from "./components/CurrentCity"; -import CityDropDown from "./components/CityDropDown"; -import SearchTextBox from "./components/SearchTextBox"; -import SortUsers from "./components/SortUsers"; -import ScaleVideo from "./components/ScaleVideo"; -import Modal from "./components/Modal"; -import ShowModal from "./components/ShowModal"; +import CounterButton from "./containers/CounterButtonContainer"; +import SpecialTextBox from "./containers/SpecialTextBoxContainer"; +import Counter from "./containers/CounterContainer"; +import SpecialText from "./containers/SpecialTextContainer"; +import UserButtons from "./containers/UserButtonContainer"; +import Thermostat from "./containers/ThermostatContainer"; +import Users from "./containers/UsersContainer"; +import ChangeTemperature from "./containers/ChangeTempContainer"; +import VideoPlayer from "./containers/VideoPlayerContainer"; +import VideoTextBox from "./containers/VideoTextBoxContainer"; +import CurrentCity from "./containers/CurrentCityContainer"; +import CityDropDown from "./containers/CityDropDownContainer"; +import SearchTextBox from "./containers/SearchTextBoxContainer"; +import SortUsers from "./containers/SortUserContainer"; +import ScaleVideo from "./containers/ScaleVideoContainer"; +import Modal from "./containers/ModalContainer"; +import ShowModal from "./containers/ShowModalContainer"; function App() { return ( diff --git a/src/actions/index.js b/src/actions/index.js index 78955f4..a35ed66 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -1,24 +1,104 @@ +export const INCREASE_COUNTER = "INCREASE_COUNTER"; + export function increaseCounter(){ return { - type:"INCREASE_COUNTER" + type:INCREASE_COUNTER + } +} + +export const DECREASE_COUNTER = "DECREASE_COUNTER"; + +export function decreaseCounter(){ + return { + type: DECREASE_COUNTER, } } +export const SET_SPECIAL_TEXT = "SET_SPECIAL_TEXT"; + export function setSpecialText(txt){ return { - type:"SET_SPECIAL_TEXT", + type: SET_SPECIAL_TEXT, value:txt } } +export const ADD_USER = "ADD_USER"; + export function addUser(user){ return { - type:"ADD_USER", + type: ADD_USER, value:user } } + +export const REMOVE_USER = "REMOVE_USER" + export function removeUser(){ return { - type:"REMOVE_USER" + type: REMOVE_USER, + } +} + +export const SET_SEARCH_TEXT = "SET_SEARCH_TEXT"; + +export function setSearchText(text) { + return { + type:SET_SEARCH_TEXT, + value:text + } +} + +export const SET_IS_LOADING = "SET_IS_LOADING"; + +export function setIsLoading(isLoading) { + return { + type:SET_IS_LOADING, + value:isLoading + } +} + +export const SET_TEMP = "SET_TEMP"; + +export function setTemp(temp) { + return { + type:SET_TEMP, + value:temp + } +} + +export const SET_CURRENT_CITY = "SET_CURRENT_CITY"; + +export function setCurrentCity(city) { + return { + type:SET_CURRENT_CITY, + value:city + } +} + +export const SET_VIDEO_URL = "SET_VIDEO_URL"; + +export function setVideoURL(URL) { + return { + type:SET_VIDEO_URL, + value:URL + } +} + +export const SET_CURRENT_USER_SORT = "SET_CURRENT_USER_SORT"; + +export function setCurrentUserSort(sort) { + return { + type:SET_CURRENT_USER_SORT, + value:sort + } +} + +export const SET_VIDEO_SCALE = "SET_VIDEO_SCALE"; + +export function setVideoScale(scale) { + return { + type:SET_VIDEO_SCALE, + value: scale } -} \ No newline at end of file +} \ No newline at end of file diff --git a/src/components/CounterButton.js b/src/components/CounterButton.js index df3a778..7925382 100644 --- a/src/components/CounterButton.js +++ b/src/components/CounterButton.js @@ -1,4 +1,12 @@ import React from 'react'; +import {connect} from "react-redux"; +import { decreaseCounter, increaseCounter } from '../actions'; + +const mapDispatchToProps = { + decrease:decreaseCounter, + increase: increaseCounter +}; + function CounterButton(props) { return ( @@ -20,4 +28,4 @@ function CounterButton(props) { ); } -export default CounterButton; \ No newline at end of file +export default connect(null, mapDispatchToProps)(CounterButton); \ No newline at end of file diff --git a/src/containers/ChangeTempContainer.js b/src/containers/ChangeTempContainer.js new file mode 100644 index 0000000..1770fb8 --- /dev/null +++ b/src/containers/ChangeTempContainer.js @@ -0,0 +1,9 @@ +import {connect} from 'react-redux'; +import ChangeTemperature from '../components/ChangeTemperature'; +import {setTemp} from '../actions/index'; + +const mapDispatchToProps = { + set: setTemp +} + +export default connect(null, mapDispatchToProps)(ChangeTemperature); \ No newline at end of file diff --git a/src/containers/CityDropDownContainer.js b/src/containers/CityDropDownContainer.js new file mode 100644 index 0000000..e1123a1 --- /dev/null +++ b/src/containers/CityDropDownContainer.js @@ -0,0 +1,9 @@ +import {connect} from 'react-redux'; +import CityDropDown from '../components/CityDropDown'; +import {setCurrentCity} from '../actions/index'; + +const mapDispatchToProps = { + set: setCurrentCity +} + +export default connect(null, mapDispatchToProps)(CityDropDown); \ No newline at end of file diff --git a/src/containers/CounterButtonContainer.js b/src/containers/CounterButtonContainer.js new file mode 100644 index 0000000..d8bc12e --- /dev/null +++ b/src/containers/CounterButtonContainer.js @@ -0,0 +1,11 @@ +import {connect} from 'react-redux'; +import CounterButton from '../components/CounterButton'; +import {increaseCounter} from '../actions/index'; +import {decreaseCounter} from '../actions/index'; + +const mapDispatchToProps = { + increase: increaseCounter, + decrease: decreaseCounter +} + +export default connect(null, mapDispatchToProps)(CounterButton); \ No newline at end of file diff --git a/src/containers/CounterContainer.js b/src/containers/CounterContainer.js new file mode 100644 index 0000000..ba441a5 --- /dev/null +++ b/src/containers/CounterContainer.js @@ -0,0 +1,10 @@ +import {connect} from 'react-redux'; +import Counter from '../components/Counter'; + +function mapStateToProps (state) { + return { + count: state.currentCount + } +} + +export default connect(mapStateToProps)(Counter); \ No newline at end of file diff --git a/src/containers/CurrentCityContainer.js b/src/containers/CurrentCityContainer.js new file mode 100644 index 0000000..c0318b9 --- /dev/null +++ b/src/containers/CurrentCityContainer.js @@ -0,0 +1,10 @@ +import {connect} from 'react-redux'; +import CurrentCity from '../components/CurrentCity'; + +function mapStateToProps(state) { + return { + text: state.currentCity + } +} + +export default connect(mapStateToProps)(CurrentCity); \ No newline at end of file diff --git a/src/containers/ModalContainer.js b/src/containers/ModalContainer.js new file mode 100644 index 0000000..6751998 --- /dev/null +++ b/src/containers/ModalContainer.js @@ -0,0 +1,15 @@ +import {connect} from 'react-redux'; +import LoadingModal from '../components/Modal'; +import {setIsLoading} from '../actions/index'; + +function mapStateToProps(state) { + return { + isLoading: state.isLoading + } +} + +const mapDispatchToProps = { + setIsLoading +} + +export default connect(mapStateToProps, mapDispatchToProps)(LoadingModal); \ No newline at end of file diff --git a/src/containers/ScaleVideoContainer.js b/src/containers/ScaleVideoContainer.js new file mode 100644 index 0000000..da9aa5b --- /dev/null +++ b/src/containers/ScaleVideoContainer.js @@ -0,0 +1,9 @@ +import {connect} from 'react-redux'; +import ScaleVideo from '../components/ScaleVideo'; +import {setVideoScale} from '../actions/index'; + +const mapDispatchToProps = { + set: setVideoScale +} + +export default connect(null, mapDispatchToProps)(ScaleVideo); \ No newline at end of file diff --git a/src/containers/SearchTextBoxContainer.js b/src/containers/SearchTextBoxContainer.js new file mode 100644 index 0000000..15d086c --- /dev/null +++ b/src/containers/SearchTextBoxContainer.js @@ -0,0 +1,9 @@ +import {connect} from 'react-redux'; +import SearchTextBox from '../components/SearchTextBox'; +import {setSearchText} from '../actions/index'; + +const mapDispatchToProps = { + set: setSearchText +} + +export default connect(null, mapDispatchToProps)(SearchTextBox); \ No newline at end of file diff --git a/src/containers/ShowModalContainer.js b/src/containers/ShowModalContainer.js new file mode 100644 index 0000000..a518813 --- /dev/null +++ b/src/containers/ShowModalContainer.js @@ -0,0 +1,9 @@ +import {connect} from 'react-redux'; +import ShowModal from '../components/ShowModal'; +import {setIsLoading} from '../actions/index'; + +const mapDispatchToProps = { + setIsLoading +} + +export default connect(null, mapDispatchToProps)(ShowModal); \ No newline at end of file diff --git a/src/containers/SortUserContainer.js b/src/containers/SortUserContainer.js new file mode 100644 index 0000000..bca2447 --- /dev/null +++ b/src/containers/SortUserContainer.js @@ -0,0 +1,9 @@ +import {connect} from 'react-redux'; +import SortUsers from '../components/SortUsers'; +import {setCurrentUserSort} from '../actions/index'; + +const mapDispatchToProps = { + set: setCurrentUserSort +} + +export default connect(null, mapDispatchToProps)(SortUsers); \ No newline at end of file diff --git a/src/containers/ThermostatContainer.js b/src/containers/ThermostatContainer.js new file mode 100644 index 0000000..61bebd5 --- /dev/null +++ b/src/containers/ThermostatContainer.js @@ -0,0 +1,9 @@ +import {connect} from 'react-redux'; +import Thermostat from '../components/Thermostat'; + +function mapStateToProps(state) { + return { + temp: state.currentTemp + } +} +export default connect(mapStateToProps)(Thermostat); \ No newline at end of file diff --git a/src/containers/UserButtonContainer.js b/src/containers/UserButtonContainer.js new file mode 100644 index 0000000..078fe13 --- /dev/null +++ b/src/containers/UserButtonContainer.js @@ -0,0 +1,10 @@ +import {connect} from 'react-redux'; +import UserButton from '../components/UserButtons'; +import {addUser} from '../actions/index'; +import {removeUser} from '../actions/index'; + +const mapDispatchToProps = { + add: addUser, + remove: removeUser +} +export default connect(null, mapDispatchToProps)(UserButton); \ No newline at end of file diff --git a/src/containers/UsersContainer.js b/src/containers/UsersContainer.js new file mode 100644 index 0000000..5962d54 --- /dev/null +++ b/src/containers/UsersContainer.js @@ -0,0 +1,11 @@ +import {connect} from 'react-redux'; +import Users from '../components/Users'; + +function mapStateToProps(state) { + return { + users: state.users, + firstNameFilter: state.searchText, + sortOn: state.currentUserSort + } +} +export default connect(mapStateToProps)(Users); \ No newline at end of file diff --git a/src/containers/VideoPlayerContainer.js b/src/containers/VideoPlayerContainer.js new file mode 100644 index 0000000..a889176 --- /dev/null +++ b/src/containers/VideoPlayerContainer.js @@ -0,0 +1,11 @@ +import {connect} from 'react-redux'; +import VideoPlayer from '../components/VideoPlayer'; + +function mapStateToProps(state) { + return { + scale: state.videoScale, + URL: state.videoURL + } +} + +export default connect (mapStateToProps)(VideoPlayer); \ No newline at end of file diff --git a/src/containers/VideoTextBoxContainer.js b/src/containers/VideoTextBoxContainer.js new file mode 100644 index 0000000..25bb474 --- /dev/null +++ b/src/containers/VideoTextBoxContainer.js @@ -0,0 +1,9 @@ +import {connect} from 'react-redux'; +import VideoTextBox from '../components/VideoTextBox'; +import {setVideoURL} from '../actions/index'; + +const mapDispatchToProps = { + set: setVideoURL +} + +export default connect(null, mapDispatchToProps)(VideoTextBox); \ No newline at end of file diff --git a/src/index.js b/src/index.js index 25f54ba..df3d903 100644 --- a/src/index.js +++ b/src/index.js @@ -2,9 +2,13 @@ import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; import './index.css'; +import {Provider} from 'react-redux'; +import store from './store'; ReactDOM.render( + , + , document.getElementById('root') ); diff --git a/src/reducers/index.js b/src/reducers/index.js index dce7c2c..c264bb2 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -1,29 +1,105 @@ +import {combineReducers} from 'redux'; +import {INCREASE_COUNTER} from "../actions/index"; +import {DECREASE_COUNTER} from "../actions/index"; +import {SET_SPECIAL_TEXT} from '../actions/index'; +import {ADD_USER} from '../actions/index'; +import {REMOVE_USER} from '../actions/index'; +import {SET_CURRENT_CITY} from '../actions/index'; +import {SET_SEARCH_TEXT} from '../actions/index'; +import {SET_TEMP} from '../actions/index'; +import {SET_IS_LOADING} from '../actions/index'; +import {SET_VIDEO_URL} from '../actions/index'; +import {SET_CURRENT_USER_SORT} from '../actions/index'; +import {SET_VIDEO_SCALE} from '../actions/index'; function currentCount(state=0, action){ - if(action.type === "INCREASE_COUNTER"){ - + if(action.type === INCREASE_COUNTER){ + return state +1 } - if(action.type === "DECREASE_COUNTER"){ - + + if(action.type === DECREASE_COUNTER){ + return state -1 } return state; -} +} -function users(state =[], action){ - if(action.type === "ADD_USER"){ +function users(state =[], action){ + if(action.type === ADD_USER){ + return [...state, action.value] } - if(action.type === "REMOVE_USER"){ - + if(action.type === REMOVE_USER){ + return state.slice(1) } return state; } function specialText(state = "", action){ - if(action.type === "SET_SPECIAL_TEXT"){ + if(action.type === SET_SPECIAL_TEXT){ + return action.value; + } + 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="first_name",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, + currentCity, + searchText, + currentTemp, + isLoading, + videoURL, + currentUserSort, + videoScale +})