From 546edfaf8c6e42616c461babdc9562c92c6cb1b6 Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Thu, 24 Aug 2017 14:20:18 -0700 Subject: [PATCH 01/18] initiial commit, added a function for update --- .babelrc | 4 + .eslintignore | 5 + .eslintrc | 21 ++++ .gitignore | 136 +++++++++++++++++++++ package.json | 38 ++++++ src/component/dashboard-container/index.js | 28 +++++ src/component/note-create-form/index.js | 50 ++++++++ src/component/note-item/index.js | 26 ++++ src/component/note-list/index.js | 25 ++++ src/index.html | 10 ++ src/main.js | 58 +++++++++ src/style/main.scss | 0 webpack.config.js | 34 ++++++ 13 files changed, 435 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/dashboard-container/index.js create mode 100644 src/component/note-create-form/index.js create mode 100644 src/component/note-item/index.js create mode 100644 src/component/note-list/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..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..52f819d --- /dev/null +++ b/package.json @@ -0,0 +1,38 @@ +{ + "name": "23-components_and_routing", + "version": "1.0.0", + "description": "![cf](https://i.imgur.com/7v5ASc8.png) 23: Components and Routing ======", + "main": "index.js", + "scripts": { + "build": "webpack", + "watch": "webpack-dev-server --inline --hot" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Jamesbillard12/23-components_and_routing.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/Jamesbillard12/23-components_and_routing/issues" + }, + "homepage": "https://github.com/Jamesbillard12/23-components_and_routing#readme", + "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/dashboard-container/index.js b/src/component/dashboard-container/index.js new file mode 100644 index 0000000..1173424 --- /dev/null +++ b/src/component/dashboard-container/index.js @@ -0,0 +1,28 @@ +import React from 'react'; +import uuid from 'uuid/v1'; + +import NoteCreateForm from '../note-create-form'; + +class DashboardContainer extends React.Component { + constructor(props) { + super(props) + this.noteCreate = this.noteCreate.bind(this); + } + + noteCreate(note) { + note.id = uuid(); + this.props.getNote.setState(state => ({ + notesArr: [...state.notesArr, note] + })); + } + + render() { + return ( +
+ +
+ ) + } +} + +export default DashboardContainer; diff --git a/src/component/note-create-form/index.js b/src/component/note-create-form/index.js new file mode 100644 index 0000000..fa66a9c --- /dev/null +++ b/src/component/note-create-form/index.js @@ -0,0 +1,50 @@ +import React from 'react'; + +class NoteCreateForm extends React.Component { + constructor(props) { + super(props); + this.state ={ + title: '', + editing: false, + completed: false, + content: '' + } + 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.handleNoteCreate(this.state); + } + + render() { + return ( +
+ + + +
+ ) + } +} + +export default NoteCreateForm; diff --git a/src/component/note-item/index.js b/src/component/note-item/index.js new file mode 100644 index 0000000..3ef14aa --- /dev/null +++ b/src/component/note-item/index.js @@ -0,0 +1,26 @@ +import React from 'react'; + +class NoteItem extends React.Component { + constructor(props){ + super(props); + this.handleDelete = this.handleDelete.bind(this) + } + + handleDelete() { + this.props.deleteNote(this.props.note.title); + } + + render() { + return ( +
  • +

    {this.props.note.title}

    + +

    {this.props.note.content}

    +
    + +
  • + ); + } +} + +export default NoteItem; diff --git a/src/component/note-list/index.js b/src/component/note-list/index.js new file mode 100644 index 0000000..518d8e9 --- /dev/null +++ b/src/component/note-list/index.js @@ -0,0 +1,25 @@ +import React from 'react'; +import NoteItem from '../note-item'; + +class NoteList extends React.Component { + constructor(props){ + super(props); + } + + render() { + return ( +
    + +
    + ); + } +} + +export default NoteList; diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..696b740 --- /dev/null +++ b/src/index.html @@ -0,0 +1,10 @@ + + + + + + + +
    + + diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..0957696 --- /dev/null +++ b/src/main.js @@ -0,0 +1,58 @@ +import './style/main.scss'; + +import React from 'react'; +import ReactDOM from 'react-dom'; +import {BrowserRouter, Route} from 'react-router-dom'; + +import DashboardContainer from './component/dashboard-container'; +import NoteList from './component/note-list'; + +class App extends React.Component { + constructor(props) { + super(props); + this.state = { + notesArr: [] + } + this.getNote = this.getNote.bind(this); + this.deleteNote = this.deleteNote.bind(this); + } + + getNote() { + return { + state: this.state, + setState: this.setState.bind(this) + } + } + + deleteNote(title) { + let notes = this.state.notesArr; + notes = notes.filter(note => note.title !== title); + this.setState({ notesArr: notes }); + } + + updateNote(title) { + let notes = this.state.notesArr; + notes = notes.map(note => note.title === title ? title : note); + this.setState({ notesArr: notes}); + } + + componentDidUpdate(){ + console.log('___STATE___', this.state); + } + + render() { + return ( +
    + +
    +

    Lets type a note!

    + } /> + +
    +
    +
    + ) + } +} + +ReactDOM.render(, document.getElementById('root')); diff --git a/src/style/main.scss b/src/style/main.scss new file mode 100644 index 0000000..e69de29 diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..a804566 --- /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']) + } + ] + } +} From 4c651b911dc4fe57e1b813adf53107cfcbb7af86 Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Thu, 24 Aug 2017 17:31:55 -0700 Subject: [PATCH 02/18] mostly complete but update not working --- src/component/dashboard-container/index.js | 5 ++- src/component/note-create-form/index.js | 15 ++++++--- src/component/note-item/index.js | 39 ++++++++++++++++++++-- src/component/note-list/index.js | 6 +++- src/main.js | 21 ++++++++---- 5 files changed, 70 insertions(+), 16 deletions(-) diff --git a/src/component/dashboard-container/index.js b/src/component/dashboard-container/index.js index 1173424..a1c619e 100644 --- a/src/component/dashboard-container/index.js +++ b/src/component/dashboard-container/index.js @@ -19,7 +19,10 @@ class DashboardContainer extends React.Component { render() { return (
    - +
    ) } diff --git a/src/component/note-create-form/index.js b/src/component/note-create-form/index.js index fa66a9c..94ac6d7 100644 --- a/src/component/note-create-form/index.js +++ b/src/component/note-create-form/index.js @@ -3,11 +3,15 @@ import React from 'react'; class NoteCreateForm extends React.Component { constructor(props) { super(props); + + let title = props.noteUpdate ? props.noteUpdate.title : ''; + let content = props.noteUpdate ? props.noteUpdate.content : ''; + this.state ={ - title: '', + title, editing: false, completed: false, - content: '' + content } this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); @@ -21,7 +25,10 @@ class NoteCreateForm extends React.Component { handleSubmit(e) { e.preventDefault(); - this.props.handleNoteCreate(this.state); + if(this.props.submitTitle == 'Update Note') { + this.props.handleSubmit(this.state, this.props.noteUpdate.id); + } + this.props.handleSubmit(this.state); } render() { @@ -41,7 +48,7 @@ class NoteCreateForm extends React.Component { placeholder='Enter Note' onChange={this.handleChange} /> - + ) } diff --git a/src/component/note-item/index.js b/src/component/note-item/index.js index 3ef14aa..f15be73 100644 --- a/src/component/note-item/index.js +++ b/src/component/note-item/index.js @@ -1,23 +1,56 @@ import React from 'react'; +import NoteCreateForm from '../note-create-form'; class NoteItem extends React.Component { constructor(props){ super(props); - this.handleDelete = this.handleDelete.bind(this) + this.state = { + editing: null, + } + + this.updateNote = this.updateNote.bind(this); + this.handleDelete = this.handleDelete.bind(this); + this.setTrue = this.setTrue.bind(this); } handleDelete() { - this.props.deleteNote(this.props.note.title); + this.props.deleteNote(this.props.note.id); + } + + setTrue() { + this.setState({ editing: true}); + } + + updateNote(note, id) { + console.log(id); + console.log(note); + let notes = this.props.notesArr; + console.log(notes); + notes = notes.map(prevNote => note.id === id ? note : prevNote); + console.log('_____NOTES____', notes); + this.props.app.setState({ notesArr: notes}); } render() { return ( -
  • +
  • {this.props.note.title}

    {this.props.note.content}

    + { + this.state.editing == true ? +
    + +
    + : +

    Double Click To Edit

    + }
  • ); } diff --git a/src/component/note-list/index.js b/src/component/note-list/index.js index 518d8e9..cba189b 100644 --- a/src/component/note-list/index.js +++ b/src/component/note-list/index.js @@ -12,7 +12,11 @@ class NoteList extends React.Component {