From 821d7f87085e7363fc8fe68664b33fbde1811d87 Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Mon, 28 Aug 2017 13:30:27 -0700 Subject: [PATCH 1/9] initial commit --- .babelrc | 4 ++ .eslintignore | 5 ++ .eslintrc | 21 +++++++ .gitignore | 136 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 48 ++++++++++++++++ webpack.config.js | 14 +++++ 6 files changed, 228 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 webpack.config.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..59e5db6 --- /dev/null +++ b/.babelrc @@ -0,0 +1,4 @@ +{ + "presets": ["es2015"], + "presets": ["react"] +} diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..05b1cf3 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..8dc6807 --- /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" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..345130c --- /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 diff --git a/package.json b/package.json new file mode 100644 index 0000000..53b5264 --- /dev/null +++ b/package.json @@ -0,0 +1,48 @@ +{ + "name": "26-react-redux", + "version": "1.0.0", + "description": "![cf](https://i.imgur.com/7v5ASc8.png) 26: React & Redux ======", + "main": "index.js", + "scripts": { + "build": "webpack", + "watch": "webpack-dev-server --inline --hot" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/codefellows-javascript-401d17/26-react-redux.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/codefellows-javascript-401d17/26-react-redux/issues" + }, + "homepage": "https://github.com/codefellows-javascript-401d17/26-react-redux#readme", + "dependencies": { + "babel-core": "^6.26.0", + "babel-loader": "^7.1.2", + "babel-plugin-react": "^1.0.0", + "babel-plugin-transform-object-rest-spread": "^6.26.0", + "babel-preset-es2015": "^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", + "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", + "superagent": "^3.6.0", + "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/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..dd8da27 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,14 @@ +'use strict'; + +require('dotenv').config({ path: `${__dirname}/.dev.env` }); +const production = process.env.NODE_ENV === 'production'; + +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']), +] From 4f2987833e152f759c50304ce1528318a0e4816e Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Mon, 28 Aug 2017 14:06:17 -0700 Subject: [PATCH 2/9] finished webpack.config.js and added folders and index.html main.js --- .babelrc | 4 +-- src/index.html | 0 src/main.js | 0 webpack.config.js | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 src/index.html create mode 100644 src/main.js diff --git a/.babelrc b/.babelrc index 59e5db6..47c9ace 100644 --- a/.babelrc +++ b/.babelrc @@ -1,4 +1,4 @@ { - "presets": ["es2015"], - "presets": ["react"] + "presets": ["es2015", "react"], + "plugins": ["transform-object-rest-spread"] } 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 index dd8da27..f094ada 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -11,4 +11,66 @@ 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) { + plugin = plugin.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]' + } + } + ] + } + ] + } +} From b61b0645e592820543fd57446dce7371e9de0cec Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Mon, 28 Aug 2017 14:28:37 -0700 Subject: [PATCH 3/9] finished index.html main.js action and reducer --- src/action/category-actions.js | 20 ++++++++++++++++++++ src/index.html | 10 ++++++++++ src/main.js | 5 +++++ src/reducer/category.js | 17 +++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 src/action/category-actions.js create mode 100644 src/reducer/category.js diff --git a/src/action/category-actions.js b/src/action/category-actions.js new file mode 100644 index 0000000..bdd6a04 --- /dev/null +++ b/src/action/category-actions.js @@ -0,0 +1,20 @@ +import uuid from 'uuid/v1'; + +export const categoryCreate = (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 +}) diff --git a/src/index.html b/src/index.html index e69de29..9069766 100644 --- a/src/index.html +++ b/src/index.html @@ -0,0 +1,10 @@ + + + + + + + +
+ + diff --git a/src/main.js b/src/main.js index e69de29..a85bc03 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')) diff --git a/src/reducer/category.js b/src/reducer/category.js new file mode 100644 index 0000000..4870e61 --- /dev/null +++ b/src/reducer/category.js @@ -0,0 +1,17 @@ +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) + default: + return state + } +} From 267c7efb958756267928ba1e5ebc1e4e6e1cb6f8 Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Mon, 28 Aug 2017 14:48:49 -0700 Subject: [PATCH 4/9] added store.js and util.js --- src/lib/store.js | 4 ++++ src/lib/util.js | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 src/lib/store.js create mode 100644 src/lib/util.js diff --git a/src/lib/store.js b/src/lib/store.js new file mode 100644 index 0000000..6fe70e3 --- /dev/null +++ b/src/lib/store.js @@ -0,0 +1,4 @@ +import {createStore} from 'redux'; +import reducer from '../reducer/category.js'; + +export default () => createStore(reducer) diff --git a/src/lib/util.js b/src/lib/util.js new file mode 100644 index 0000000..32d047b --- /dev/null +++ b/src/lib/util.js @@ -0,0 +1,4 @@ +export const renderif = (test, component) => test ? component : undefined; + +export const classToggler = (options) => + object.keys(options).filter(key => !!options[key]).join(' ') From 41f5be037ee5e3db6cb721afc3c9a5e2273154db Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Mon, 28 Aug 2017 16:23:33 -0700 Subject: [PATCH 5/9] added some components --- src/component/app/index.js | 31 +++++++++++++ src/component/category-form/index.js | 51 ++++++++++++++++++++++ src/component/category-item/index.js | 0 src/component/dashboard-container/index.js | 45 +++++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 src/component/app/index.js create mode 100644 src/component/category-form/index.js create mode 100644 src/component/category-item/index.js create mode 100644 src/component/dashboard-container/index.js diff --git a/src/component/app/index.js b/src/component/app/index.js new file mode 100644 index 0000000..5d731f6 --- /dev/null +++ b/src/component/app/index.js @@ -0,0 +1,31 @@ +import React from 'react'; +import {Provider} from 'react-redux'; +import {BrowserRouter, Route} from ' react-router-dom'; +import createAppStore from '../../lib/store'; +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; diff --git a/src/component/category-form/index.js b/src/component/category-form/index.js new file mode 100644 index 0000000..e7a30e6 --- /dev/null +++ b/src/component/category-form/index.js @@ -0,0 +1,51 @@ +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({ + [e.target.name]: e.target.value + }) + } + + handleSubmit(e) { + e.preventDefault(); + this.props.onComplete(Object.assign({}, this.state)); + } + + render() { + return ( +
+ + + + + +
+ ) + } +} + +export default CategoryForm; diff --git a/src/component/category-item/index.js b/src/component/category-item/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..3721e03 --- /dev/null +++ b/src/component/dashboard-container/index.js @@ -0,0 +1,45 @@ +import React from 'react'; +import {connect} from 'react-redux'; +import {categoryCreate, categoryUpdate, categoryDelete} from '../../action/category-actions.js'; +import CategoryForm from '../category-form'; +import CategoryItem from '../category-item'; + +class DashboardContainer extends React.Component { + render() { + return( +
+

Dashboard

+ + +
    + {this.props.categories.map((item, i) => { + return ( + + ) + )} +
+
+ ) + } +} + + +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); From 1fbc4522ed14d708ec41f409668f562d41e2a022 Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Mon, 28 Aug 2017 17:51:50 -0700 Subject: [PATCH 6/9] got the state in my update now --- package.json | 2 +- src/component/app/index.js | 5 +++-- src/component/category-form/index.js | 3 ++- src/component/category-item/index.js | 24 ++++++++++++++++++++++ src/component/dashboard-container/index.js | 21 +++++++++++-------- src/reducer/category.js | 8 ++++++-- webpack.config.js | 21 +++++++++++++------ 7 files changed, 64 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 53b5264..8088d89 100644 --- a/package.json +++ b/package.json @@ -21,9 +21,9 @@ "dependencies": { "babel-core": "^6.26.0", "babel-loader": "^7.1.2", - "babel-plugin-react": "^1.0.0", "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", "dotenv": "^4.0.0", diff --git a/src/component/app/index.js b/src/component/app/index.js index 5d731f6..3ec8ea6 100644 --- a/src/component/app/index.js +++ b/src/component/app/index.js @@ -1,15 +1,16 @@ import React from 'react'; import {Provider} from 'react-redux'; -import {BrowserRouter, Route} from ' react-router-dom'; +import {BrowserRouter, Route} from 'react-router-dom'; import createAppStore from '../../lib/store'; import DashboardContainer from '../dashboard-container'; const store = createAppStore(); class App extends React.Component { + componentDidMount() { store.subscribe(() =>{ - console.log('*___STATE___*', store.getState() + console.log('*___STATE___*', store.getState()) }); store.dispatch({ type: null }); diff --git a/src/component/category-form/index.js b/src/component/category-form/index.js index e7a30e6..7b8337e 100644 --- a/src/component/category-form/index.js +++ b/src/component/category-form/index.js @@ -5,7 +5,8 @@ class CategoryForm extends React.Component { super(props); this.state = { - title: props.category ? props.category.title : '' + title: props.category ? props.category.title : '', + budget: props.category ? props.category.budget : '' } this.handleChange = this.handleChange.bind(this); diff --git a/src/component/category-item/index.js b/src/component/category-item/index.js index e69de29..14219ae 100644 --- a/src/component/category-item/index.js +++ b/src/component/category-item/index.js @@ -0,0 +1,24 @@ +import React from 'react'; +import CategoryForm from '../category-form'; +import {categoryCreate, categoryUpdate, categoryDelete} from '../../action/category-actions.js'; + + +class CategoryItem extends React.Component { + render() { + return( +
  • +

    {this.props.category.title}

    +

    {this.props.category.budget}

    + + +
  • + ) + } + +} + +export default CategoryItem diff --git a/src/component/dashboard-container/index.js b/src/component/dashboard-container/index.js index 3721e03..080614c 100644 --- a/src/component/dashboard-container/index.js +++ b/src/component/dashboard-container/index.js @@ -14,20 +14,25 @@ class DashboardContainer extends React.Component { buttonText='create category' onComplete={this.props.categoryCreate} />
      - {this.props.categories.map((item, i) => { + {this.props.categories.map((item) => { return ( - ) - )} -
    - - ) - } + } + )} + + + ) +} } + const mapStateToProps = (state) => { return { categories: state diff --git a/src/reducer/category.js b/src/reducer/category.js index 4870e61..839f208 100644 --- a/src/reducer/category.js +++ b/src/reducer/category.js @@ -7,9 +7,13 @@ export default (state=initialState, action) => { case 'CATEGORY_CREATE': return [...state, payload] case 'CATEGORY_UPDATE': - return state.map(category => - category.id === payload.id ? payload : category) + return state.map(category => { + console.log(category); + console.log(payload); + category.id === payload.id ? payload : category + }) case 'CATEGORY_DELETE': + console.log('delete'); return state.filter(category => category.id !== payload.id) default: return state diff --git a/webpack.config.js b/webpack.config.js index f094ada..9d3f943 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -12,14 +12,14 @@ 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 HtmlPlugin({ template: `${__dirname}/src/index.html` }), new DefinePlugin({ __DEBUG__: JSON.stringify(!production) }) ] -if(production) { - plugin = plugin.concat([ new CleanPlugin(), new UglifyPlugin()]) +if (production) { + plugins = plugins.concat([ new CleanPlugin(), new UglifyPlugin() ]); } module.exports = { @@ -30,11 +30,10 @@ module.exports = { }, devtool: production ? undefined : 'eval', output: { - path: `${-__dirname}/build`, + path: `${__dirname}/build`, filename: 'bundle-[hash].js', publicPath: process.env.CDN_URL }, - module: { rules: [ { @@ -48,7 +47,7 @@ module.exports = { }, { test: /\.(woff|woff2|ttf|eot|glyph|\.svg)$/, - use:[ + use: [ { loader: 'url-loader', options: { @@ -70,6 +69,16 @@ module.exports = { } } ] + }, + { + test: /\.(mp3|aac|aiff|wav|flac|m4a|mp4|ogg)$/, + exclude: /\.glyph.svg/, + use: [ + { + loader: 'file-loader', + options: { name: 'audio/[name].[ext]' } + } + ] } ] } From aa390517c993c7c221cb127e95a959678c160360 Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Mon, 28 Aug 2017 18:25:56 -0700 Subject: [PATCH 7/9] got delete to work --- src/component/category-item/index.js | 2 +- src/component/dashboard-container/index.js | 6 +++--- src/reducer/category.js | 7 ++----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/component/category-item/index.js b/src/component/category-item/index.js index 14219ae..f4f6b67 100644 --- a/src/component/category-item/index.js +++ b/src/component/category-item/index.js @@ -9,7 +9,7 @@ class CategoryItem extends React.Component {
  • {this.props.category.title}

    {this.props.category.budget}

    - + ) } diff --git a/src/reducer/category.js b/src/reducer/category.js index 839f208..be1efdc 100644 --- a/src/reducer/category.js +++ b/src/reducer/category.js @@ -7,11 +7,8 @@ export default (state=initialState, action) => { case 'CATEGORY_CREATE': return [...state, payload] case 'CATEGORY_UPDATE': - return state.map(category => { - console.log(category); - console.log(payload); - category.id === payload.id ? payload : category - }) + console.log('update'); + return state.map(category => category.id === payload.id ? payload : category) case 'CATEGORY_DELETE': console.log('delete'); return state.filter(category => category.id !== payload.id) From 1ae63028c5a3ac5d4d0b4e5246a9ae4997e461e2 Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Mon, 28 Aug 2017 19:31:53 -0700 Subject: [PATCH 8/9] update not working --- src/component/category-form/index.js | 19 +++++++++++++++---- src/component/category-item/index.js | 3 +-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/component/category-form/index.js b/src/component/category-form/index.js index 7b8337e..6708730 100644 --- a/src/component/category-form/index.js +++ b/src/component/category-form/index.js @@ -14,10 +14,21 @@ class CategoryForm extends React.Component { } handleChange(e) { - this.setState({ - [e.target.name]: e.target.value - }) - } + let {name, value, type} = e.target; + if (type === 'number') { + try { + this.setState({ + [name]: parseInt(value), + }); + } catch (err) { + console.error(err); + } + } else { + this.setState({ + [name]: value, + }); + } + } handleSubmit(e) { e.preventDefault(); diff --git a/src/component/category-item/index.js b/src/component/category-item/index.js index f4f6b67..4c5564f 100644 --- a/src/component/category-item/index.js +++ b/src/component/category-item/index.js @@ -1,6 +1,5 @@ import React from 'react'; import CategoryForm from '../category-form'; -import {categoryCreate, categoryUpdate, categoryDelete} from '../../action/category-actions.js'; class CategoryItem extends React.Component { @@ -11,8 +10,8 @@ class CategoryItem extends React.Component {

    {this.props.category.budget}

  • From 97a15080b471238a2723ff96b7dd1de4334dc2c1 Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Mon, 28 Aug 2017 20:28:37 -0700 Subject: [PATCH 9/9] finally finished --- src/component/category-form/index.js | 30 ++++++++++++---------- src/component/category-item/index.js | 1 - src/component/dashboard-container/index.js | 15 ++++++----- src/reducer/category.js | 5 +++- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/component/category-form/index.js b/src/component/category-form/index.js index 6708730..2ce4028 100644 --- a/src/component/category-form/index.js +++ b/src/component/category-form/index.js @@ -14,25 +14,27 @@ class CategoryForm extends React.Component { } handleChange(e) { - let {name, value, type} = e.target; - if (type === 'number') { - try { - this.setState({ - [name]: parseInt(value), - }); - } catch (err) { - console.error(err); - } - } else { + let {name, value, type} = e.target; + if (type === 'number') { + try { this.setState({ - [name]: value, + [name]: parseInt(value), }); + } catch (err) { + console.error(err); } + } else { + this.setState({ + [name]: value, + }); } + } handleSubmit(e) { e.preventDefault(); - this.props.onComplete(Object.assign({}, this.state)); + let category = Object.assign({}, this.state); + if(this.props.category) category.id = this.props.category.id; + this.props.onComplete(category); } render() { @@ -44,7 +46,7 @@ class CategoryForm extends React.Component { placeholder='title' value={this.state.title} onChange={this.handleChange} - /> + /> + /> diff --git a/src/component/category-item/index.js b/src/component/category-item/index.js index 4c5564f..6bc4138 100644 --- a/src/component/category-item/index.js +++ b/src/component/category-item/index.js @@ -17,7 +17,6 @@ class CategoryItem extends React.Component { ) } - } export default CategoryItem diff --git a/src/component/dashboard-container/index.js b/src/component/dashboard-container/index.js index dbdab2c..14aa2b7 100644 --- a/src/component/dashboard-container/index.js +++ b/src/component/dashboard-container/index.js @@ -15,6 +15,7 @@ class DashboardContainer extends React.Component { onComplete={this.props.categoryCreate} />
      {this.props.categories.map((item) => { + console.log(item); return ( - ) - } - )} -
    - - ) -} + ) + } + )} + + + ) + } } diff --git a/src/reducer/category.js b/src/reducer/category.js index be1efdc..2c1cee1 100644 --- a/src/reducer/category.js +++ b/src/reducer/category.js @@ -5,11 +5,14 @@ export default (state=initialState, action) => { switch(type) { case 'CATEGORY_CREATE': + console.log('CREATEPAYLOAD',payload); return [...state, payload] case 'CATEGORY_UPDATE': - console.log('update'); + console.log('UPDATEPAYLOAD',payload); return state.map(category => category.id === payload.id ? payload : category) case 'CATEGORY_DELETE': + console.log(payload); + console.log('delete'); return state.filter(category => category.id !== payload.id) default: