Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015", "react"]
}
21 changes: 21 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -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"
}
136 changes: 136 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
58 changes: 0 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +0,0 @@
![cf](https://i.imgur.com/7v5ASc8.png) 23: Components and Routing
======

## Submission Instructions
* fork this repository & create a new branch for your work
* write all of your code in a directory named `lab-` + `<your name>` **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 create front end routes through the use of `react-router-dom`
* students will be able to restructure their applications to use modular components
* students will be able to differentiate between view state and application state
* students will be able to lift application state to better control one way data flow

#### Configuration
* `README.md`
* `.babelrc`
* `.gitignore`
* `package.json`
* `webpack.config.js`
* `src/**`
* `src/main.js`
* `src/style`
* `src/style/main.scss`

#### Feature Tasks
* create the following component and structure it according to the diagram below:
```
App
NoteCreateForm
```
###### App Component
* the app component should manage the entire **application state**
* the state should contain a notes array
* each note should have the following data
* `id` - always should contain the result of `uuid.v1()`
* `editing` - false by default
* `completed` - false by default
* `content` - user provided content

###### NoteCreateForm Component
* `onSubmit` - the `NoteCreateForm` component should add a note to the application state
* **note:** in your app component, create a method for logging the state of your application when a note is added (ie: `componentDidUpdate`)
* this should show an array of all notes that have been added to the state

#### Stretch Goals

###### NoteList Component
* should display an unordered list of NoteItem components

###### NoteItem Component
* should display the note content
* should display a delete button
* `onClick` the note should be removed from the application state

38 changes: 38 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
28 changes: 28 additions & 0 deletions src/component/note-container/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import uuid from 'uuid/v1';

import NoteCreateForm from '../note-create-form';

class NoteContainer extends React.Component {
constructor(props) {
super(props);
this.noteCreate = this.noteCreate.bind(this);
}

noteCreate(note) {
note.id = uuid();
this.props.app.setState(state => ({
notes: [...state.notes, note]
}));
}

render() {
return (
<div className='note-container'>
<NoteCreateForm handleNoteCreate={this.noteCreate} />
</div>
)
}
}

export default NoteContainer;
51 changes: 51 additions & 0 deletions src/component/note-create-form/index.js
Original file line number Diff line number Diff line change
@@ -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.handleNoteCreate(this.state);
}

render() {
return (
<form onSubmit={this.handleSubmit}>
<input
name='title'
type='text'
placeholder='title'
value={this.state.title}
onChange={this.handleChange}
/>
<input
className='note-content'
name='content'
type='text'
placeholder='enter note content here'
value={this.state.content}
onChange={this.handleChange}
/>
<button type='submit'>Add</button>
</form>
)
}
}

export default NoteCreateForm;
31 changes: 31 additions & 0 deletions src/component/note-list/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';

class NoteList extends React.Component {
constructor(props){
super(props);
}

render() {
return (
<section>
{ this.props.notes.length === 0 ?
<div>
<p>add a note</p>
</div> :
<ul>
{this.props.notes.map((note, i) => {
return (
<li key={i}>
<h2>{note.title}</h2>
<p>{note.content}</p>
</li>
)
})}
</ul>
}
</section>
)
}
}

export default NoteList;
10 changes: 10 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Note Maker App</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
Loading