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..7de6e20 100644 --- a/src/App.js +++ b/src/App.js @@ -1,17 +1,17 @@ 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 CounterButton from "./containers/CounterBottonContainer"; +import SpecialTextBox from "./containers/SpecialTextBoxContainer"; +import Counter from "./containers/CounterContainer"; +import SpecialText from "./containers/SearchTextBoxContainer"; 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 Thermostat from "./containers/ThermostatContainer"; +import Users from "./containers/UsersContainer"; +import ChangeTemperature from "./containers/ChangeTemperatureContainer"; +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 "./components/SortUsers"; import ScaleVideo from "./components/ScaleVideo"; import Modal from "./components/Modal"; diff --git a/src/actions/index.js b/src/actions/index.js index 78955f4..1a7a752 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -4,6 +4,12 @@ export function increaseCounter(){ } } +export function decreaseCounter(){ + return { + type:"DECREASE_COUNTER" + } +} + export function setSpecialText(txt){ return { type:"SET_SPECIAL_TEXT", @@ -21,4 +27,33 @@ export function removeUser(){ return { type:"REMOVE_USER" } +} + +export function setCurrentCity(city) { + return { + type: "SET_CURRENT_CITY", + value: city + } +} + +export function setCurrentTemperature(temperature) { + return { + type: "SET_CURRENT_TEMPERATURE", + value: temperature + } +} + +export function setVideoUrl(url) { + return { + type: "SET_VIDEO_URL", + value: url + } +} + + +export function setFirstNameFilter(firstName) { + return { + type: "SET_FIRST_NAME", + value: firstName + } } \ No newline at end of file diff --git a/src/components/CityDropDown.js b/src/components/CityDropDown.js index 843b9a3..3b5ecff 100644 --- a/src/components/CityDropDown.js +++ b/src/components/CityDropDown.js @@ -11,6 +11,7 @@ function CityDropDown(props) { } } }> + diff --git a/src/components/SpecialTextBox.js b/src/components/SpecialTextBox.js index 53c3938..83141ef 100644 --- a/src/components/SpecialTextBox.js +++ b/src/components/SpecialTextBox.js @@ -1,8 +1,6 @@ import React from 'react'; -import {connect} from "react-redux"; -import {setSpecialText} from "../actions"; -function SpecialTextBox(props) { +export default function SpecialTextBox(props) { return (
Enter Special Text: @@ -13,14 +11,4 @@ function SpecialTextBox(props) { }} />
); -} - -function mapDispatchToProps(dispatch){ - return { - set:function(txt){ - let action = setSpecialText(txt) - dispatch(action); - } - } -} -export default (SpecialTextBox); \ No newline at end of file +} \ No newline at end of file diff --git a/src/components/UserButtons.js b/src/components/UserButtons.js index 261dd4d..a522e51 100644 --- a/src/components/UserButtons.js +++ b/src/components/UserButtons.js @@ -8,8 +8,7 @@ function UserButtons(props) { if(props.add){ props.add({ "id": 1, - "first_name": "george", - "last_name": "bluth", + "name": "George Bluth", "address": "4116 Magnolia Drive, Portland, ME 04103", "phone": 15551234567, "occupation": "father", diff --git a/src/components/Users.js b/src/components/Users.js index 6a04386..bc41891 100644 --- a/src/components/Users.js +++ b/src/components/Users.js @@ -11,8 +11,8 @@ function Users(props) { (props.firstNameFilter && u.name.indexOf(props.firstNameFilter) > -1); }) - usersDivs = usersDivs.map(function(u){ - return
{u.name}
+ usersDivs = usersDivs.map(function(u, i){ + return
{u.name}
}) } return ( diff --git a/src/containers/ChangeTemperatureContainer.js b/src/containers/ChangeTemperatureContainer.js new file mode 100644 index 0000000..a2fda14 --- /dev/null +++ b/src/containers/ChangeTemperatureContainer.js @@ -0,0 +1,11 @@ +import { connect } from 'react-redux'; +import {setCurrentTemperature} from "../actions"; +import ChangeTemperature from "../components/ChangeTemperature"; + + +const mapDispatchToProps = { + set:setCurrentTemperature + } + + +export default connect(null,mapDispatchToProps)(ChangeTemperature); diff --git a/src/containers/CityDropDownContainer.js b/src/containers/CityDropDownContainer.js new file mode 100644 index 0000000..e356c7c --- /dev/null +++ b/src/containers/CityDropDownContainer.js @@ -0,0 +1,11 @@ +import { connect } from 'react-redux'; +import {setCurrentCity} from "../actions"; +import CityDropDown from "../components/CityDropDown"; + + +const mapDispatchToProps = { + set:setCurrentCity + } + + +export default connect(null,mapDispatchToProps)(CityDropDown); diff --git a/src/containers/CounterBottonContainer.js b/src/containers/CounterBottonContainer.js new file mode 100644 index 0000000..60e7150 --- /dev/null +++ b/src/containers/CounterBottonContainer.js @@ -0,0 +1,12 @@ +import { connect } from 'react-redux'; +import {increaseCounter, decreaseCounter} from "../actions"; +import CounterButton from "../components/CounterButton"; + + +const mapDispatchToProps = { + increase:increaseCounter, + decrease:decreaseCounter + } + + +export default connect(null,mapDispatchToProps)(CounterButton); diff --git a/src/containers/CounterContainer.js b/src/containers/CounterContainer.js new file mode 100644 index 0000000..2e2a094 --- /dev/null +++ b/src/containers/CounterContainer.js @@ -0,0 +1,13 @@ +import { connect } from 'react-redux'; +import Counter from "../components/Counter"; + +//map a prop called text to the state specialText +function mapStateToProps(state){ + console.log("Counter: " + state.currentCount); + + return { + count: state.currentCount + } +} + +export default connect(mapStateToProps)(Counter); diff --git a/src/containers/CurrentCityContainer.js b/src/containers/CurrentCityContainer.js new file mode 100644 index 0000000..7819b81 --- /dev/null +++ b/src/containers/CurrentCityContainer.js @@ -0,0 +1,14 @@ +import { connect } from 'react-redux'; +import {setCurrentCity} from "../actions"; +import CurrentCity from "../components/CurrentCity"; + +//map a prop called text to the state currentCity +function mapStateToProps(state){ + console.log("The new City: " + state.currentCity); + + return { + text: state.currentCity + } +} + +export default connect(mapStateToProps)(CurrentCity); diff --git a/src/containers/SearchTextBoxContainer.js b/src/containers/SearchTextBoxContainer.js new file mode 100644 index 0000000..f9dc72d --- /dev/null +++ b/src/containers/SearchTextBoxContainer.js @@ -0,0 +1,11 @@ +import { connect } from 'react-redux'; +import {setFirstNameFilter} from "../actions"; +import SearchTextBox from "../components/SearchTextBox"; + + +const mapDispatchToProps = { + set:setFirstNameFilter + } + + +export default connect(null,mapDispatchToProps)(SearchTextBox); diff --git a/src/containers/SpecialTextContainer.js b/src/containers/SpecialTextContainer.js index 794bd45..2ce0b44 100644 --- a/src/containers/SpecialTextContainer.js +++ b/src/containers/SpecialTextContainer.js @@ -1,9 +1,10 @@ import { connect } from 'react-redux'; -import {setCurrentUser} from "../actions"; import SpecialText from "../components/SpecialText"; //map a prop called text to the state specialText function mapStateToProps(state){ + console.log("About to pass: " + state.specialText); + return { text: state.specialText } diff --git a/src/containers/ThermostatContainer.js b/src/containers/ThermostatContainer.js new file mode 100644 index 0000000..ca87110 --- /dev/null +++ b/src/containers/ThermostatContainer.js @@ -0,0 +1,13 @@ +import { connect } from 'react-redux'; +import Thermostat from "../components/Thermostat"; + +//map a prop called text to the state specialText +function mapStateToProps(state){ + console.log("Temperature: " + state.currentTemp); + + return { + temp: state.currentTemp + } +} + +export default connect(mapStateToProps)(Thermostat); diff --git a/src/containers/UsersContainer.js b/src/containers/UsersContainer.js new file mode 100644 index 0000000..c2185fe --- /dev/null +++ b/src/containers/UsersContainer.js @@ -0,0 +1,14 @@ +import { connect } from 'react-redux'; +import Users from "../components/Users"; + +//map a prop called text to the state specialText +function mapStateToProps(state){ + + console.log("First Name: " + state.searchText); + return { + users: state.users, + firstNameFilter: state.searchText + } +} + +export default connect(mapStateToProps)(Users); diff --git a/src/containers/VideoPlayerContainer.js b/src/containers/VideoPlayerContainer.js new file mode 100644 index 0000000..be5cbf9 --- /dev/null +++ b/src/containers/VideoPlayerContainer.js @@ -0,0 +1,13 @@ +import { connect } from 'react-redux'; +import VideoPlayer from "../components/VideoPlayer"; + +//map a prop called text to the state specialText +function mapStateToProps(state){ + console.log("Video URL: " + state.videoURL); + + return { + URL: state.videoURL + } +} + +export default connect(mapStateToProps)(VideoPlayer); diff --git a/src/containers/VideoTextBoxContainer.js b/src/containers/VideoTextBoxContainer.js new file mode 100644 index 0000000..ac987f1 --- /dev/null +++ b/src/containers/VideoTextBoxContainer.js @@ -0,0 +1,11 @@ +import { connect } from 'react-redux'; +import {setVideoUrl} from "../actions"; +import VideoTextBox from "../components/VideoTextBox"; + + +const mapDispatchToProps = { + set:setVideoUrl + } + + +export default connect(null,mapDispatchToProps)(VideoTextBox); diff --git a/src/index.js b/src/index.js index 25f54ba..e3b82ab 100644 --- a/src/index.js +++ b/src/index.js @@ -2,9 +2,10 @@ 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..4471c11 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -1,10 +1,12 @@ +import {combineReducers} from "redux"; + function currentCount(state=0, action){ - if(action.type === "INCREASE_COUNTER"){ - + if (action.type === "INCREASE_COUNTER"){ + state += 1; } - if(action.type === "DECREASE_COUNTER"){ - + else if( action.type === "DECREASE_COUNTER"){ + state -= 1; } return state; } @@ -12,9 +14,14 @@ function currentCount(state=0, action){ function users(state =[], action){ if(action.type === "ADD_USER"){ + //let tmp = state.map(p=>p); + //tmp.push(action.value); + //return tmp; + + return [...state, action.value]; } if(action.type === "REMOVE_USER"){ - + return state.splice(); } return state; } @@ -27,3 +34,43 @@ function specialText(state = "", action){ return state; } + +function currentCity(state = "", action) { + if (action.type === "SET_CURRENT_CITY") { + return action.value; + } + return state; +} + + +function currentTemp(state=0, action) { + if (action.type === "SET_CURRENT_TEMPERATURE") { + return action.value + } + return state; +} + +function videoURL(state="", action) { + if (action.type === "SET_VIDEO_URL") { + return action.value + } + return state; +} + +function searchText(state="", action) { + if (action.type == "SET_FIRST_NAME") { + return action.value; + } + return state; +} + +let reducers = combineReducers({ + currentCount, + users, + specialText, + currentCity, + currentTemp, + videoURL, + searchText +}) +export default reducers;