From ba3f3d10f50a8db8ac686291110457d8ba0fe8c2 Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 28 Aug 2017 14:47:47 -0700 Subject: [PATCH 01/13] Setup file scaffolding --- lab-eddie/.babelrc | 0 lab-eddie/.gitignore | 136 ++++++++++++++++++++++++++++++++++++ lab-eddie/package.json | 39 +++++++++++ lab-eddie/src/index.html | 0 lab-eddie/src/main.js | 0 lab-eddie/webpack.config.js | 0 6 files changed, 175 insertions(+) create mode 100644 lab-eddie/.babelrc create mode 100644 lab-eddie/.gitignore create mode 100644 lab-eddie/package.json create mode 100644 lab-eddie/src/index.html create mode 100644 lab-eddie/src/main.js create mode 100644 lab-eddie/webpack.config.js diff --git a/lab-eddie/.babelrc b/lab-eddie/.babelrc new file mode 100644 index 0000000..e69de29 diff --git a/lab-eddie/.gitignore b/lab-eddie/.gitignore new file mode 100644 index 0000000..345130c --- /dev/null +++ b/lab-eddie/.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/lab-eddie/package.json b/lab-eddie/package.json new file mode 100644 index 0000000..a749074 --- /dev/null +++ b/lab-eddie/package.json @@ -0,0 +1,39 @@ +{ + "name": "lab-eddie", + "version": "1.0.0", + "description": "", + "main": "webpack.confic.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "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", + "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/lab-eddie/src/index.html b/lab-eddie/src/index.html new file mode 100644 index 0000000..e69de29 diff --git a/lab-eddie/src/main.js b/lab-eddie/src/main.js new file mode 100644 index 0000000..e69de29 diff --git a/lab-eddie/webpack.config.js b/lab-eddie/webpack.config.js new file mode 100644 index 0000000..e69de29 From 874a863c3c57e69721f8e71022c860b04bcbd4a6 Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 28 Aug 2017 14:48:16 -0700 Subject: [PATCH 02/13] Deleted stock README.md file --- README.md | 83 ------------------------------------------------------- 1 file changed, 83 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index b22a2ec..0000000 --- a/README.md +++ /dev/null @@ -1,83 +0,0 @@ -![cf](https://i.imgur.com/7v5ASc8.png) 26: React & Redux -====== - -## Submission Instructions -* fork this repository & create a new branch for your work -* write all of your code in a directory named `lab-` + `` **e.g.** `lab-susan` -* push to your repository -* submit a pull request to this repository -* submit a link to your PR in canvas -* write a question and observation on canvas - -## Learning Objectives -* students will be able to use redux with react -* students will be able to design redux reducers for controlling application state -* students will learn to design action creator functions for working with redux - -## Requirements -#### Configuration -* `README.md` -* `.babelrc` -* `.gitignore` -* `package.json` -* `webpack.config.js` -* `src/**` -* `src/main.js` -* `src/style` -* `src/style/main.scss` - -#### Feature Tasks -##### Category -* in this application, a category should contain *(at least)* the following properties - * `id` - a unique identifier - * `timestamp` - a date from when the category was created - * `name` - a string that is the name of the category - * `budget` - a number that is the total amount of money in the category - -##### Redux -###### reducer -* create a category reducer in your your reducer directory -* this reducer should support the following interactions - * `CATEGORY_CREATE` - * `CATEGORY_UPDATE` - * `CATEGORY_DESTORY` - -###### action creators -* create an action creator for each interaction supported by your category reducer - -###### store -* in `lib/store.js` export a function that will return a new redux store from your category reducer - -##### Components -* create the following component and structure it according to the diagram below: -``` -Provider - App - BrowserRouter - Route / Dashboard - CategoryForm -- for creating categories - [Category Item] - CategoryForm -- for updating categories -``` - -###### App Component -* the App component should setup the `Provider` for the redux store and the `Router` - -###### Dashboard Component -* should be displayed on the `/` route -* should use react-redux's `connect` to map state and dispatch methods to props -* should display a `CategoryForm` for adding categories to the application state -* should display a `CategoryItem` for each category in the application state - -###### CategoryForm Component -* should expect an `onComplete` prop to be a function - * that function should be invoked with the `CategoryForm`'s state when the form is submitted -* should expect a `buttonText` prop to configure the submit button text -* should support an optional `category` prop that will initialize the state of the form - -###### CategoryItem Component -* should display the category's name and budget -* should display a delete button - * `onClick` the category should be removed from the application state -* should display a `CategoryForm` - * `onComplete` the form should update the component in the application state From 0f62e8738028cb9d41a6ac3731cbb1d8e161fb3d Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 28 Aug 2017 16:47:12 -0700 Subject: [PATCH 03/13] Wrote webpack file --- lab-eddie/webpack.config.js | 85 +++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/lab-eddie/webpack.config.js b/lab-eddie/webpack.config.js index e69de29..b92a038 100644 --- a/lab-eddie/webpack.config.js +++ b/lab-eddie/webpack.config.js @@ -0,0 +1,85 @@ +'use strict'; + +const HtmlPlugin = require('html-webpack-plugin'); +const ExtractPlugin = require('extract-text-webpack-plugin'); +const UglifyPlugin = require('uglify-webpack-plugin'); +const CleanPlugin = require('clean-webpack-plugin'); +const {DefinePlugin, EnvironmentPlugin} = require('webpack'); + +require('dotenv').config({path: `${__dirname}/,dev.env`}); +const production = process.env.NODE_ENV === 'production'; + +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.export = { + plugins, + devtool: production ? undefined : 'eval', + devServer: { + historyApiFallback: true + }, + entry: `${__dirname}/src/main.js`, + output: { + path: `${__dirname}/src/build`, + filename: 'bundle-[hash].js', + publicPath: process.env.CDN_URL + }, + module: { + rules: [ + { + test: /\.js$/m, + 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 52ff54ab45a3907230051774a0cd5b9a08ceff97 Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 28 Aug 2017 17:08:23 -0700 Subject: [PATCH 04/13] Ran npm run watch to test if server would start :D --- lab-eddie/.babelrc | 4 ++++ lab-eddie/package.json | 3 ++- lab-eddie/src/component/app/index.js | 15 +++++++++++++++ lab-eddie/src/index.html | 12 ++++++++++++ lab-eddie/src/main.js | 5 +++++ lab-eddie/webpack.config.js | 24 ++++++++++++------------ 6 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 lab-eddie/src/component/app/index.js diff --git a/lab-eddie/.babelrc b/lab-eddie/.babelrc index e69de29..52e3a27 100644 --- a/lab-eddie/.babelrc +++ b/lab-eddie/.babelrc @@ -0,0 +1,4 @@ +{ + "presets": ["es2015", "react"], + "plugins": "transform-object-rest-spread" +} diff --git a/lab-eddie/package.json b/lab-eddie/package.json index a749074..71f429e 100644 --- a/lab-eddie/package.json +++ b/lab-eddie/package.json @@ -4,7 +4,8 @@ "description": "", "main": "webpack.confic.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "build": "webpack", + "watch": "webpack-dev-server --inline --hot" }, "keywords": [], "author": "", diff --git a/lab-eddie/src/component/app/index.js b/lab-eddie/src/component/app/index.js new file mode 100644 index 0000000..a39ebc4 --- /dev/null +++ b/lab-eddie/src/component/app/index.js @@ -0,0 +1,15 @@ +import React from 'react'; + +class App extends React.Component { + constructor(props) { + super(props) + } + + render() { + return( +

Testing

+ ) + } +} + +export default App; diff --git a/lab-eddie/src/index.html b/lab-eddie/src/index.html index e69de29..8349dc7 100644 --- a/lab-eddie/src/index.html +++ b/lab-eddie/src/index.html @@ -0,0 +1,12 @@ + + + + + + + +
+ +
+ + diff --git a/lab-eddie/src/main.js b/lab-eddie/src/main.js index e69de29..d268bce 100644 --- a/lab-eddie/src/main.js +++ b/lab-eddie/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/lab-eddie/webpack.config.js b/lab-eddie/webpack.config.js index b92a038..9eb360f 100644 --- a/lab-eddie/webpack.config.js +++ b/lab-eddie/webpack.config.js @@ -1,45 +1,45 @@ 'use strict'; +const {DefinePlugin, EnvironmentPlugin} = require('webpack'); const HtmlPlugin = require('html-webpack-plugin'); -const ExtractPlugin = require('extract-text-webpack-plugin'); -const UglifyPlugin = require('uglify-webpack-plugin'); const CleanPlugin = require('clean-webpack-plugin'); -const {DefinePlugin, EnvironmentPlugin} = require('webpack'); +const UglifyPlugin = require('uglifyjs-webpack-plugin'); +const ExtractPlugin = require('extract-text-webpack-plugin'); -require('dotenv').config({path: `${__dirname}/,dev.env`}); +require('dotenv').config({ path: `${__dirname}/.dev.env` }); const production = process.env.NODE_ENV === 'production'; 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) { - plugins = plugins.concat([new CleanPlugin(), new UglifyPlugin()]); + plugins = plugins.concat([ new CleanPlugin(), new UglifyPlugin() ]); } -module.export = { +module.exports = { plugins, - devtool: production ? undefined : 'eval', + entry: `${__dirname}/src/main.js`, devServer: { historyApiFallback: true }, - entry: `${__dirname}/src/main.js`, + devtool: production ? undefined : 'eval', output: { - path: `${__dirname}/src/build`, + path: `${__dirname}/build`, filename: 'bundle-[hash].js', publicPath: process.env.CDN_URL }, module: { rules: [ { - test: /\.js$/m, + test: /\.js$/, exclude: /node_modules/, - loader: 'babel-loader', + loader: 'babel-loader' }, { test: /\.scss$/, From 818f75ff527abd6f84ca93a400725a6e774b36c9 Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 28 Aug 2017 17:27:50 -0700 Subject: [PATCH 05/13] Wrote cetegory action --- lab-eddie/src/action/category-action.js | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lab-eddie/src/action/category-action.js diff --git a/lab-eddie/src/action/category-action.js b/lab-eddie/src/action/category-action.js new file mode 100644 index 0000000..85cebf9 --- /dev/null +++ b/lab-eddie/src/action/category-action.js @@ -0,0 +1,28 @@ +'use strict'; + +import uuid from 'uuid/v1'; + +export const categoryCreate = (cat) => { + cat.id = uuid(); + cate.published = new Date(); + return { + type: 'CATEGORY_CREATE', + payload: cat + }; +}; + +export const categoryUpdate = (cat) => { + return { + type: 'CATEGORY_UPDATE', + payload: cat + }; +}; + +export const categoryDelete = (cat) => { + return { + type: 'CATEGORY_DELETE', + payload: cat + }; +}; + +export const categoryReset = () => ({type: 'CATEGORY_RESET'}); From 5b78413ffc5f08b38ecc331ccdb62ece3c7661a0 Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 28 Aug 2017 17:41:40 -0700 Subject: [PATCH 06/13] Added category reducer :D --- lab-eddie/src/index.html | 1 - lab-eddie/src/reducer/category.js | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 lab-eddie/src/reducer/category.js diff --git a/lab-eddie/src/index.html b/lab-eddie/src/index.html index 8349dc7..6333256 100644 --- a/lab-eddie/src/index.html +++ b/lab-eddie/src/index.html @@ -6,7 +6,6 @@
-
diff --git a/lab-eddie/src/reducer/category.js b/lab-eddie/src/reducer/category.js new file mode 100644 index 0000000..4ccc6db --- /dev/null +++ b/lab-eddie/src/reducer/category.js @@ -0,0 +1,22 @@ +'use strict'; + +let initState = []; + +export default (state=initState, action) => { + let {type, payload} = action; + + switch(type) { + case 'CATEGORY_CREATE': + return [...state, payload]; + case 'CATEGORY_UPDATE': + return state.map(cat => { + return cat.id === payload.id ? payload : cat; + }) + case 'CATEGORY_DELETE': + return state.filter(cat => cat.id !== payload.id); + case 'CATEGORY_RESET': + return initState; + default: + return state; + } +} From bd6b700997b80b036206d78786ddd40bdc4b2632 Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 28 Aug 2017 17:52:32 -0700 Subject: [PATCH 07/13] Added store :D --- lab-eddie/src/lib/store.js | 4 ++++ lab-eddie/src/lib/util.js | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 lab-eddie/src/lib/store.js create mode 100644 lab-eddie/src/lib/util.js diff --git a/lab-eddie/src/lib/store.js b/lab-eddie/src/lib/store.js new file mode 100644 index 0000000..e4d2844 --- /dev/null +++ b/lab-eddie/src/lib/store.js @@ -0,0 +1,4 @@ +import {createStore} from 'redux'; +import catReducer from '../reducer/category.js'; + +export default () => createStore(catReducer); diff --git a/lab-eddie/src/lib/util.js b/lab-eddie/src/lib/util.js new file mode 100644 index 0000000..1e8c160 --- /dev/null +++ b/lab-eddie/src/lib/util.js @@ -0,0 +1,6 @@ +'use strict'; + +export const renderIf = (test, component) => test ? component: undefined; +export const classToggle = options => { + Object.keys(options).filter(key => !!options[key]).join(' '); +} From ceaadf38c3070748ac7ff2a21d069485f39b4aef Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 28 Aug 2017 19:24:31 -0700 Subject: [PATCH 08/13] Finished my lab :DDDDDDDD --- .../src/component/category-body/index.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lab-eddie/src/component/category-body/index.js diff --git a/lab-eddie/src/component/category-body/index.js b/lab-eddie/src/component/category-body/index.js new file mode 100644 index 0000000..11ffe2d --- /dev/null +++ b/lab-eddie/src/component/category-body/index.js @@ -0,0 +1,23 @@ +import React from 'react'; + +class CategoryBody extends React.Component { + constructor(props) { + super(props); + this.onClick = this.onClick.bind(this); + } + + onClick() { + this.props.removeCat(this.props.category) + } + + render() { + return( +
  • +

    {this.props.category.title}

    + +
  • + ) + } +} + +export default CategoryBody; From 9da40f1c952008d0289d5635be59b46abeccab1a Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 28 Aug 2017 19:33:44 -0700 Subject: [PATCH 09/13] I lied. Forgot to add the budget --- lab-eddie/.dev.env | 1 + lab-eddie/src/action/category-action.js | 2 +- lab-eddie/src/component/app/index.js | 20 ++++++-- lab-eddie/src/component/cat-form/index.js | 50 ++++++++++++++++++ .../src/component/category-body/index.js | 1 + lab-eddie/src/component/dashboard/index.js | 51 +++++++++++++++++++ 6 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 lab-eddie/.dev.env create mode 100644 lab-eddie/src/component/cat-form/index.js create mode 100644 lab-eddie/src/component/dashboard/index.js diff --git a/lab-eddie/.dev.env b/lab-eddie/.dev.env new file mode 100644 index 0000000..13ea3e1 --- /dev/null +++ b/lab-eddie/.dev.env @@ -0,0 +1 @@ +NODE_ENV='dev' diff --git a/lab-eddie/src/action/category-action.js b/lab-eddie/src/action/category-action.js index 85cebf9..eb27da2 100644 --- a/lab-eddie/src/action/category-action.js +++ b/lab-eddie/src/action/category-action.js @@ -4,7 +4,7 @@ import uuid from 'uuid/v1'; export const categoryCreate = (cat) => { cat.id = uuid(); - cate.published = new Date(); + cat.published = new Date(); return { type: 'CATEGORY_CREATE', payload: cat diff --git a/lab-eddie/src/component/app/index.js b/lab-eddie/src/component/app/index.js index a39ebc4..96b3f72 100644 --- a/lab-eddie/src/component/app/index.js +++ b/lab-eddie/src/component/app/index.js @@ -1,13 +1,25 @@ import React from 'react'; +import {BrowserRouter, Route} from 'react-router-dom'; +import {Provider} from 'react-redux'; +import createStore from '../../lib/store.js'; +import Dashboard from '../dashboard'; + +let store = createStore(); class App extends React.Component { - constructor(props) { - super(props) - } + componentDidMount() { + store.subscribe(() => { + console.log('__STATE__', store.getState()) + }); + }; render() { return( -

    Testing

    + + + + + ) } } diff --git a/lab-eddie/src/component/cat-form/index.js b/lab-eddie/src/component/cat-form/index.js new file mode 100644 index 0000000..0e5e430 --- /dev/null +++ b/lab-eddie/src/component/cat-form/index.js @@ -0,0 +1,50 @@ +import React from 'react'; + +class CategoryForm extends React.Component { + constructor(props) { + super(props); + this.state = { + title: props.category ? props.category.title: '', + budget: props.category ? props.category.budget: 0, + }; + this.onChange = this.onChange.bind(this); + this.onSubmit = this.onSubmit.bind(this); + } + + onChange(e) { + this.setState({ + [e.target.name]: e.target.value + }); + }; + + onSubmit(e) { + e.preventDefault(); + this.props.addCat(Object.assign({}, this.state)); + } + + render() { + return ( +
    + + + +
    + ) + } +} + +export default CategoryForm; diff --git a/lab-eddie/src/component/category-body/index.js b/lab-eddie/src/component/category-body/index.js index 11ffe2d..0f5084b 100644 --- a/lab-eddie/src/component/category-body/index.js +++ b/lab-eddie/src/component/category-body/index.js @@ -14,6 +14,7 @@ class CategoryBody extends React.Component { return(
  • {this.props.category.title}

    +

    {`Budget: ${this.props.category.budget}`}

  • ) diff --git a/lab-eddie/src/component/dashboard/index.js b/lab-eddie/src/component/dashboard/index.js new file mode 100644 index 0000000..9079220 --- /dev/null +++ b/lab-eddie/src/component/dashboard/index.js @@ -0,0 +1,51 @@ +import React from 'react'; +import {connect} from 'react-redux'; +import CategoryForm from '../cat-form'; +import CategoryBody from '../category-body'; +import { + categoryCreate, + categoryUpdate, + categoryDelete +} from '../../action/category-action.js' + +class Dashboard extends React.Component { + render() { + return ( +
    +

    {'Eddie\'s Kick Ass Dashboard :D'}

    + +
      + {this.props.categories.map(cat => { + 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)(Dashboard) From 479365e409dc24db506356698bdd6e4c4fb52d4d Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 28 Aug 2017 19:46:18 -0700 Subject: [PATCH 10/13] Added budget and ability to update :D --- lab-eddie/src/component/cat-form/index.js | 9 ++++++--- .../src/component/category-body/index.js | 4 ++-- lab-eddie/src/component/dashboard/index.js | 20 ++++++++++++------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lab-eddie/src/component/cat-form/index.js b/lab-eddie/src/component/cat-form/index.js index 0e5e430..345d258 100644 --- a/lab-eddie/src/component/cat-form/index.js +++ b/lab-eddie/src/component/cat-form/index.js @@ -19,10 +19,13 @@ class CategoryForm extends React.Component { onSubmit(e) { e.preventDefault(); - this.props.addCat(Object.assign({}, this.state)); + let tempCat = Object.assign({}, this.state); + if(this.props.category) tempCat.id = this.props.category.id; + this.props.onComplete(tempCat); } render() { + let cat = this.props.category; return (
    diff --git a/lab-eddie/src/component/category-body/index.js b/lab-eddie/src/component/category-body/index.js index 0f5084b..79b5739 100644 --- a/lab-eddie/src/component/category-body/index.js +++ b/lab-eddie/src/component/category-body/index.js @@ -12,11 +12,11 @@ class CategoryBody extends React.Component { render() { return( -
  • +

    {this.props.category.title}

    {`Budget: ${this.props.category.budget}`}

    -
  • + ) } } diff --git a/lab-eddie/src/component/dashboard/index.js b/lab-eddie/src/component/dashboard/index.js index 9079220..3ec8c2e 100644 --- a/lab-eddie/src/component/dashboard/index.js +++ b/lab-eddie/src/component/dashboard/index.js @@ -14,18 +14,24 @@ class Dashboard extends React.Component {

    {'Eddie\'s Kick Ass Dashboard :D'}

      {this.props.categories.map(cat => { return ( - +
    • + + +
    • ); })}
    From ac07186e9cb16290118010fcf3fe96f4218bd659 Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 28 Aug 2017 19:54:49 -0700 Subject: [PATCH 11/13] Added config files and readme --- lab-eddie/.eslintignore | 5 +++++ lab-eddie/.eslintrc | 21 +++++++++++++++++++++ lab-eddie/README.md | 5 +++++ 3 files changed, 31 insertions(+) create mode 100644 lab-eddie/.eslintignore create mode 100644 lab-eddie/.eslintrc create mode 100644 lab-eddie/README.md diff --git a/lab-eddie/.eslintignore b/lab-eddie/.eslintignore new file mode 100644 index 0000000..05b1cf3 --- /dev/null +++ b/lab-eddie/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* diff --git a/lab-eddie/.eslintrc b/lab-eddie/.eslintrc new file mode 100644 index 0000000..8dc6807 --- /dev/null +++ b/lab-eddie/.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/lab-eddie/README.md b/lab-eddie/README.md new file mode 100644 index 0000000..778e90b --- /dev/null +++ b/lab-eddie/README.md @@ -0,0 +1,5 @@ +This is my redux + react app :D + +It allows you to add a category and set a budget :o +Once you add a category, you can remove it by clicking the button 'remove'. +If you want to update the category, You can enter new values in the form below and click update! From d6d5a289f97add4d023bbf4ff9ef05bddbf787a7 Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 28 Aug 2017 19:55:53 -0700 Subject: [PATCH 12/13] Forgot to save my dashboard component before pushing :( --- lab-eddie/src/component/dashboard/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lab-eddie/src/component/dashboard/index.js b/lab-eddie/src/component/dashboard/index.js index 3ec8c2e..82a0bf8 100644 --- a/lab-eddie/src/component/dashboard/index.js +++ b/lab-eddie/src/component/dashboard/index.js @@ -20,7 +20,7 @@ class Dashboard extends React.Component {
      {this.props.categories.map(cat => { return ( -
    • +
    • Date: Mon, 28 Aug 2017 20:03:18 -0700 Subject: [PATCH 13/13] Changed budget to an integer instead of a string --- lab-eddie/src/component/cat-form/index.js | 3 ++- lab-eddie/src/component/dashboard/index.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lab-eddie/src/component/cat-form/index.js b/lab-eddie/src/component/cat-form/index.js index 345d258..2136a6b 100644 --- a/lab-eddie/src/component/cat-form/index.js +++ b/lab-eddie/src/component/cat-form/index.js @@ -20,6 +20,7 @@ class CategoryForm extends React.Component { onSubmit(e) { e.preventDefault(); let tempCat = Object.assign({}, this.state); + tempCat.budget = parseInt(tempCat.budget); if(this.props.category) tempCat.id = this.props.category.id; this.props.onComplete(tempCat); } @@ -37,7 +38,7 @@ class CategoryForm extends React.Component { placeholder={cat ? cat.title :'Enter Category'} /> {this.props.categories.map(cat => { return ( -
    • +