-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainCard.js
More file actions
73 lines (61 loc) · 2.45 KB
/
Copy pathMainCard.js
File metadata and controls
73 lines (61 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import React from 'react';
import NewCard from '../components/NewCard';
class MainCard extends React.Component {
i = 0;
state = {
task: '',
deadline: '',
importance: '',
cards: []
}
handleChange = (event) => (
this.setState({[event.target.name]: event.target.value})
)
handleSubmit = (event) => {
event.preventDefault();
this.refs['task'].form.reset();
this.refs['dl'].form.reset();
this.refs['impt'].form.reset();
}
onButtonClick = () => {
const card = <NewCard key = {this.i} task = {this.state.task} deadline = {this.state.deadline} importance = {this.state.importance} removal = {this.onRemovalButtonClick}/>;
this.setState(prevState => ({
cards: [...prevState.cards, card]}));
this.i++;
this.setState({
task: '',
deadline: '',
importance: ''
});
}
onRemovalButtonClick = (key) => {
const newArray = [...this.state.cards];
newArray.splice(key, 1);
this.setState({cards: newArray});
}
render() {
return (
<div>
<form onSubmit = {this.handleSubmit}>
<label> Task: </label>
<input name = "task" onInput = {this.handleChange} ref = "task" type = "text" style = {{width: 200}}/>
<br/>
<label> Deadline: </label>
<input name = "deadline" onInput = {this.handleChange} ref = "dl" type = "text" style = {{width: 200}}/>
<br/>
<label> Importance: </label>
<select name = "importance" onInput={this.handleChange} ref = "impt" style = {{width: 200, height: 21}}>
<option value="None">(Select option)</option>
<option value="Very important">Very important</option>
<option value="Important">Important</option>
<option value="Not too important">Not too important</option>
</select>
<br/>
<button type = "submit" onClick = {this.onButtonClick} style = {{fontFamily: "Monotype Corsiva", fontSize: 20, margin: 5}}> Submit </button>
<h1 style = {{color: "brown", fontSize: 30}}>{this.state.cards} </h1>
</form>
</div>
);
}
}
export default MainCard;