Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed May 10, 2017
0 parents commit 1893151
Show file tree
Hide file tree
Showing 16 changed files with 7,269 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env
npm-debug.log*
yarn-debug.log*
yarn-error.log*

1,623 changes: 1,623 additions & 0 deletions README.md

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "projectmanager",
"version": "0.1.0",
"private": true,
"dependencies": {
"jquery": "^3.2.1",
"react": "^15.5.4",
"react-dom": "^15.5.4"
},
"devDependencies": {
"react-scripts": "0.9.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Binary file added public/favicon.ico
Binary file not shown.
14 changes: 14 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">

<title>Project Manager</title>
</head>
<body>
<div id="root"></div>

</body>
</html>
Empty file added src/App.css
Empty file.
88 changes: 88 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import React, { Component } from 'react';
import uuid from 'uuid';
import $ from 'jquery';
import Projects from './components/Projects';
import AddProject from './components/AddProject';
import Todos from './components/Todos';
import './App.css';

class App extends Component {
constructor(){
super();
this.state = {
projects: [],
todos:[]
}
}

getTodos(){
$.ajax({
url: 'https://jsonplaceholder.typicode.com/todos',
dataType:'json',
cache: false,
success: function(data){
this.setState({todos: data}, function(){
console.log(this.state);
});
}.bind(this),
error: function(xhr, status, err){
console.log(err);
}
});
}

getProjects(){
this.setState({projects: [
{
id:uuid.v4(),
title: 'Business Website',
category: 'Web Deisgn'
},
{
id:uuid.v4(),
title: 'Social App',
category: 'Mobile Development'
},
{
id:uuid.v4(),
title: 'Ecommerce Shopping Cart',
category: 'Web Development'
}
]});
}

componentWillMount(){
this.getProjects();
this.getTodos();
}

componentDidMount(){
this.getTodos();
}

handleAddProject(project){
let projects = this.state.projects;
projects.push(project);
this.setState({projects:projects});
}

handleDeleteProject(id){
let projects = this.state.projects;
let index = projects.findIndex(x => x.id === id);
projects.splice(index, 1);
this.setState({projects:projects});
}

render() {
return (
<div className="App">
<AddProject addProject={this.handleAddProject.bind(this)} />
<Projects projects={this.state.projects} onDelete={this.handleDeleteProject.bind(this)} />
<hr />
<Todos todos={this.state.todos} />
</div>
);
}
}

export default App;
8 changes: 8 additions & 0 deletions src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
});
63 changes: 63 additions & 0 deletions src/components/AddProject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React, { Component } from 'react';
import uuid from 'uuid';

class AddProject extends Component {
constructor(){
super();
this.state - {
newProject: {}
}
}

static defaultProps = {
categories: ['Web Design', 'Web Development', 'Mobile Development']
}

handelSubmit(e){
if(this.refs.title.value === ''){
alert('Title is required');
} else {
this.setState({newProject:{
id: uuid.v4(),
title: this.refs.title.value,
category: this.refs.category.value
}}, function(){
// console.log(this.state);
this.props.addProject(this.state.newProject);
});
}
e.preventDefault();
}

render() {
let categoryOptions = this.props.categories.map(category =>{
return <option key={category} value={category}>{category}</option>
});
return (
<div>
<h3>Add Project</h3>
<form onSubmit={this.handelSubmit.bind(this)}>
<div>
<label>Tile</label><br />
<input type='text' ref='title' />
</div>
<div>
<label>Category</label><br />
<select ref='category'>
{categoryOptions}
</select>
</div>
<br />
<input type='submit' value='Submit'/>
</form>
</div>
);
}
}

AddProject.propTypes = {
categories: React.PropTypes.array,
AddProject: React.PropTypes.func
}

export default AddProject;
24 changes: 24 additions & 0 deletions src/components/ProjectItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { Component } from 'react';


class ProjectItem extends Component {

deleteProject(id){
this.props.onDelete(id);
}

render() {
return (
<li className="Project">
<strong>{this.props.project.title}</strong>: {this.props.project.category} <a href="#" onClick={this.deleteProject.bind(this, this.props.project.id)}>X</a>
</li>
);
}
}

ProjectItem.propTypes = {
project: React.PropTypes.object,
onDelete: React.PropTypes.func
}

export default ProjectItem;
34 changes: 34 additions & 0 deletions src/components/Projects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { Component } from 'react';
import ProjectItem from './ProjectItem';

class Projects extends Component {

deleteProject(id){
this.props.onDelete(id);
}

render() {
let projectItems;
if(this.props.projects){
projectItems = this.props.projects.map(project => {
// console.log(project);
return(
<ProjectItem onDelete={this.deleteProject.bind(this)} key={project.title} project={project} />
);
});
}
return (
<div className="Projects">
<h3>Latest Projects</h3>
{projectItems}
</div>
);
}
}

Projects.propTypes = {
projects: React.PropTypes.array,
onDelete: React.PropTypes.func
}

export default Projects;
17 changes: 17 additions & 0 deletions src/components/TodoItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, { Component } from 'react';

class TodoItem extends Component {
render() {
return (
<li className="Todo">
<strong>{this.props.todo.title}</strong>
</li>
);
}
}

TodoItem.propTypes = {
todo: React.PropTypes.object
}

export default TodoItem;
28 changes: 28 additions & 0 deletions src/components/Todos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { Component } from 'react';
import TodoItem from './TodoItem';

class Todos extends Component {
render() {
let todoItems;
if(this.props.todos){
todoItems = this.props.todos.map(todo => {
//console.log(project);
return (
<TodoItem key={todo.title} todo={todo} />
);
});
}
return (
<div className="Todos">
<h3>Todo List</h3>
{todoItems}
</div>
);
}
}

Todos.propTypes = {
todos: React.PropTypes.array
}

export default Todos;
5 changes: 5 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
body {
margin: 0;
padding: 0;
font-family: sans-serif;
}
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';


ReactDOM.render(
<App />,
document.getElementById('root')
);
Loading

0 comments on commit 1893151

Please sign in to comment.