File tree Expand file tree Collapse file tree 4 files changed +22
-6
lines changed Expand file tree Collapse file tree 4 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -3,4 +3,8 @@ export function addTodoItem(todoItem) {
3
3
type : "ADD_TODO_ITEM" , todoItem
4
4
}
5
5
}
6
-
6
+ export function removeTodoItem ( idx ) {
7
+ return {
8
+ type : "REMOVE_TODO_ITEM" , idx
9
+ }
10
+ }
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ export class TodoResultsComponent extends React.Component {
17
17
< tbody >
18
18
{
19
19
this . props . resultsList . map ( ( arr , idx ) => {
20
- return ( < TodoResultsRow key = { `result${ idx } ` } todoItem = { arr } /> )
20
+ return ( < TodoResultsRow idx = { idx } key = { `result${ idx } ` } todoItem = { arr } /> )
21
21
} )
22
22
}
23
23
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import MaterialIcon from 'material-icons-react' ;
3
- import { connect } from 'react-redux'
3
+ import { removeTodoItem } from '../../../actions/resultsListAction'
4
+ import { connect } from 'react-redux'
4
5
5
- export class TodoResultsRowComponent extends React . Component {
6
+ class TodoResultsRowComponent extends React . Component {
7
+ constructor ( ) {
8
+ super ( ) ;
9
+ this . removeRow = this . removeRow . bind ( this )
10
+ }
11
+ removeRow ( ) {
12
+ this . props . dispatch ( removeTodoItem ( this . props . idx ) )
13
+ }
6
14
7
15
render ( ) {
8
16
return (
@@ -13,7 +21,7 @@ export class TodoResultsRowComponent extends React.Component {
13
21
< div >
14
22
</ div >
15
23
</ span >
16
- < button className = "iconContainer" >
24
+ < button onClick = { this . removeRow } className = "iconContainer" >
17
25
< MaterialIcon icon = "delete" />
18
26
</ button >
19
27
</ td >
Original file line number Diff line number Diff line change @@ -3,11 +3,15 @@ const initialState = {
3
3
}
4
4
5
5
export default function todoApp ( state = initialState , action ) {
6
+ let newResultsList = state . resultsList . slice ( 0 )
6
7
switch ( action . type ) {
7
8
case "ADD_TODO_ITEM" :
8
- let newResultsList = state . resultsList . slice ( 0 )
9
9
newResultsList . push ( action . todoItem )
10
10
return { ...state , resultsList : newResultsList }
11
+ case "REMOVE_TODO_ITEM" :
12
+ newResultsList . splice ( action . idx , 1 )
13
+ console . log ( newResultsList )
14
+ return { ...state , resultsList : newResultsList }
11
15
default :
12
16
return state
13
17
}
You can’t perform that action at this time.
0 commit comments