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

add react task #1

Open
wants to merge 2 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
43 changes: 42 additions & 1 deletion components/Board.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
import React from 'react';
import List from './List';

export default class Board extends React.Component {
state = {
lists: [],
newListName: ''
}

addList = () => {
this.setState({
lists: this.state.lists.concat({listName: this.state.newListName}),
newListName: ''
});
};

onListChange = e => {
this.setState({
newListName: e.target.value
})
};

preventDefault = e => {
e.preventDefault();
};

onRemoveList = i => {
this.setState({
lists: this.state.lists.filter((item,index) => {
return index != i;
}),
});
}

render() {
let lists = [];
for (let i = 0; i < this.state.lists.length; i++) {
lists.push(< List listInfo = { this.state.lists[i] } removeList = {() => this.onRemoveList(i)}/>);
}
return (
<div>Board!</div>
<div>
<form onSubmit={this.preventDefault} className='form'>
<input type='text' onChange={this.onListChange} value={this.state.newListName}/>
<button onClick={this.addList}>Add List</button>
</form>
{ lists }
</div>
);
}
}
22 changes: 22 additions & 0 deletions components/Card.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';

class Card extends React.Component {
state = {
task: this.props.cardInfo.task
};

removeCard = () => {
this.props.removeCard();
}

render() {
return (
<div className="card">
<div onClick={this.removeCard} className='remove'>x</div>
<p>{this.props.cardInfo.task}</p>
</div>
);
}
}

export default Card;
59 changes: 59 additions & 0 deletions components/List.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';
import Card from './Card';

class List extends React.Component {
state = {
listName: this.props.listInfo.listName,
cards : [],
newTask: ''
};

addCard = () => {
this.setState({
cards: this.state.cards.concat({task: this.state.newTask}),
newTask: ''
});
};

onCardChange = e => {
this.setState({
newTask: e.target.value
})
};

preventDefault = e => {
e.preventDefault();
};

removeList = () => {
this.props.removeList();
}

onRemoveCard = i => {
this.setState({
cards: this.state.cards.filter((item,index) => {
return index != i;
}),
});
}

render() {
let cards = [];
for (let i = 0; i < this.state.cards.length; i++) {
cards.push(< Card cardInfo = { this.state.cards[i] } removeCard = {() => this.onRemoveCard(i)} />);
}
return (
<div className='list'>
<form onSubmit={this.preventDefault}>
<div onClick={this.removeList} className='remove'>x</div>
<p>{this.props.listInfo.listName}</p>
<input type='text' onChange={this.onCardChange} value={this.state.newTask}/>
<button onClick={this.addCard}>Add Card</button>
</form>
{ cards }
</div>
);
}
}

export default List;
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Task Board</title>
<link rel="stylesheet" href="style/style.css">
</head>

<body>
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"devDependencies": {
"babel-core": "^6.11.4",
"babel-loader": "^6.2.4",
"babel-plugin-transform-class-properties": "^6.10.2",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.11.1",
"babel-preset-stage-1": "^6.5.0",
Expand All @@ -23,6 +24,9 @@
"react",
"stage-1",
"es2015"
],
"plugins": [
"transform-class-properties"
]
},
"dependencies": {
Expand Down
30 changes: 30 additions & 0 deletions style/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.list {
position: relative;
width: 300px;
float: left;
border: 1px solid #c7c4c4;
background: #d8d6d6;
padding: 5px;
color: #3c3939;
margin: 10px;
}
.card {
position: relative;
color: white;
margin-top: 5px;
background: #696565;
padding: 5px;
}
.card p {
margin: 0;
}

.form{
margin-left: 10px;
}

.remove{
position: absolute;
top: 0;
right: 5px;
}