diff --git a/original-24/.babelrc b/original-24/.babelrc new file mode 100644 index 0000000..86c445f --- /dev/null +++ b/original-24/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["es2015", "react"] +} diff --git a/original-24/.eslintrc b/original-24/.eslintrc new file mode 100644 index 0000000..8dc6807 --- /dev/null +++ b/original-24/.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/original-24/.gitignore b/original-24/.gitignore new file mode 100644 index 0000000..57bad08 --- /dev/null +++ b/original-24/.gitignore @@ -0,0 +1,70 @@ +# Created by https://www.gitignore.io/api/osx,linux,node,vim +node_modules +.env +.test.env +db/ +build/ + +.DS_Store +.AppleDouble +.LSOverride + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + + +### Node ### +# Logs +logs +*.log +npm-debug.log* +.tern-project + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + +### Vim ### +# swap +[._]*.s[a-w][a-z] +[._]s[a-w][a-z] +# session +Session.vim +# temporary +.netrwhist +*~ + +# auto-generated tag files +tags diff --git a/original-24/README.md b/original-24/README.md new file mode 100644 index 0000000..e69de29 diff --git a/original-24/package.json b/original-24/package.json new file mode 100644 index 0000000..5a0f16c --- /dev/null +++ b/original-24/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/nickjaz/23-components_and_routing.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/nickjaz/23-components_and_routing/issues" + }, + "homepage": "https://github.com/nickjaz/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/original-24/src/.babelrc b/original-24/src/.babelrc new file mode 100644 index 0000000..86c445f --- /dev/null +++ b/original-24/src/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["es2015", "react"] +} diff --git a/original-24/src/.eslintrc b/original-24/src/.eslintrc new file mode 100644 index 0000000..8dc6807 --- /dev/null +++ b/original-24/src/.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/original-24/src/.gitignore b/original-24/src/.gitignore new file mode 100644 index 0000000..57bad08 --- /dev/null +++ b/original-24/src/.gitignore @@ -0,0 +1,70 @@ +# Created by https://www.gitignore.io/api/osx,linux,node,vim +node_modules +.env +.test.env +db/ +build/ + +.DS_Store +.AppleDouble +.LSOverride + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + + +### Node ### +# Logs +logs +*.log +npm-debug.log* +.tern-project + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + +### Vim ### +# swap +[._]*.s[a-w][a-z] +[._]s[a-w][a-z] +# session +Session.vim +# temporary +.netrwhist +*~ + +# auto-generated tag files +tags diff --git a/original-24/src/component/note-container/index.js b/original-24/src/component/note-container/index.js new file mode 100644 index 0000000..127229e --- /dev/null +++ b/original-24/src/component/note-container/index.js @@ -0,0 +1,60 @@ +import React from 'react'; +import uuid from 'uuid/v1'; + +import NoteCreateForm from '../note-create-form'; +import NoteList from '../note-list' + +class NoteContainer 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] + })); + } + + 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 NoteContainer; diff --git a/original-24/src/component/note-create-form/index.js b/original-24/src/component/note-create-form/index.js new file mode 100644 index 0000000..80c7fd2 --- /dev/null +++ b/original-24/src/component/note-create-form/index.js @@ -0,0 +1,51 @@ +import React from 'react'; + +class NoteCreateForm extends React.Component { + constructor(props) { + super(props); + this.state = { + title: '', + content: '', + // editing: false, + completed: false + } + 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.handleSubmit(this.state); + } + + render() { + return ( +
+ + + +
+ ) + } +} + +export default NoteCreateForm; diff --git a/original-24/src/component/note-list/index.js b/original-24/src/component/note-list/index.js new file mode 100644 index 0000000..e8283c2 --- /dev/null +++ b/original-24/src/component/note-list/index.js @@ -0,0 +1,60 @@ +import React from 'react'; +import NoteUpdateForm from '../note-update-form'; + +let renderIf = (test, component) => test ? component :undefined; + +class NoteList extends React.Component { + constructor(props){ + super(props); + this.state = { + editing:false + } + + this.handleEditClick = this.handleEditClick.bind(this); + } + + handleEditClick(e){ + this.setState({ + editing: true + }) + } + //state editing = true + render() { + return ( +
+ { this.props.notes.length === 0 ? +
+

add a note

+
: + + } +
+ ) + } +} + +export default NoteList; diff --git a/original-24/src/component/note-update-form/index.js b/original-24/src/component/note-update-form/index.js new file mode 100644 index 0000000..c46fe51 --- /dev/null +++ b/original-24/src/component/note-update-form/index.js @@ -0,0 +1,46 @@ +import React from 'react'; + +class NoteUpdateForm extends React.Component { + constructor(props) { + super(props); + + this.state = { + title: this.props.note.title, + content: '', + editing: false, + complete: false + } + + 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.handleSubmit(this.state) + } + + + render() { + return( +
+ + + +
+ ) + } +} + +export default NoteUpdateForm diff --git a/original-24/src/index.html b/original-24/src/index.html new file mode 100644 index 0000000..3243af3 --- /dev/null +++ b/original-24/src/index.html @@ -0,0 +1,10 @@ + + + + + Note Maker App + + +
+ + diff --git a/original-24/src/main.js b/original-24/src/main.js new file mode 100644 index 0000000..429c9a4 --- /dev/null +++ b/original-24/src/main.js @@ -0,0 +1,45 @@ +import './style/main.scss'; +import React from 'react'; +import ReactDom from 'react-dom'; +import {BrowserRouter, Route} from 'react-router-dom'; + +import NoteContainer from './component/note-container'; + +class App extends React.Component { + constructor(props) { + super(props); + this.state = { + notes: [] + } + + this.getApp = this.getApp.bind(this); + } + + componentDidUpdate() { + console.log('__STATE__', this.state); + } + + getApp() { + return { + state: this.state, + setState: this.setState.bind(this) + } + } + + render() { + return ( +
+

Note Maker

+ +
+ + } /> +
+
+ +
+ ) + } +} + +ReactDom.render(, document.getElementById('root')) diff --git a/original-24/src/style/main.scss b/original-24/src/style/main.scss new file mode 100644 index 0000000..c6cf1c3 --- /dev/null +++ b/original-24/src/style/main.scss @@ -0,0 +1,14 @@ +main { + font-family: helvetica; +} + +input, button { + display: block; + margin: 4px auto; +} + +button { + border: none; + border-radius: 2px; + padding: 4px 8px; +} diff --git a/original-24/webpack.config.js b/original-24/webpack.config.js new file mode 100644 index 0000000..6a08720 --- /dev/null +++ b/original-24/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: { + filename: 'bundle-[hash].js', + path: `${__dirname}/build`, + publicPath: '/' + }, + 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']) + } + ] + } +};