From 030514eac862417eaa7f84926c00c7cc6fbb8e20 Mon Sep 17 00:00:00 2001 From: ohjonah Date: Mon, 28 Aug 2017 22:25:51 -0700 Subject: [PATCH 01/19] Adds Scaffolding --- .babelrc | 3 + .eslintignore | 5 + .eslintrc | 21 ++++ .gitignore | 136 +++++++++++++++++++++ package.json | 21 ++++ src/component/app/index.js | 0 src/component/dashboard-container/index.js | 0 src/index.html | 0 src/main.js | 0 webpack.config.js | 0 10 files changed, 186 insertions(+) create mode 100644 .babelrc create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .gitignore create mode 100644 package.json create mode 100644 src/component/app/index.js create mode 100644 src/component/dashboard-container/index.js create mode 100644 src/index.html create mode 100644 src/main.js create mode 100644 webpack.config.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..facd180 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["es2015", "react"] +} \ No newline at end of file diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..82ff623 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* \ No newline at end of file diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..b663d77 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,21 @@ +{ + "rules": { + "no-console": "off", + "indent": [ "error", 2 ], + "quotes": [ "error", "single" ], + "semi": ["error", "always"], + "linebreak-style": [ "error", "unix" ] + }, + "env": { + "es6": true, + "node": true, + "mocha": true, + "jasmine": true + }, + "ecmaFeatures": { + "modules": true, + "experimentalObjectRestSpread": true, + "impliedStrict": true + }, + "extends": "eslint:recommended" +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..393ef53 --- /dev/null +++ b/.gitignore @@ -0,0 +1,136 @@ +# Created by https://www.gitignore.io/api/osx,vim,node,macos,windows + +### macOS ### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + + +### OSX ### + +# Icon must end with two \r + +# Thumbnails + +# Files that might appear in the root of a volume + +# Directories potentially created on remote AFP share + +### Vim ### +# swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-v][a-z] +[._]sw[a-p] +# session +Session.vim +# temporary +.netrwhist +*~ +# auto-generated tag files +tags + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.gitignore.io/api/osx,vim,node,macos,windows \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..78b7961 --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "name": "26-react-redux", + "version": "1.0.0", + "description": "![cf](https://i.imgur.com/7v5ASc8.png) 26: React & Redux ======", + "main": "main.js", + "scripts": { + "build": "webpack", + "watch": "webpack-dev-server --inline --hot" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/ohjonah/26-react-redux.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/ohjonah/26-react-redux/issues" + }, + "homepage": "https://github.com/ohjonah/26-react-redux#readme" +} diff --git a/src/component/app/index.js b/src/component/app/index.js new file mode 100644 index 0000000..e69de29 diff --git a/src/component/dashboard-container/index.js b/src/component/dashboard-container/index.js new file mode 100644 index 0000000..e69de29 diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..e69de29 diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..e69de29 diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..e69de29 From 52a7c43c89c32a9bddda1db82bf2b9f9c917a09b Mon Sep 17 00:00:00 2001 From: ohjonah Date: Mon, 28 Aug 2017 22:27:51 -0700 Subject: [PATCH 02/19] Adds Files --- src/action/category-actions.js | 0 src/component/category-form/category-form.js | 0 src/lib/store.js | 0 src/reducer/category-reducer.js | 0 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/action/category-actions.js create mode 100644 src/component/category-form/category-form.js create mode 100644 src/lib/store.js create mode 100644 src/reducer/category-reducer.js diff --git a/src/action/category-actions.js b/src/action/category-actions.js new file mode 100644 index 0000000..e69de29 diff --git a/src/component/category-form/category-form.js b/src/component/category-form/category-form.js new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/store.js b/src/lib/store.js new file mode 100644 index 0000000..e69de29 diff --git a/src/reducer/category-reducer.js b/src/reducer/category-reducer.js new file mode 100644 index 0000000..e69de29 From 6a463e6764a3a54e70e3de161c5f91faf08eb5ef Mon Sep 17 00:00:00 2001 From: ohjonah Date: Mon, 28 Aug 2017 22:28:39 -0700 Subject: [PATCH 03/19] Adds Webpack Config --- .dev.env | 0 webpack.config.js | 91 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 .dev.env diff --git a/.dev.env b/.dev.env new file mode 100644 index 0000000..e69de29 diff --git a/webpack.config.js b/webpack.config.js index e69de29..2821954 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -0,0 +1,91 @@ +'use strict'; + +require('dotenv').config({ path: `${__dirname}/.dev.env` }); +const production = process.env.NODE_ENV === 'production'; + +// AMD : Asynchronous Module Definition +const {DefinePlugin, EnvironmentPlugin} = require('webpack'); +const HtmlPlugin = require('html-webpack-plugin'); +const CleanPlugin = require('clean-webpack-plugin'); +const UglifyPlugin = require('uglifyjs-webpack-plugin'); +const ExtractPlugin = require('extract-text-webpack-plugin'); + +let plugins = [ + new EnvironmentPlugin(['NODE_ENV']), + new ExtractPlugin('bundle-[hash].css'), + new HtmlPlugin({ template: `${__dirname}/src/index.html` }), + new DefinePlugin({ __DEBUG__: JSON.stringify(!production) }) +]; + +if (production) { + plugins = plugins.concat([ + new CleanPlugin(), + new UglifyPlugin() + ]); +} + +module.exports = { + plugins, + entry: `${__dirname}/src/main.js`, + devServer: { + historyApiFallback: true + }, + devtool: production ? undefined : 'eval', + output: { + path: `${__dirname}/build`, + filename: 'bundle-[hash].js', + publicPath: process.env.CDN_URL + }, + module: { + rules: [ + { + test: /\.js$/, + exclude: /node_modules/, + loader: 'babel-loader' + }, + { + test: /\.scss$/, + loader: ExtractPlugin.extract([ + 'css-loader', + 'sass-loader']) + }, + { + test: /\.(woff|woff2|ttf|eot|glyph|\.svg)$/, + use: [ + { + loader: 'url-loader', + options: { + limit: 10000, + name: 'font/[name].[ext]' + } + } + ] + }, + { + test: /\.(jpg|jpeg|gif|png|tiff|svg)$/, + exclude: /\.glyph.svg/, + use: [ + { + loader: 'url-loader', + options: { + limit: 6000, + name: 'image/[name].[ext]' + } + } + ] + }, + { + test: /\.(mp3|aac|aiff|wav|flac|m4a|mp4|ogg)$/, + exclude: /\.glyph.svg/, + use: [ + { + loader: 'file-loader', + options: { name: 'audio/[name].[ext]'} + } + ] + } + ] + } +}; + + From 1b2561677799c3d5945816a8384582bf02ef96e8 Mon Sep 17 00:00:00 2001 From: ohjonah Date: Mon, 28 Aug 2017 23:12:05 -0700 Subject: [PATCH 04/19] Creates Store --- src/lib/store.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/store.js b/src/lib/store.js index e69de29..75700f6 100644 --- a/src/lib/store.js +++ b/src/lib/store.js @@ -0,0 +1,4 @@ +import {createStore} from 'redux'; +import reducer from '../reducer/category.js'; + +export default () => createStore(reducer); \ No newline at end of file From 4f9ee88006d4424ae541878e0bf8abff9e05d983 Mon Sep 17 00:00:00 2001 From: ohjonah Date: Tue, 29 Aug 2017 07:22:12 -0700 Subject: [PATCH 05/19] Adds Category Actions --- src/action/category-actions.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/action/category-actions.js b/src/action/category-actions.js index e69de29..59ab5d2 100644 --- a/src/action/category-actions.js +++ b/src/action/category-actions.js @@ -0,0 +1,23 @@ +import uuid from 'uuid/v1'; + +export const categoreCreate = (category) => { + category.id = uuid(); + category.timestamp = new Date(); + + return { + type: 'CATEGORY_CREATE', + payload: category + } +} + +export const categoryUpdate = (category) => ({ + type: 'CATEGORY_UPDATE', + payload: category +}) + +export const categoryDelete = (category) => ({ + type: 'CATEGORY_DELETE', + payload: category +}) + +export const categoryReset = () => ({ type: 'CATEGORY_RESET' }) \ No newline at end of file From 10f04640cf48fdb72c0e34106f8df5a1cbe14492 Mon Sep 17 00:00:00 2001 From: ohjonah Date: Tue, 29 Aug 2017 07:24:22 -0700 Subject: [PATCH 06/19] Adds main.js and index.html --- src/index.html | 10 ++++++++++ src/main.js | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/src/index.html b/src/index.html index e69de29..0605799 100644 --- a/src/index.html +++ b/src/index.html @@ -0,0 +1,10 @@ + + + + + Redux Budget App + + +
+ + \ No newline at end of file diff --git a/src/main.js b/src/main.js index e69de29..d209467 100644 --- a/src/main.js +++ b/src/main.js @@ -0,0 +1,5 @@ +import React from 'react'; +import ReactDom from 'react-dom'; +import App from './component/app'; + +ReactDom.render(, document.getElementById('root')); \ No newline at end of file From 939bb6b51c570abb7a5604d29eedcc390f70dde7 Mon Sep 17 00:00:00 2001 From: ohjonah Date: Tue, 29 Aug 2017 07:33:17 -0700 Subject: [PATCH 07/19] Adds Reducer --- src/reducer/category-reducer.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/reducer/category-reducer.js b/src/reducer/category-reducer.js index e69de29..901bdb1 100644 --- a/src/reducer/category-reducer.js +++ b/src/reducer/category-reducer.js @@ -0,0 +1,24 @@ +let initialstate = []; + +export default (state=initialState, action) => { + let {type, payload} = action; + + switch(type) { + case 'CATEGORY_CREATE': + return [...state, payload]; + + case 'CATEGORY_UPDATE': + return state.map(category => + category.id === payload.id ? payload : category); + + case 'CATEGORY_DELETE': + return state.filter(category => + category.id !== payload.id); + + case 'CATEGORY_RESET': + return initialState; + + default: + return state; + } +} \ No newline at end of file From b648c4aeec416f9ef647d361820779fa6e015ce8 Mon Sep 17 00:00:00 2001 From: ohjonah Date: Tue, 29 Aug 2017 07:56:51 -0700 Subject: [PATCH 08/19] Adds App Component --- src/component/app/index.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/component/app/index.js b/src/component/app/index.js index e69de29..a3b3fa0 100644 --- a/src/component/app/index.js +++ b/src/component/app/index.js @@ -0,0 +1,32 @@ +import React from 'react'; +import {Provider} from 'react-redux'; +import {BrowserRouter, Route} from 'react-router-dom'; +import createAppStore from '../../lib/store.js'; +import DashboardContainer from '../dashboard-container'; + +const store = createAppStore(); + +class App extends React.Component { + + componentDidMount() { + store.subscribe(() => { + console.log('__STATE__:', store.getState()) + }); + + store.dispatch({ type: null }); + } + + render() { + return ( +
+ + + + + +
+ ) + } +} + +export default App; \ No newline at end of file From b909cc45a360e85a98170f58cfa9efe5d8108050 Mon Sep 17 00:00:00 2001 From: ohjonah Date: Tue, 29 Aug 2017 08:04:32 -0700 Subject: [PATCH 09/19] Adds Dashboard Container --- src/component/dashboard-container/index.js | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/component/dashboard-container/index.js b/src/component/dashboard-container/index.js index e69de29..fb82e88 100644 --- a/src/component/dashboard-container/index.js +++ b/src/component/dashboard-container/index.js @@ -0,0 +1,47 @@ +import React from 'react'; +import {connect} from 'react-redux'; + +import { + categoryCreate, + categoryUpdate, + categoryDelete +} from '../../action/category-actions.js'; + +imort CategoryForm from '../category-form'; + +class DashboardContainer extends React.Component { + render() { + return ( +
+

Dashboard

+ + + + {this.props.categories.map((item) => +
+

{item.title}

+
+ )} +
+ ) + } +} + +const mapStateToProps = (state) => { + return { + categories: state + } +} + +const mapDispatchToProps = (dispatch, getState) => { + return { + categoryCreate: (category) => dispatch(categoryCreate(category)), + categoryUpdate: (category) => dispatch(categoryUpdate(category)), + categoryDelete:(category) => dispatch(categoryDelete(category)) + } +} + +export default connect(mapStateToProps, mapDispatchToProps)(DashboardContainer); \ No newline at end of file From 252bec58efbc46e1ce77f1cc887b4a9accf05a38 Mon Sep 17 00:00:00 2001 From: ohjonah Date: Tue, 29 Aug 2017 08:06:02 -0700 Subject: [PATCH 10/19] Fixes Dashboard Container Typo --- src/component/dashboard-container/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/component/dashboard-container/index.js b/src/component/dashboard-container/index.js index fb82e88..d538530 100644 --- a/src/component/dashboard-container/index.js +++ b/src/component/dashboard-container/index.js @@ -7,9 +7,14 @@ import { categoryDelete } from '../../action/category-actions.js'; -imort CategoryForm from '../category-form'; +import CategoryForm from '../category-form'; class DashboardContainer extends React.Component { + + componentDidMount() { + this.props.categoryCreate({ title: 'THIS IS A TEST' }); + } + render() { return (
From 19d59984b3c44d67355681021f8fddd0e6218961 Mon Sep 17 00:00:00 2001 From: ohjonah Date: Tue, 29 Aug 2017 08:11:00 -0700 Subject: [PATCH 11/19] Adds Category Form Comonent and Dependencies --- package.json | 27 ++++++++++++- src/component/category-form/category-form.js | 41 ++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 78b7961..7b61a17 100644 --- a/package.json +++ b/package.json @@ -17,5 +17,30 @@ "bugs": { "url": "https://github.com/ohjonah/26-react-redux/issues" }, - "homepage": "https://github.com/ohjonah/26-react-redux#readme" + "homepage": "https://github.com/ohjonah/26-react-redux#readme", + "dependencies": { + "babel-core": "^6.26.0", + "babel-loader": "^7.1.2", + "babel-plugin-transform-object-rest-spread": "^6.26.0", + "babel-preset-es2015": "^6.24.1", + "babel-preset-react": "^6.24.1", + "clean-webpack-plugin": "^0.1.16", + "css-loader": "^0.28.5", + "extract-text-webpack-plugin": "^3.0.0", + "file-loader": "^0.11.2", + "html-webpack-plugin": "^2.30.1", + "node-sass": "^4.5.3", + "react": "^15.6.1", + "react-dom": "^15.6.1", + "react-redux": "^5.0.6", + "react-router-dom": "^4.2.2", + "react-test-renderer": "^15.6.1", + "redux": "^3.7.2", + "sass-loader": "^6.0.6", + "uglifyjs-webpack-plugin": "^0.4.6", + "url-loader": "^0.5.9", + "uuid": "^3.1.0", + "webpack": "^3.5.5", + "webpack-dev-server": "^2.7.1" + } } diff --git a/src/component/category-form/category-form.js b/src/component/category-form/category-form.js index e69de29..329dbfa 100644 --- a/src/component/category-form/category-form.js +++ b/src/component/category-form/category-form.js @@ -0,0 +1,41 @@ +import React from 'react'; + +class CategoryForm extends React.Component { + constructor(props) { + super(props); + + this.state = { + title: props.category ? props.category.title : '' + } + + this.handleChange = this.handleChange.bind(this); + this.handleSubmit = this.handleSubmit.bind(this); + } + + handleChange(e) { + this.setState({ title: e.target.value }) + } + + handleSubmit(e) { + e.preventDefault(); + this.props.onComplete(Object.assign({}, this.state)) + } + + render() { + return ( +
+ + + +
+ ) + } +} + +export default CategoryForm; \ No newline at end of file From 62363be15fc5e077335d192004ee1c123edd1a31 Mon Sep 17 00:00:00 2001 From: ohjonah Date: Tue, 29 Aug 2017 08:22:59 -0700 Subject: [PATCH 12/19] TroubleShoots Lab Code --- .dev.env | 1 + package.json | 1 + src/action/category-actions.js | 2 +- src/component/category-form/{category-form.js => index.js} | 0 src/component/dashboard-container/index.js | 5 ++--- src/lib/store.js | 2 +- src/reducer/category-reducer.js | 2 +- 7 files changed, 7 insertions(+), 6 deletions(-) rename src/component/category-form/{category-form.js => index.js} (100%) diff --git a/.dev.env b/.dev.env index e69de29..dd660b8 100644 --- a/.dev.env +++ b/.dev.env @@ -0,0 +1 @@ +NODE_ENV='dev' \ No newline at end of file diff --git a/package.json b/package.json index 7b61a17..d4366ef 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "babel-preset-react": "^6.24.1", "clean-webpack-plugin": "^0.1.16", "css-loader": "^0.28.5", + "dotenv": "^4.0.0", "extract-text-webpack-plugin": "^3.0.0", "file-loader": "^0.11.2", "html-webpack-plugin": "^2.30.1", diff --git a/src/action/category-actions.js b/src/action/category-actions.js index 59ab5d2..2975cb7 100644 --- a/src/action/category-actions.js +++ b/src/action/category-actions.js @@ -1,6 +1,6 @@ import uuid from 'uuid/v1'; -export const categoreCreate = (category) => { +export const categoryCreate = (category) => { category.id = uuid(); category.timestamp = new Date(); diff --git a/src/component/category-form/category-form.js b/src/component/category-form/index.js similarity index 100% rename from src/component/category-form/category-form.js rename to src/component/category-form/index.js diff --git a/src/component/dashboard-container/index.js b/src/component/dashboard-container/index.js index d538530..14c3111 100644 --- a/src/component/dashboard-container/index.js +++ b/src/component/dashboard-container/index.js @@ -10,9 +10,8 @@ import { import CategoryForm from '../category-form'; class DashboardContainer extends React.Component { - componentDidMount() { - this.props.categoryCreate({ title: 'THIS IS A TEST' }); + this.props.categoryCreate({ title: 'test category' }); } render() { @@ -25,7 +24,7 @@ class DashboardContainer extends React.Component { onComplete={this.props.categoryCreate} /> - {this.props.categories.map((item) => + {this.props.categories.map((item) =>

{item.title}

diff --git a/src/lib/store.js b/src/lib/store.js index 75700f6..8fbd8f5 100644 --- a/src/lib/store.js +++ b/src/lib/store.js @@ -1,4 +1,4 @@ import {createStore} from 'redux'; -import reducer from '../reducer/category.js'; +import reducer from '../reducer/category-reducer.js'; export default () => createStore(reducer); \ No newline at end of file diff --git a/src/reducer/category-reducer.js b/src/reducer/category-reducer.js index 901bdb1..b11b220 100644 --- a/src/reducer/category-reducer.js +++ b/src/reducer/category-reducer.js @@ -1,4 +1,4 @@ -let initialstate = []; +let initialState = []; export default (state=initialState, action) => { let {type, payload} = action; From 01c11b17d1903ca0efbf6ae4978b7e87e28ef1b6 Mon Sep 17 00:00:00 2001 From: ohjonah Date: Tue, 29 Aug 2017 08:40:30 -0700 Subject: [PATCH 13/19] Adds Name and Budget Change Handlers --- src/component/category-form/index.js | 33 ++++++++++++++++------ src/component/dashboard-container/index.js | 10 +++++-- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/component/category-form/index.js b/src/component/category-form/index.js index 329dbfa..bedc41f 100644 --- a/src/component/category-form/index.js +++ b/src/component/category-form/index.js @@ -5,15 +5,25 @@ class CategoryForm extends React.Component { super(props); this.state = { - title: props.category ? props.category.title : '' + name: props.category ? props.category.name : '', + budget: props.category ? props.category.budget : 0 } - this.handleChange = this.handleChange.bind(this); + this.handleNameChange = this.handleNameChange.bind(this); + this.handleBudgetChange = this.handleBudgetChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); } - handleChange(e) { - this.setState({ title: e.target.value }) + handleNameChange(e) { + this.setState({ + name: e.target.value + }) + } + + handleBudgetChange(e) { + this.setState({ + budget: e.target.value + }) } handleSubmit(e) { @@ -25,11 +35,18 @@ class CategoryForm extends React.Component { return (
+ diff --git a/src/component/dashboard-container/index.js b/src/component/dashboard-container/index.js index 14c3111..806d41d 100644 --- a/src/component/dashboard-container/index.js +++ b/src/component/dashboard-container/index.js @@ -11,7 +11,10 @@ import CategoryForm from '../category-form'; class DashboardContainer extends React.Component { componentDidMount() { - this.props.categoryCreate({ title: 'test category' }); + this.props.categoryCreate({ + name: 'test category', + budget: 400 + }); } render() { @@ -20,13 +23,14 @@ class DashboardContainer extends React.Component {

Dashboard

{this.props.categories.map((item) =>
-

{item.title}

+

{item.name}

+

{item.budget}

)}
From f68be85d851401fc64f747639f9818a02fd82962 Mon Sep 17 00:00:00 2001 From: ohjonah Date: Tue, 29 Aug 2017 12:34:57 -0700 Subject: [PATCH 14/19] Adds Plugin to babelrc --- .babelrc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.babelrc b/.babelrc index facd180..47c9ace 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,4 @@ { - "presets": ["es2015", "react"] -} \ No newline at end of file + "presets": ["es2015", "react"], + "plugins": ["transform-object-rest-spread"] +} From 1975fb66e1489d7feaff3a797648983a82db041b Mon Sep 17 00:00:00 2001 From: ohjonah Date: Tue, 29 Aug 2017 13:50:42 -0700 Subject: [PATCH 15/19] Delete Action --- README.md | 2 +- src/component/category-form/index.js | 4 ++-- src/component/dashboard-container/index.js | 13 ++++--------- src/reducer/category-reducer.js | 20 ++++++++++---------- 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 2f36254..43f3009 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ * this reducer should support the following interactions * `CATEGORY_CREATE` * `CATEGORY_UPDATE` - * `CATEGORY_DESTORY` + * `CATEGORY_DESTROY` ###### action creators * create an action creator for each interaction supported by your category reducer diff --git a/src/component/category-form/index.js b/src/component/category-form/index.js index bedc41f..79db4be 100644 --- a/src/component/category-form/index.js +++ b/src/component/category-form/index.js @@ -28,7 +28,7 @@ class CategoryForm extends React.Component { handleSubmit(e) { e.preventDefault(); - this.props.onComplete(Object.assign({}, this.state)) + this.props.onComplete({...this.state}); } render() { @@ -44,7 +44,7 @@ class CategoryForm extends React.Component { diff --git a/src/component/dashboard-container/index.js b/src/component/dashboard-container/index.js index 806d41d..ba1c8e8 100644 --- a/src/component/dashboard-container/index.js +++ b/src/component/dashboard-container/index.js @@ -10,13 +10,6 @@ import { import CategoryForm from '../category-form'; class DashboardContainer extends React.Component { - componentDidMount() { - this.props.categoryCreate({ - name: 'test category', - budget: 400 - }); - } - render() { return (
@@ -29,8 +22,10 @@ class DashboardContainer extends React.Component { {this.props.categories.map((item) =>
-

{item.name}

-

{item.budget}

+

{item.name}

+

{item.budget}

+ +
)}
diff --git a/src/reducer/category-reducer.js b/src/reducer/category-reducer.js index b11b220..dfce5c8 100644 --- a/src/reducer/category-reducer.js +++ b/src/reducer/category-reducer.js @@ -7,18 +7,18 @@ export default (state=initialState, action) => { case 'CATEGORY_CREATE': return [...state, payload]; - case 'CATEGORY_UPDATE': - return state.map(category => - category.id === payload.id ? payload : category); + case 'CATEGORY_UPDATE': + return state.map(category => + category.id === payload.id ? payload : category); - case 'CATEGORY_DELETE': - return state.filter(category => - category.id !== payload.id); + case 'CATEGORY_DELETE': + return state.filter(category => + category.id !== payload.id); - case 'CATEGORY_RESET': - return initialState; + case 'CATEGORY_RESET': + return initialState; - default: - return state; + default: + return state; } } \ No newline at end of file From fce5451b18742c6d1d6da6b3e6f9db96476c2e0f Mon Sep 17 00:00:00 2001 From: ohjonah Date: Tue, 29 Aug 2017 14:08:44 -0700 Subject: [PATCH 16/19] TS Update Route --- src/component/category-form/index.js | 1 + src/component/dashboard-container/index.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/component/category-form/index.js b/src/component/category-form/index.js index 79db4be..191ce4f 100644 --- a/src/component/category-form/index.js +++ b/src/component/category-form/index.js @@ -41,6 +41,7 @@ class CategoryForm extends React.Component { value={this.state.name} onChange={this.handleNameChange} /> + {item.name}

{item.budget}

- - )} From 3bb3ae8666b0e7641fdcf1c8166e6ea75204dd93 Mon Sep 17 00:00:00 2001 From: ohjonah Date: Tue, 29 Aug 2017 15:03:40 -0700 Subject: [PATCH 18/19] TS Form Clear --- src/component/category-form/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/component/category-form/index.js b/src/component/category-form/index.js index 4402b2f..e37dfa3 100644 --- a/src/component/category-form/index.js +++ b/src/component/category-form/index.js @@ -30,7 +30,6 @@ class CategoryForm extends React.Component { handleSubmit(e) { e.preventDefault(); this.props.onComplete({...this.state}); - this.props. } render() { From dbe9d1b769da10a067d43ac3058d277ae2d5c3d6 Mon Sep 17 00:00:00 2001 From: ohjonah Date: Tue, 29 Aug 2017 15:57:24 -0700 Subject: [PATCH 19/19] Adds ONE LINE OF CODE --- src/component/dashboard-container/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/component/dashboard-container/index.js b/src/component/dashboard-container/index.js index 0a458c3..7522ab2 100644 --- a/src/component/dashboard-container/index.js +++ b/src/component/dashboard-container/index.js @@ -22,7 +22,8 @@ class DashboardContainer extends React.Component { {this.props.categories.map((item) =>
-

{item.name}

+

category: {item.name}

+

budget: {item.budget}