From 8c308e318eb7adf75922388e7ae7fc469b2ba46c Mon Sep 17 00:00:00 2001 From: Aaron Altounian Date: Tue, 28 May 2019 20:52:48 -0500 Subject: [PATCH 1/3] got up to currentTemp --- package-lock.json | 56 +++++++++++++++++++++-------- src/components/ChangeTemperature.js | 8 ++++- src/components/CityDropDown.js | 8 ++++- src/components/Counter.js | 9 +++++ src/components/CounterButton.js | 11 ++++-- src/components/CurrentCity.js | 8 +++++ src/components/SpecialText.js | 9 +++++ src/components/SpecialTextBox.js | 9 +++-- src/components/Thermostat.js | 8 +++++ src/reducers/index.js | 40 +++++++++++++++------ 10 files changed, 136 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index 20071db..2224181 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3086,12 +3086,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" @@ -3106,17 +3108,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", @@ -3233,7 +3238,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -3245,6 +3251,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -3259,6 +3266,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -3266,12 +3274,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" @@ -3290,6 +3300,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -3370,7 +3381,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -3382,6 +3394,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -3503,6 +3516,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", @@ -7487,12 +7501,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" @@ -7507,17 +7523,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", @@ -7634,7 +7653,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -7646,6 +7666,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -7660,6 +7681,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -7667,12 +7689,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" @@ -7691,6 +7715,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -7771,7 +7796,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -7783,6 +7809,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -7904,6 +7931,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/components/ChangeTemperature.js b/src/components/ChangeTemperature.js index fa894bc..d1826fb 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,12 @@ function ChangeTemperature(props){
diff --git a/src/components/CityDropDown.js b/src/components/CityDropDown.js index c47586e..91e462d 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,12 @@ function CityDropDown(props) { CurrentCity: { - + let value = e.target.value; + let message = { + type: 'SET_SPECIAL_TEXT', + value: value + } + store.dispatch(message); }} /> ); diff --git a/src/components/Thermostat.js b/src/components/Thermostat.js index 2e43fbe..ce5c3dc 100644 --- a/src/components/Thermostat.js +++ b/src/components/Thermostat.js @@ -1,9 +1,17 @@ import React from "react"; import DonutChart from "./ignore/DonutChart"; +import store from '../store'; class Thermostat extends React.Component { state={temp:""} + componentDidMount() { + store.subscribe(() => { + let temp = store.getState().currentTemp; + this.setState({temp}); + }) + } + render() { const { props, diff --git a/src/reducers/index.js b/src/reducers/index.js index e4e85c8..b7031ad 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -1,28 +1,46 @@ import { combineReducers } from 'redux' -function currentCount(state=0, action){ - if(action.type === "INCREASE_COUNTER"){ - +function currentCount(state=0, action) { + 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") { } - if(action.type === "REMOVE_USER"){ + + if(action.type === "REMOVE_USER") { } + 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 currentTemp(state='', action) { + if(action.type === 'SET_CURRENT_TEMP') { return action.value; } return state; @@ -31,5 +49,7 @@ function specialText(state = "", action){ export default combineReducers({ currentCount, users, - specialText + specialText, + currentCity, + currentTemp }) \ No newline at end of file From c7ddbb7a5bde579d59f9cd9f3a7f1316c3fb4332 Mon Sep 17 00:00:00 2001 From: Aaron Altounian Date: Wed, 29 May 2019 21:28:21 -0500 Subject: [PATCH 2/3] can't get Modal and ShowModal to work with isLoading --- src/components/ChangeTemperature.js | 2 +- src/components/Modal.js | 15 ++++++++++++++- src/components/ShowModal.js | 9 ++++++++- src/reducers/index.js | 12 ++++++++++-- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/components/ChangeTemperature.js b/src/components/ChangeTemperature.js index d1826fb..fdd1a44 100644 --- a/src/components/ChangeTemperature.js +++ b/src/components/ChangeTemperature.js @@ -9,7 +9,7 @@ function ChangeTemperature(props){ { let value = e.target.value; let message = { - type: 'SET_CURRENT_TEMP', + type: 'SET_TEMP', value: value } store.dispatch(message); diff --git a/src/components/Modal.js b/src/components/Modal.js index 1789040..4f709fc 100644 --- a/src/components/Modal.js +++ b/src/components/Modal.js @@ -1,10 +1,19 @@ import React from 'react'; import Modal from 'react-modal'; +import store from '../store'; class LoadingModal extends React.Component { state={ isLoading:false } + + componentDidMount() { + store.subscribe(() => { + let isLoading = store.getState().isLoading; + this.setState({isLoading}); + }) + } + render() { const { props, @@ -18,7 +27,11 @@ class LoadingModal extends React.Component { >
Loading .......
diff --git a/src/components/ShowModal.js b/src/components/ShowModal.js index 1e73950..c2e6ae5 100644 --- a/src/components/ShowModal.js +++ b/src/components/ShowModal.js @@ -1,11 +1,18 @@ import React from 'react'; +import store from '../store'; +import state from '../state'; function ShowModal(props) { + return (
diff --git a/src/reducers/index.js b/src/reducers/index.js index b7031ad..dc47985 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -40,7 +40,14 @@ function currentCity(state = "", action) { } function currentTemp(state='', action) { - if(action.type === 'SET_CURRENT_TEMP') { + 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; @@ -51,5 +58,6 @@ export default combineReducers({ users, specialText, currentCity, - currentTemp + currentTemp, + isLoading }) \ No newline at end of file From 219451b56e60834ea4b49b17ed9efe91eff33082 Mon Sep 17 00:00:00 2001 From: Aaron Altounian Date: Thu, 30 May 2019 18:27:37 -0500 Subject: [PATCH 3/3] got showModal to work --- src/components/Modal.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/Modal.js b/src/components/Modal.js index 4f709fc..5fbb8cb 100644 --- a/src/components/Modal.js +++ b/src/components/Modal.js @@ -9,8 +9,9 @@ class LoadingModal extends React.Component { componentDidMount() { store.subscribe(() => { + console.log(store.getState().isLoading); let isLoading = store.getState().isLoading; - this.setState({isLoading}); + this.setState({isLoading: isLoading}); }) } @@ -21,7 +22,7 @@ class LoadingModal extends React.Component { return (