From 5d7ae508326699552495da955246d86c61ac9dd1 Mon Sep 17 00:00:00 2001 From: yamov Date: Wed, 13 Feb 2019 09:55:43 +0100 Subject: [PATCH 1/9] Remove unused functions, variables, modules and assets. --- package.json | 1 - src/App.test.js | 9 --- src/actionCreators.js | 7 --- src/actionTypes.js | 3 +- src/index.css | 5 -- src/index.js | 10 ---- src/logo.svg | 7 --- src/reducers.js | 4 +- src/registerServiceWorker.js | 113 ----------------------------------- src/store.js | 10 +--- yarn.lock | 2 +- 11 files changed, 4 insertions(+), 167 deletions(-) delete mode 100644 src/App.test.js delete mode 100644 src/index.css delete mode 100644 src/logo.svg delete mode 100644 src/registerServiceWorker.js diff --git a/package.json b/package.json index ab559ea..77e6d1e 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "private": true, "dependencies": { "aphrodite": "^2.2.2", - "express": "^4.16.3", "react": "^16.4.1", "react-dom": "^16.4.1", "react-redux": "^5.0.7", diff --git a/src/App.test.js b/src/App.test.js deleted file mode 100644 index 4bf1935..0000000 --- a/src/App.test.js +++ /dev/null @@ -1,9 +0,0 @@ -import React from 'react' -import ReactDOM from 'react-dom' -import App from './App' - -it('renders without crashing', () => { - const div = document.createElement('div') - ReactDOM.render(, div) - ReactDOM.unmountComponentAtNode(div) -}) diff --git a/src/actionCreators.js b/src/actionCreators.js index d53ec6c..2460d65 100644 --- a/src/actionCreators.js +++ b/src/actionCreators.js @@ -6,13 +6,6 @@ export const addQuestion = () => { } } -export const loadQuestions = result => { - return { - type: actionTypes.LOAD_QUESTIONS, - data: result, - } -} - export const addAnswer = () => { return { type: actionTypes.ADD_ANSWER, diff --git a/src/actionTypes.js b/src/actionTypes.js index e71eed2..2657d71 100644 --- a/src/actionTypes.js +++ b/src/actionTypes.js @@ -2,6 +2,5 @@ export const ADD_QUESTION = 'ADD_QUESTION' export const ADD_ANSWER = 'ADD_ANSWER' export const CHANGE_MESSAGE = 'CHANGE_MESSAGE' export const REMOVE_MESSAGE = 'REMOVE_MESSAGE' -export const LOAD_QUESTIONS = 'LOAD_QUESTIONS' export const INCREMENT_COUNTER = 'INCREMENT_COUNTER' -export const DECREMENT_COUNTER = 'DECREMENT_COUNTER' \ No newline at end of file +export const DECREMENT_COUNTER = 'DECREMENT_COUNTER' diff --git a/src/index.css b/src/index.css deleted file mode 100644 index b4cc725..0000000 --- a/src/index.css +++ /dev/null @@ -1,5 +0,0 @@ -body { - margin: 0; - padding: 0; - font-family: sans-serif; -} diff --git a/src/index.js b/src/index.js index 9be622e..a043dc9 100644 --- a/src/index.js +++ b/src/index.js @@ -1,11 +1,8 @@ import React from 'react' import ReactDOM from 'react-dom' -import './index.css' import App from './App' -import registerServiceWorker from './registerServiceWorker' import store from './store' import Provider from 'react-redux/es/components/Provider' -// import { loadQuestions } from './actionCreators' ReactDOM.render( @@ -14,10 +11,3 @@ ReactDOM.render( document.getElementById('root') ) -// fetch('/polish') -// .then(res => res.json()) -// .then(result => { -// store.dispatch(loadQuestions(result)) -// }) - -registerServiceWorker() diff --git a/src/logo.svg b/src/logo.svg deleted file mode 100644 index 6b60c10..0000000 --- a/src/logo.svg +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/src/reducers.js b/src/reducers.js index 675be18..f4cd1f5 100644 --- a/src/reducers.js +++ b/src/reducers.js @@ -1,5 +1,3 @@ -// @flow - import * as actionTypes from './actionTypes' export const chatReducer = ( @@ -57,4 +55,4 @@ export const counterReducer = (state = 0, action) => { default: return state } -} \ No newline at end of file +} diff --git a/src/registerServiceWorker.js b/src/registerServiceWorker.js deleted file mode 100644 index df05bcb..0000000 --- a/src/registerServiceWorker.js +++ /dev/null @@ -1,113 +0,0 @@ -// In production, we register a service worker to serve assets from local cache. - -// This lets the app load faster on subsequent visits in production, and gives -// it offline capabilities. However, it also means that developers (and users) -// will only see deployed updates on the "N+1" visit to a page, since previously -// cached resources are updated in the background. - -// To learn more about the benefits of this model, read https://goo.gl/KwvDNy. -// This link also includes instructions on opting out of this behavior. - -const isLocalhost = Boolean( - window.location.hostname === 'localhost' || - // [::1] is the IPv6 localhost address. - window.location.hostname === '[::1]' || - // 127.0.0.1/8 is considered localhost for IPv4. - window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/) -) - -export default function register() { - if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { - // The URL constructor is available in all browsers that support SW. - const publicUrl = new URL(process.env.PUBLIC_URL, window.location) - if (publicUrl.origin !== window.location.origin) { - // Our service worker won't work if PUBLIC_URL is on a different origin - // from what our page is served on. This might happen if a CDN is used to - // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374 - return - } - - window.addEventListener('load', () => { - const swUrl = `${process.env.PUBLIC_URL}/service-worker.js` - - if (isLocalhost) { - // This is running on localhost. Lets check if a service worker still exists or not. - checkValidServiceWorker(swUrl) - - // Add some additional logging to localhost, pointing developers to the - // service worker/PWA documentation. - navigator.serviceWorker.ready.then(() => { - console.log( - 'This web app is being served cache-first by a service ' + - 'worker. To learn more, visit https://goo.gl/SC7cgQ' - ) - }) - } else { - // Is not local host. Just register service worker - registerValidSW(swUrl) - } - }) - } -} - -function registerValidSW(swUrl) { - navigator.serviceWorker - .register(swUrl) - .then(registration => { - registration.onupdatefound = () => { - const installingWorker = registration.installing - installingWorker.onstatechange = () => { - if (installingWorker.state === 'installed') { - if (navigator.serviceWorker.controller) { - // At this point, the old content will have been purged and - // the fresh content will have been added to the cache. - // It's the perfect time to display a "New content is - // available; please refresh." message in your web app. - console.log('New content is available; please refresh.') - } else { - // At this point, everything has been precached. - // It's the perfect time to display a - // "Content is cached for offline use." message. - console.log('Content is cached for offline use.') - } - } - } - } - }) - .catch(error => { - console.error('Error during service worker registration:', error) - }) -} - -function checkValidServiceWorker(swUrl) { - // Check if the service worker can be found. If it can't reload the page. - fetch(swUrl) - .then(response => { - // Ensure service worker exists, and that we really are getting a JS file. - if ( - response.status === 404 || - response.headers.get('content-type').indexOf('javascript') === -1 - ) { - // No service worker found. Probably a different app. Reload the page. - navigator.serviceWorker.ready.then(registration => { - registration.unregister().then(() => { - window.location.reload() - }) - }) - } else { - // Service worker found. Proceed as normal. - registerValidSW(swUrl) - } - }) - .catch(() => { - console.log('No internet connection found. App is running in offline mode.') - }) -} - -export function unregister() { - if ('serviceWorker' in navigator) { - navigator.serviceWorker.ready.then(registration => { - registration.unregister() - }) - } -} diff --git a/src/store.js b/src/store.js index 9107b43..d42e95a 100644 --- a/src/store.js +++ b/src/store.js @@ -1,15 +1,7 @@ -import { createStore } from 'redux' -import { combineReducers } from 'redux' +import { createStore, combineReducers } from 'redux' import { chatReducer, counterReducer } from './reducers' -// const appReducer = (state = {}, action) => { -// return { -// chat: chatReducer(state.chat, action), -// counter: counterReducer(state.counter, action), -// } -// } - const appReducer = combineReducers({ chat: chatReducer, counter: counterReducer, diff --git a/yarn.lock b/yarn.lock index 4536fa8..1fc85f3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2539,7 +2539,7 @@ expand-tilde@^2.0.0, expand-tilde@^2.0.2: dependencies: homedir-polyfill "^1.0.1" -express@^4.13.3, express@^4.16.3: +express@^4.13.3: version "4.16.3" resolved "https://registry.yarnpkg.com/express/-/express-4.16.3.tgz#6af8a502350db3246ecc4becf6b5a34d22f7ed53" dependencies: From 0ce8504857077f4ca626f01f706a8d8fe341481a Mon Sep 17 00:00:00 2001 From: yamov Date: Wed, 13 Feb 2019 10:08:05 +0100 Subject: [PATCH 2/9] Move redux-related modules to the `store` directory. --- src/App.js | 2 +- src/index.js | 3 ++- src/{ => store}/actionCreators.js | 0 src/{ => store}/actionTypes.js | 0 src/{store.js => store/index.js} | 0 src/{ => store}/reducers.js | 0 6 files changed, 3 insertions(+), 2 deletions(-) rename src/{ => store}/actionCreators.js (100%) rename src/{ => store}/actionTypes.js (100%) rename src/{store.js => store/index.js} (100%) rename src/{ => store}/reducers.js (100%) diff --git a/src/App.js b/src/App.js index 3b8d6a0..a5adf3f 100644 --- a/src/App.js +++ b/src/App.js @@ -7,7 +7,7 @@ import { removeMessage, incrementCounter, decrementCounter, -} from './actionCreators' +} from './store/actionCreators' import Button from './components/Button.js' import MessagesToType from './components/MessagesToType' import { MessagesToShow } from './components/MessagesToShow' diff --git a/src/index.js b/src/index.js index a043dc9..4636a79 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,9 @@ import React from 'react' import ReactDOM from 'react-dom' +import Provider from 'react-redux/es/components/Provider' + import App from './App' import store from './store' -import Provider from 'react-redux/es/components/Provider' ReactDOM.render( diff --git a/src/actionCreators.js b/src/store/actionCreators.js similarity index 100% rename from src/actionCreators.js rename to src/store/actionCreators.js diff --git a/src/actionTypes.js b/src/store/actionTypes.js similarity index 100% rename from src/actionTypes.js rename to src/store/actionTypes.js diff --git a/src/store.js b/src/store/index.js similarity index 100% rename from src/store.js rename to src/store/index.js diff --git a/src/reducers.js b/src/store/reducers.js similarity index 100% rename from src/reducers.js rename to src/store/reducers.js From 7014ab8f011bf9a503d5c08b053504bf0c346a5b Mon Sep 17 00:00:00 2001 From: yamov Date: Wed, 13 Feb 2019 10:20:25 +0100 Subject: [PATCH 3/9] Prettify all. --- src/App.js | 98 +++++++++++++------------------- src/components/MessagesToShow.js | 5 +- src/index.js | 1 - src/store/reducers.js | 90 ++++++++++++++--------------- 4 files changed, 89 insertions(+), 105 deletions(-) diff --git a/src/App.js b/src/App.js index a5adf3f..0fbe7d2 100644 --- a/src/App.js +++ b/src/App.js @@ -1,79 +1,63 @@ -import React, { Component } from 'react' +import React from 'react' import { connect } from 'react-redux' +import { css, StyleSheet } from 'aphrodite/no-important' + import { addAnswer, addQuestion, changeMessage, - removeMessage, - incrementCounter, decrementCounter, + incrementCounter, + removeMessage, } from './store/actionCreators' import Button from './components/Button.js' import MessagesToType from './components/MessagesToType' import { MessagesToShow } from './components/MessagesToShow' -import { StyleSheet, css } from 'aphrodite/no-important' -class App extends Component { - render() { - return ( -
-
-
-
-
-
-
Start counting: {this.props.counter}
-
-
- {this.props.messages.map((value, index) => ( - - ))} -
-
+const App = props => { + return ( +
+
+
+
-
+
+
+
Start counting: {props.counter}
+
- {this.props.messages.map((item, index, array) => ( - ( + ))}
- ) - } +
+
+ {props.messages.map((item, index, array) => ( + + ))} +
+
+
+ ) } const styles = StyleSheet.create({ diff --git a/src/components/MessagesToShow.js b/src/components/MessagesToShow.js index c32cc85..887f3bb 100644 --- a/src/components/MessagesToShow.js +++ b/src/components/MessagesToShow.js @@ -2,7 +2,7 @@ import React from 'react' import carla from '../carla.png' import { StyleSheet, css } from 'aphrodite/no-important' -function MessagesToShow(props) { +const MessagesToShow = props => { const type = props.type let messageContainer = [styles.messageContainer] @@ -19,7 +19,8 @@ function MessagesToShow(props) {
Avatar of Carla
- {props.item}  + {props.item} +   {props.hasCounter && The current counter is {props.counter}}
diff --git a/src/index.js b/src/index.js index 4636a79..153c5e5 100644 --- a/src/index.js +++ b/src/index.js @@ -11,4 +11,3 @@ ReactDOM.render( , document.getElementById('root') ) - diff --git a/src/store/reducers.js b/src/store/reducers.js index f4cd1f5..2b974be 100644 --- a/src/store/reducers.js +++ b/src/store/reducers.js @@ -1,58 +1,58 @@ import * as actionTypes from './actionTypes' export const chatReducer = ( - state = [{ text: 'question 0', type: 'question' }, { text: 'answer 0', type: 'answer' }], - action + state = [{ text: 'question 0', type: 'question' }, { text: 'answer 0', type: 'answer' }], + action ) => { - switch (action.type) { - case actionTypes.ADD_QUESTION: - return [ - ...state, - { - text: 'question', - type: 'question', - }, - ] + switch (action.type) { + case actionTypes.ADD_QUESTION: + return [ + ...state, + { + text: 'question', + type: 'question', + }, + ] - case actionTypes.ADD_ANSWER: - return [ - ...state, - { - text: 'answer', - type: 'answer', - }, - ] - case actionTypes.CHANGE_MESSAGE: - return state.map((currentMessage, i) => { - if (i === action.data.index) { - return { - text: action.data.newText, - type: currentMessage.type, - } - } else { - return currentMessage - } - }) + case actionTypes.ADD_ANSWER: + return [ + ...state, + { + text: 'answer', + type: 'answer', + }, + ] + case actionTypes.CHANGE_MESSAGE: + return state.map((currentMessage, i) => { + if (i === action.data.index) { + return { + text: action.data.newText, + type: currentMessage.type, + } + } else { + return currentMessage + } + }) - case actionTypes.REMOVE_MESSAGE: - return state.filter((el, i) => { - return i !== action.data.index - }) + case actionTypes.REMOVE_MESSAGE: + return state.filter((el, i) => { + return i !== action.data.index + }) - default: - return state - } + default: + return state + } } export const counterReducer = (state = 0, action) => { - switch (action.type) { - case actionTypes.INCREMENT_COUNTER: - return ++state + switch (action.type) { + case actionTypes.INCREMENT_COUNTER: + return ++state - case actionTypes.DECREMENT_COUNTER: - return state <= 0 ? 0 : --state + case actionTypes.DECREMENT_COUNTER: + return state <= 0 ? 0 : --state - default: - return state - } + default: + return state + } } From d72ee75dc59c8ff5710a042599a255c997dd19c4 Mon Sep 17 00:00:00 2001 From: yamov Date: Wed, 13 Feb 2019 10:59:58 +0100 Subject: [PATCH 4/9] Remove counter logic from the app. --- src/App.js | 57 ++++++++------------------------ src/components/Button.js | 8 ++--- src/components/MessagesToShow.js | 6 +--- src/store/actionCreators.js | 12 ------- src/store/actionTypes.js | 2 -- src/store/index.js | 3 +- src/store/reducers.js | 13 -------- 7 files changed, 19 insertions(+), 82 deletions(-) diff --git a/src/App.js b/src/App.js index 0fbe7d2..e072051 100644 --- a/src/App.js +++ b/src/App.js @@ -2,14 +2,7 @@ import React from 'react' import { connect } from 'react-redux' import { css, StyleSheet } from 'aphrodite/no-important' -import { - addAnswer, - addQuestion, - changeMessage, - decrementCounter, - incrementCounter, - removeMessage, -} from './store/actionCreators' +import { addAnswer, addQuestion, changeMessage, removeMessage } from './store/actionCreators' import Button from './components/Button.js' import MessagesToType from './components/MessagesToType' import { MessagesToShow } from './components/MessagesToShow' @@ -20,39 +13,26 @@ const App = props => {
-
-
-
Start counting: {props.counter}
-
- {props.messages.map((value, index) => ( - - ))} -
+ {props.messages.map((value, index) => ( + + ))}
+
{props.messages.map((item, index, array) => ( - + ))}
@@ -86,17 +66,10 @@ const styles = StyleSheet.create({ width: '50%', boxSizing: 'border-box', }, - counter: { - padding: '2rem', - backgroundColor: 'yellow', - fontWeight: 'bold', - marginBottom: '2rem', - }, }) const mapStateToProps = state => ({ messages: state.chat, - counter: state.counter, }) const mapDispatchToProps = { @@ -104,8 +77,6 @@ const mapDispatchToProps = { addAnswer, changeMessage, removeMessage, - incrementCounter, - decrementCounter, } export default connect( diff --git a/src/components/Button.js b/src/components/Button.js index 7435a82..caf770b 100644 --- a/src/components/Button.js +++ b/src/components/Button.js @@ -22,11 +22,9 @@ class Button extends React.Component { } return ( -
- -
+ ) } } diff --git a/src/components/MessagesToShow.js b/src/components/MessagesToShow.js index 887f3bb..e4c4e3c 100644 --- a/src/components/MessagesToShow.js +++ b/src/components/MessagesToShow.js @@ -18,11 +18,7 @@ const MessagesToShow = props => { return (
Avatar of Carla -
- {props.item} -   - {props.hasCounter && The current counter is {props.counter}} -
+
{props.item}
) } diff --git a/src/store/actionCreators.js b/src/store/actionCreators.js index 2460d65..c530801 100644 --- a/src/store/actionCreators.js +++ b/src/store/actionCreators.js @@ -30,15 +30,3 @@ export const removeMessage = index => { }, } } - -export const incrementCounter = () => { - return { - type: actionTypes.INCREMENT_COUNTER, - } -} - -export const decrementCounter = () => { - return { - type: actionTypes.DECREMENT_COUNTER, - } -} diff --git a/src/store/actionTypes.js b/src/store/actionTypes.js index 2657d71..686362d 100644 --- a/src/store/actionTypes.js +++ b/src/store/actionTypes.js @@ -2,5 +2,3 @@ export const ADD_QUESTION = 'ADD_QUESTION' export const ADD_ANSWER = 'ADD_ANSWER' export const CHANGE_MESSAGE = 'CHANGE_MESSAGE' export const REMOVE_MESSAGE = 'REMOVE_MESSAGE' -export const INCREMENT_COUNTER = 'INCREMENT_COUNTER' -export const DECREMENT_COUNTER = 'DECREMENT_COUNTER' diff --git a/src/store/index.js b/src/store/index.js index d42e95a..98806fb 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,10 +1,9 @@ import { createStore, combineReducers } from 'redux' -import { chatReducer, counterReducer } from './reducers' +import { chatReducer } from './reducers' const appReducer = combineReducers({ chat: chatReducer, - counter: counterReducer, }) const store = createStore( diff --git a/src/store/reducers.js b/src/store/reducers.js index 2b974be..4d064ae 100644 --- a/src/store/reducers.js +++ b/src/store/reducers.js @@ -43,16 +43,3 @@ export const chatReducer = ( return state } } - -export const counterReducer = (state = 0, action) => { - switch (action.type) { - case actionTypes.INCREMENT_COUNTER: - return ++state - - case actionTypes.DECREMENT_COUNTER: - return state <= 0 ? 0 : --state - - default: - return state - } -} From e61488d800057913bdd0e8015b63961091a61de9 Mon Sep 17 00:00:00 2001 From: yamov Date: Wed, 13 Feb 2019 11:58:28 +0100 Subject: [PATCH 5/9] Create assets directory --- src/{ => assets}/carla.png | Bin src/assets/typing_44x20.gif | Bin 0 -> 11895 bytes src/components/MessagesToShow.js | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename src/{ => assets}/carla.png (100%) create mode 100644 src/assets/typing_44x20.gif diff --git a/src/carla.png b/src/assets/carla.png similarity index 100% rename from src/carla.png rename to src/assets/carla.png diff --git a/src/assets/typing_44x20.gif b/src/assets/typing_44x20.gif new file mode 100644 index 0000000000000000000000000000000000000000..53bed596e7905f993a7f6fcec3bdf0bb80d31b59 GIT binary patch literal 11895 zcmeI2cUaSRyT&ugFC>95f(c;Vh0?SF5eHqU~Glcwf(x{E*st{yEpVPOt0uhay9W_vgN!`}zL96DNiG zk5BNxFfdCo815U&G)?pjl_EmpC6?l`7~{KQrbcko33&fZz(!~qs z&wYIM%;~{_Q~f9VdOtdG{Md&dyx(*5NcZ7G2M_Gux3{ZvPe*&(?$(y(T}_P*J9lia ze{b8?Et@xOtlLn#zGhu@Rb|E6^0Lwry{@>ZP`hUJs+B92FDqEOBtI{A@uHlC*;$zx z>1nA8=BFelB__oGbKcyzf5gs-nLTS}^o*#;i0RX&PMI7&DQse>My*mRLM8+U$pZsq z{^R|8eZ0Lqr4q5oL+CExySchJJMp+2M+bX5wk?Y}&W2%aWobb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dDvUfEwa@3~J*AfnT5oq9HjUp8;NAa5SZXRwLTRs&2R}0KE&iM%PbZ ze~fFG6e!m~G`fC*w}5MObfdKm+yGny-6+)Hv%fFY?;fZ8`l{C&f0B^ozOlyL8^JUZ z-0G_-B1G11r{K0!gedHgLx&`+1dVJ%Pt~a8DvS|mUEDG3SwOJ z!*P!WIV>u9UWP^EP_g6PnC|_T@9hrTc0JhiO79+<{dS5gj3_RCpokSrrePv#n%A`! z&Dy_fc&}!7qQ7$G{%%GypNqFG{K51}!i;9NjgKXjhk3@a{c!%jaN~=vXdPvCaY$mX zlxs^Vip$YrLX)P^rVRBSKu9#JO { From b8dd7e5e8d8bdad65a0e99b51db21d5f9fccacaa Mon Sep 17 00:00:00 2001 From: yamov Date: Wed, 13 Feb 2019 12:06:05 +0100 Subject: [PATCH 6/9] Add fakeApi module --- src/fakeApi.js | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/fakeApi.js diff --git a/src/fakeApi.js b/src/fakeApi.js new file mode 100644 index 0000000..7ab78bb --- /dev/null +++ b/src/fakeApi.js @@ -0,0 +1,3 @@ +export const getQuestionMessage = () => { + return 'Question message' +} From 94bfda8f6949e21b9527b103569cdfff344e3638 Mon Sep 17 00:00:00 2001 From: yamov Date: Wed, 13 Feb 2019 12:34:23 +0100 Subject: [PATCH 7/9] Install and set up redux-thunk library --- package.json | 3 ++- src/store/index.js | 6 ++++-- yarn.lock | 5 +++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 77e6d1e..16955e9 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "react-dom": "^16.4.1", "react-redux": "^5.0.7", "react-scripts": "1.1.4", - "redux": "^4.0.0" + "redux": "^4.0.0", + "redux-thunk": "^2.3.0" }, "scripts": { "start": "react-scripts start", diff --git a/src/store/index.js b/src/store/index.js index 98806fb..e45f372 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,4 +1,5 @@ -import { createStore, combineReducers } from 'redux' +import { createStore, combineReducers, applyMiddleware } from 'redux' +import thunk from 'redux-thunk' import { chatReducer } from './reducers' @@ -8,7 +9,8 @@ const appReducer = combineReducers({ const store = createStore( appReducer, - window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() + window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(), + applyMiddleware(thunk) ) export default store diff --git a/yarn.lock b/yarn.lock index 1fc85f3..0132d02 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5744,6 +5744,11 @@ reduce-function-call@^1.0.1: dependencies: balanced-match "^0.4.2" +redux-thunk@^2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.3.0.tgz#51c2c19a185ed5187aaa9a2d08b666d0d6467622" + integrity sha512-km6dclyFnmcvxhAcrQV2AkZmPQjzPDjgVlQtR0EQjxZPyJ0BnMf3in1ryuR8A2qU0HldVRfxYXbFSKlI3N7Slw== + redux@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.0.tgz#aa698a92b729315d22b34a0553d7e6533555cc03" From 32729784639d32b14a9cee3cb48a510e3f48ff01 Mon Sep 17 00:00:00 2001 From: yamov Date: Wed, 13 Feb 2019 13:28:41 +0100 Subject: [PATCH 8/9] Set initial chat state to empty array --- src/store/reducers.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/store/reducers.js b/src/store/reducers.js index 4d064ae..559b6c0 100644 --- a/src/store/reducers.js +++ b/src/store/reducers.js @@ -1,7 +1,7 @@ import * as actionTypes from './actionTypes' export const chatReducer = ( - state = [{ text: 'question 0', type: 'question' }, { text: 'answer 0', type: 'answer' }], + state = [], action ) => { switch (action.type) { @@ -9,7 +9,7 @@ export const chatReducer = ( return [ ...state, { - text: 'question', + text: 'Question', type: 'question', }, ] @@ -18,7 +18,7 @@ export const chatReducer = ( return [ ...state, { - text: 'answer', + text: 'Answer', type: 'answer', }, ] From b8f3cb586be6533f660d3930b30626daa8d38b1e Mon Sep 17 00:00:00 2001 From: yamov Date: Wed, 13 Feb 2019 14:07:42 +0100 Subject: [PATCH 9/9] Minor cleanup. --- src/App.js | 10 ++++------ src/components/MessagesToShow.js | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/App.js b/src/App.js index e072051..24d7e4f 100644 --- a/src/App.js +++ b/src/App.js @@ -5,7 +5,7 @@ import { css, StyleSheet } from 'aphrodite/no-important' import { addAnswer, addQuestion, changeMessage, removeMessage } from './store/actionCreators' import Button from './components/Button.js' import MessagesToType from './components/MessagesToType' -import { MessagesToShow } from './components/MessagesToShow' +import MessagesToShow from './components/MessagesToShow' const App = props => { return ( @@ -30,11 +30,9 @@ const App = props => {
-
- {props.messages.map((item, index, array) => ( - - ))} -
+ {props.messages.map((item, index, array) => ( + + ))}
) diff --git a/src/components/MessagesToShow.js b/src/components/MessagesToShow.js index ff3f9c7..7cea0e5 100644 --- a/src/components/MessagesToShow.js +++ b/src/components/MessagesToShow.js @@ -61,4 +61,4 @@ const styles = StyleSheet.create({ }, }) -export { MessagesToShow } +export default MessagesToShow