Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react task finished, "remove list" button added #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
22 changes: 22 additions & 0 deletions maruhin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Task Board
===

Create Board with lists as in Trello.

Board should have input with button to create new list.

Each list have input with button for new items creating.


More (optional)
---

Implement list and items remove.

Add names editing


Super Advanced
---

Implement drag and drop items from list to list.
36 changes: 36 additions & 0 deletions maruhin/components/Board.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import List from './List.jsx';
import ListForm from './ListForm.jsx';

export default class Board extends React.Component {
state = {
lists:[]
};
addList = (listName) => {
let arr = this.state.lists;
arr.push(listName);
this.setState({lists:arr});
};
removeList = (i) => {
let arr = this.state.lists;
arr.splice(i,1);
this.setState({lists: arr});
};
eachList = (list,i) =>{
return(
<List key={i}
index={i}
onRemove = {this.removeList}
>{list}</List>
)
};

render() {
return(
<div className = "board">
<ListForm createList = {this.addList}/>
{this.state.lists.map(this.eachList)}
</div>
)
}
}
42 changes: 42 additions & 0 deletions maruhin/components/List.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import TaskForm from './TaskForm.jsx';
import Task from './Task.jsx'

export default class List extends React.Component {
state = {
tasks: [],
};
componentDidMount = () =>{
$(this.getDOMNode()).draggable();
};
addTask = (taskName) => {
let arr = this.state.tasks;
arr.push(taskName);
this.setState({tasks:arr});
};
eachTask = (task,i) => {
return(
<Task key={i}
index={i}
>{task}</Task>
)
};
remove = () => {
this.props.onRemove(this.props.index);
};

render() {
return (
<div className = "list">
<div>
<h1>{this.props.children}</h1>
<TaskForm createTask = {this.addTask}/>
{this.state.tasks.map(this.eachTask)}
</div>
<span>
<button onClick={this.remove}>Remove List</button>
</span>
</div>
)
}
}
25 changes: 25 additions & 0 deletions maruhin/components/ListForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';

export default class ListForm extends React.Component {
state = {
inputValue: ''
}

onInputValueChange = (e) => {
this.setState({inputValue: e.target.value})
}

onClick = (e) => {
this.props.createList(this.state.inputValue)
this.setState({inputValue: ''})
}

render() {
return (
<div>
<input type="text" onChange={this.onInputValueChange} placeholder="create a new list" value={this.state.inputValue}></input>
<button onClick={this.onClick}>Add New List</button>
</div>
);
}
};
10 changes: 10 additions & 0 deletions maruhin/components/Task.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';

export default class Task extends React.Component {

render() {
return (
<p>{this.props.children}</p>
)
}
}
25 changes: 25 additions & 0 deletions maruhin/components/TaskForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';

export default class TaskForm extends React.Component {
state = {
inputValue: ''
}

onInputValueChange = (e) => {
this.setState({inputValue: e.target.value})
}

onClick = (e) => {
this.props.createTask(this.state.inputValue)
this.setState({inputValue: ''})
}

render() {
return (
<div>
<input type="text" onChange={this.onInputValueChange} placeholder="create a new task" value={this.state.inputValue}></input>
<button onClick={this.onClick}>Add New Task</button>
</div>
);
}
};
18 changes: 18 additions & 0 deletions maruhin/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Task Board</title>
</head>

<body>

<div id="app"></div>
<script src="./build/bundle.js"></script>

</body>

</html>
9 changes: 9 additions & 0 deletions maruhin/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';

import Board from './components/Board';

ReactDOM.render(
<Board />,
document.getElementById('app')
);
35 changes: 35 additions & 0 deletions maruhin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "react-lecture-task",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"start": "http-server",
"build": "webpack ./webpack.config.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.11.4",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.11.1",
"babel-preset-stage-1": "^6.5.0",
"http-server": "^0.9.0",
"webpack": "^1.13.1"
},
"babel": {
"presets": [
"react",
"stage-1",
"es2015"
],
"plugins": [
"transform-class-properties"
]
},
"dependencies": {
"react": "^15.2.1",
"react-dom": "^15.2.1"
}
}
17 changes: 17 additions & 0 deletions maruhin/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
entry: __dirname + '/index.jsx',
output: {
path: __dirname + '/build',
filename: 'bundle.js'
},
resolve: {
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel'
}]
}
};