Skip to content

Commit 8fef9f1

Browse files
author
Carlos Alcazar
committed
Added remove todo item functionality
1 parent ddfde78 commit 8fef9f1

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

web-app-redux/src/actions/resultsListAction.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ export function addTodoItem(todoItem) {
33
type: "ADD_TODO_ITEM", todoItem
44
}
55
}
6-
6+
export function removeTodoItem(idx) {
7+
return {
8+
type: "REMOVE_TODO_ITEM", idx
9+
}
10+
}

web-app-redux/src/home/todoResults/todoResults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class TodoResultsComponent extends React.Component {
1717
<tbody>
1818
{
1919
this.props.resultsList.map((arr, idx)=>{
20-
return(<TodoResultsRow key={`result${idx}`} todoItem={arr}/>)
20+
return(<TodoResultsRow idx={idx} key={`result${idx}`} todoItem={arr}/>)
2121
})
2222
}
2323

web-app-redux/src/home/todoResults/todoResultsRow/todoResultsRow.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import React from 'react';
22
import MaterialIcon from 'material-icons-react';
3-
import { connect } from 'react-redux'
3+
import { removeTodoItem } from '../../../actions/resultsListAction'
4+
import {connect} from 'react-redux'
45

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+
}
614

715
render() {
816
return (
@@ -13,7 +21,7 @@ export class TodoResultsRowComponent extends React.Component {
1321
<div>
1422
</div>
1523
</span>
16-
<button className="iconContainer">
24+
<button onClick={this.removeRow} className="iconContainer">
1725
<MaterialIcon icon="delete" />
1826
</button>
1927
</td>

web-app-redux/src/reducers/resultsList.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ const initialState = {
33
}
44

55
export default function todoApp(state = initialState, action) {
6+
let newResultsList = state.resultsList.slice(0)
67
switch (action.type) {
78
case "ADD_TODO_ITEM":
8-
let newResultsList = state.resultsList.slice(0)
99
newResultsList.push(action.todoItem)
1010
return {...state, resultsList: newResultsList}
11+
case "REMOVE_TODO_ITEM":
12+
newResultsList.splice(action.idx, 1)
13+
console.log(newResultsList)
14+
return {...state, resultsList: newResultsList}
1115
default:
1216
return state
1317
}

0 commit comments

Comments
 (0)