Skip to content

Commit dbd2584

Browse files
major bug fix occuring due to event.target
1 parent dbb47e0 commit dbd2584

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

src/Action_Creators/actions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ export const addTodo = (VALUE) => ({
1111
export const deleteTodo = (VALUE) => ({
1212
type: CONST.DEL_TODO,
1313
ID: VALUE
14+
}
1415

15-
});
16+
);

src/App.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ constructor(){
2020

2121
deleteTODO(e){
2222

23+
console.log(e.target);
2324
let id = parseInt(e.target.id, 10);
25+
// console.log('delete todo',id);
26+
// console.log(typeof(id));
2427
this.props.deleteTodo(id);
2528
}
2629

@@ -31,7 +34,7 @@ constructor(){
3134
})
3235
}
3336

34-
handleClick(e){
37+
handleClick_with_keypress_(e){
3538
if(this.state.input_value == '')
3639
return;
3740

@@ -41,6 +44,14 @@ constructor(){
4144

4245
}
4346

47+
checkTODO(e){
48+
// console.log(e.target)
49+
// console.log(e.target.id);
50+
// let id = parseInt(e.target.id, 10);
51+
52+
console.log(typeof(id));
53+
}
54+
4455
handleClick_without_keypress_(e){
4556
if(this.state.input_value == '')
4657
return;
@@ -58,16 +69,19 @@ constructor(){
5869

5970
<h1> A TO-DO Application </h1>
6071

61-
<ADD className = "pad" value = {this.state.input_value} onKeyPress = {(e) => {this.handleClick(e)}} onChange = {(e) => {this.change(e)}} />
72+
<ADD className = "pad" value = {this.state.input_value} onKeyPress = {(e) => {this.handleClick_with_keypress_(e)}} onChange = {(e) => {this.change(e)}} />
73+
6274
<TODO className = "pad" handleClick = {(e) => {this.handleClick_without_keypress_(e)}}/>
75+
6376
<ul className = "_ul">
6477
{this.props.TODO_ARRAY.map((listValue,index) => {
65-
6678
return(
6779
<div id = {index}>
6880
<li key={index} className = "_font" > {listValue.title}
69-
<DEL value = {listValue.title} id = {index} onClick = {(e) => {this.deleteTODO(e)}} />
70-
<CHECK />
81+
82+
<DEL id = {index} onClick = {(e) => {this.deleteTODO(e)}} />
83+
84+
<CHECK id = {index} onClick = {(e)=>{this.checkTODO(e)}}/>
7185
</li>
7286
</div>
7387
)

src/Components/check_todo.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import ReactDOM from 'react-dom';
44

55

66
function CHECK(props) {
7-
return(<button className = " _left btn btn-default"><i className="fa fa-check"></i></button>)
7+
return(
8+
<button className = " _left btn btn-default" id = {props.id} onClick = {props.onClick} >
9+
<i id = {props.id} className="fa fa-check"></i>
10+
</button>)
811
}
912

1013
export default CHECK;

src/Components/del_todo.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11

2+
3+
24
import React from 'react';
35
import ReactDOM from 'react-dom';
46

57

68
function DEL(props) {
7-
// console.log(props);
8-
return(<button className = " _left btn btn-default" type = "text" id = {props.id} value = {props.value} onClick = {props.onClick} ><i className="fa fa-close"></i></button>)
9+
return(
10+
<button className = " _left btn btn-default" id = {props.id} onClick = {props.onClick} >
11+
<i id = {props.id} className="fa fa-close"></i>
12+
</button>)
913
}
1014

1115
export default DEL;

src/Reducers/reducer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const intialState = {
1111
export const TodoList = (state = intialState , action) =>{
1212

1313
console.log('In Reducer',action);
14+
1415
switch(action.type){
1516

1617
case 'ADD_TODO':

0 commit comments

Comments
 (0)