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
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["es2015", "react"],
"plugins": ["transform-object-rest-spread"]
}
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
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
48 changes: 48 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "26-react-redux",
"version": "1.0.0",
"description": "![cf](https://i.imgur.com/7v5ASc8.png) 26: React & Redux ======",
"main": "index.js",
"scripts": {
"build": "webpack",
"watch": "webpack-dev-server --inline --hot"
},
"repository": {
"type": "git",
"url": "git+https://github.com/codefellows-javascript-401d17/26-react-redux.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/codefellows-javascript-401d17/26-react-redux/issues"
},
"homepage": "https://github.com/codefellows-javascript-401d17/26-react-redux#readme",
"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"
}
}
20 changes: 20 additions & 0 deletions src/action/category-actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import uuid from 'uuid/v1';

export const categoryCreate = (category) => {
category.id = uuid();
category.timestamp = new Date();
return {
type: 'CATEGORY_CREATE',
payload: category
}
}

export const categoryUpdate = (category) => ({
type: 'CATEGORY_UPDATE',
payload: category
})

export const categoryDelete = (category) => ({
type: 'CATEGORY_DELETE',
payload: category
})
32 changes: 32 additions & 0 deletions src/component/app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import {Provider} from 'react-redux';
import {BrowserRouter, Route} from 'react-router-dom';
import createAppStore from '../../lib/store';
import DashboardContainer from '../dashboard-container';

const store = createAppStore();

class App extends React.Component {

componentDidMount() {
store.subscribe(() =>{
console.log('*___STATE___*', store.getState())
});

store.dispatch({ type: null });
}

render() {
return (
<section>
<Provider store={store}>
<BrowserRouter>
<Route exact path='/' component={DashboardContainer} />
</BrowserRouter>
</Provider>
</section>
)
}
}

export default App;
65 changes: 65 additions & 0 deletions src/component/category-form/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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 : ''
}

this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}

handleChange(e) {
let {name, value, type} = e.target;
if (type === 'number') {
try {
this.setState({
[name]: parseInt(value),
});
} catch (err) {
console.error(err);
}
} else {
this.setState({
[name]: value,
});
}
}

handleSubmit(e) {
e.preventDefault();
let category = Object.assign({}, this.state);
if(this.props.category) category.id = this.props.category.id;
this.props.onComplete(category);
}

render() {
return (
<form className='category-form' onSubmit={this.handleSubmit}>
<input
name='title'
type='text'
placeholder='title'
value={this.state.title}
onChange={this.handleChange}
/>

<input
name='budget'
type='number'
placeholder='budget'
value={this.state.budget}
onChange={this.handleChange}
/>

<button type='submit'>{this.props.buttonText}</button>
</form>
)
}
}

export default CategoryForm;
22 changes: 22 additions & 0 deletions src/component/category-item/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import CategoryForm from '../category-form';


class CategoryItem extends React.Component {
render() {
return(
<li>
<h2>{this.props.category.title}</h2>
<h3>{this.props.category.budget}</h3>
<button className='deleteButton' onClick={()=>this.props.categoryDelete(this.props.category)}>X</button>
<CategoryForm
buttonText='Update Category'
category={this.props.category}
onComplete={this.props.categoryUpdate}
/>
</li>
)
}
}

export default CategoryItem
Loading