From 66fc4989d4acc93f6696c1488cff568ed87d8686 Mon Sep 17 00:00:00 2001 From: Your NameJohnScarrow Date: Thu, 24 Aug 2017 17:54:47 -0700 Subject: [PATCH] trying to get the update to work --- .babelrc | 3 + .eslintignore | 5 + .eslintrc | 21 ++++ .gitignore | 136 ++++++++++++++++++++++++ package.json | 30 ++++++ src/component/body-comp/_body-comp.scss | 3 + src/component/body-comp/index.js | 61 +++++++++++ src/component/create-note-comp/index.js | 47 ++++++++ src/component/modal/index.js | 15 +++ src/component/note-populate/index.js | 36 +++++++ src/component/note-update/index.js | 47 ++++++++ src/index.html | 9 ++ src/main.js | 40 +++++++ src/style/main.scss | 3 + webpack.config.js | 34 ++++++ 15 files changed, 490 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/body-comp/_body-comp.scss create mode 100644 src/component/body-comp/index.js create mode 100644 src/component/create-note-comp/index.js create mode 100644 src/component/modal/index.js create mode 100644 src/component/note-populate/index.js create mode 100644 src/component/note-update/index.js create mode 100644 src/index.html create mode 100644 src/main.js create mode 100644 src/style/main.scss create mode 100644 webpack.config.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..86c445f --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["es2015", "react"] +} 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..b0c0da4 --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "name": "24-components-composition", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "build": "webpack", + "watch": "webpack-dev-server --inline --hot" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "babel-core": "^6.26.0", + "babel-loader": "^7.1.2", + "babel-preset-es2015": "^6.24.1", + "babel-preset-react": "^6.24.1", + "css-loader": "^0.28.5", + "extract-text-webpack-plugin": "^3.0.0", + "html-webpack-plugin": "^2.30.1", + "node-sass": "^4.5.3", + "react": "^15.6.1", + "react-dom": "^15.6.1", + "react-router-dom": "^4.1.2", + "sass-loader": "^6.0.6", + "uuid": "^3.1.0", + "webpack": "^3.5.5", + "webpack-dev-server": "^2.7.1" + } +} diff --git a/src/component/body-comp/_body-comp.scss b/src/component/body-comp/_body-comp.scss new file mode 100644 index 0000000..f9bc286 --- /dev/null +++ b/src/component/body-comp/_body-comp.scss @@ -0,0 +1,3 @@ +.body-conp { + border: solid 1em blue; +} diff --git a/src/component/body-comp/index.js b/src/component/body-comp/index.js new file mode 100644 index 0000000..edc8e7c --- /dev/null +++ b/src/component/body-comp/index.js @@ -0,0 +1,61 @@ +import './_body-comp.scss'; +import React from 'react'; +import uuid from 'uuid/v1'; + +import NoteCreate from '../create-note-comp'; +import NotePopulate from '../note-populate'; +import NoteUpdate from '../note-update'; + +class BodyContainer extends React.Component { + constructor(props) { + super(props); + this.noteCreate = this.noteCreate.bind(this); + this.noteRemove = this.noteRemove.bind(this); + this.noteUpdate = this.noteUpdate.bind(this); + } + + noteCreate(note) { + note.id = uuid(); + this.props.app.setState(state => ({ + notes: [...state.notes, note] + })); + } + // noteUpdate(note){ + // let {app} = this.props; + // app.setState(prevState => ({ + // notes: prevState.notes.id = item.id + // })); + // } + noteRemove(note) { + let {app} = this.props; + app.setState(prevState => ({ + notes: prevState.notes.filter((item) => { + return item.id !== note.id; + }) + })); + } + noteUpdate(note){ + let {app} = this.props; + app.setState(prevState => ({ + notes: prevState.notes.map((item) => { + return item.id === note.id ? note : item; + }) + })); + } + + render() { + let {app} = this.props; + return ( +
+ + + +
+ ) + } +} + +export default BodyContainer; diff --git a/src/component/create-note-comp/index.js b/src/component/create-note-comp/index.js new file mode 100644 index 0000000..b077838 --- /dev/null +++ b/src/component/create-note-comp/index.js @@ -0,0 +1,47 @@ +import React from 'react'; + +class NoteCreateForm extends React.Component { + constructor(props) { + super(props); + + let title = props.expense ? props.expense.title : ''; + let price = props.expense ? props.expense.price : 0; + + this.state = { title, price }; + 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.noteCreate(this.state); + } + render() { + return( +
+ + + + +
+ ) + } + } + +export default NoteCreateForm; diff --git a/src/component/modal/index.js b/src/component/modal/index.js new file mode 100644 index 0000000..36c0e18 --- /dev/null +++ b/src/component/modal/index.js @@ -0,0 +1,15 @@ +import React from 'react'; + +class Modal extends React.Component{ + render(){ + return( +
+ +
+ {this.prop.children} +
+
+ ) + } +} +export default Modal; diff --git a/src/component/note-populate/index.js b/src/component/note-populate/index.js new file mode 100644 index 0000000..f522e39 --- /dev/null +++ b/src/component/note-populate/index.js @@ -0,0 +1,36 @@ +import React from 'react'; + +import CreateNoteComp from '../create-note-comp'; +import UpdateNote from '../note-update'; + +class NotePopulate extends React.Component { + render(){ + let {app} = this.props; + console.log('populate:', this.props) + return( +
+ +
+ ) + } +} +export default NotePopulate; diff --git a/src/component/note-update/index.js b/src/component/note-update/index.js new file mode 100644 index 0000000..1030134 --- /dev/null +++ b/src/component/note-update/index.js @@ -0,0 +1,47 @@ +import React from 'react'; + +class UpdateNote extends React.Component{ +constructor(props){ + super(props); + let title = props.expense ? props.expense.title : ''; + let price = props.expense ? props.expense.price : 0; + + this.state = { title, price }; + this.handleUpdateChange = this.handleUpdateChange.bind(this); + this.handleUpdateSubmit = this.handleUpdateSubmit.bind(this); + } + handleUpdateChange(e) { + this.setState({ + [e.target.name]: e.target.value + }) + } + handleUpdateSubmit(e) { + e.preventDefault(); + this.props.noteUpdate(this.state); + } + render() { + console.log('update:', this.props); + return( +
+ + + + +
+ ) + } +} + +export default UpdateNote; diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..85c2fd7 --- /dev/null +++ b/src/index.html @@ -0,0 +1,9 @@ + + + + Note Tracking App + + +
+ + diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..b573b33 --- /dev/null +++ b/src/main.js @@ -0,0 +1,40 @@ +import './style/main.scss'; + +import React from 'react'; +import ReactDom from 'react-dom'; +import {BrowserRouter, Route} from 'react-router-dom'; + +import BodyContainer from './component/body-comp/'; + +class App extends React.Component { + constructor(props) { + super(props); + this.state = { + totalNotes: 0, + notes: [] + } + this.getApp = this.getApp.bind(this); + } + getApp() { + return { + state: this.state, + setState: this.setState.bind(this) + } + } + + componentDidUpdate() { + console.log('__STATE__', this.state); + } + render() { + return( +
+ +
+ } /> +
+
+
+ ) + } +} +ReactDom.render(, document.getElementById('root')); diff --git a/src/style/main.scss b/src/style/main.scss new file mode 100644 index 0000000..d32cbcf --- /dev/null +++ b/src/style/main.scss @@ -0,0 +1,3 @@ +body{ + background-color: orange; +} diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..9801c9d --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,34 @@ +'use strict'; + +const HtmlPlugin = require('html-webpack-plugin'); +const ExtractPlugin = require('extract-text-webpack-plugin'); + +module.exports = { + devtool: 'cheap-module-eval-source-map', + devServer: { + historyApiFallback:true + }, + entry: `${__dirname}/src/main.js`, + output: { + path: `${__dirname}/build`, + publicPath: '/', + filename: 'bundle-[hash].js' + }, + plugins:[ + new HtmlPlugin({template: `${__dirname}/src/index.html`}), + new ExtractPlugin('bundle-[hash].css') + ], + module:{ + rules:[ + { + test: /\.js$/, + exclude:/node_modules/, + loader: 'babel-loader' + }, + { + test:/\.scss$/, + loader:ExtractPlugin.extract(['css-loader', 'sass-loader']) + } + ] + } +};