-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#100 added redux to todolist implementation
- Loading branch information
1 parent
18dca35
commit 911b21c
Showing
10 changed files
with
110 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
tutify/src/actions/todolist.js → tutify/src/redux/actions/todolist_action.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
let nextTodoId = 0 | ||
export const addTodo = title => ({ | ||
type: 'ADD_TODO', | ||
id: nextTodoId++, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { connect } from 'react-redux' | ||
import TodoList from '/Users/jasminelatendresse/TutifySoen490/tutify/src/components/UserDashboardPage/Todo/TodoList.js' | ||
import { VisibilityFilters, markComplete } from '../actions/todolist_action' | ||
|
||
const getVisibleTodos = (todos, filter) => { | ||
switch (filter) { | ||
case VisibilityFilters.SHOW_ALL: | ||
return todos | ||
case VisibilityFilters.SHOW_COMPLETED: | ||
return todos.filter(t => t.completed) | ||
case VisibilityFilters.SHOW_ACTIVE: | ||
return todos.filter(t => !t.completed) | ||
default: | ||
throw new Error('Unknown filter: ' + filter) | ||
} | ||
} | ||
|
||
const mapStateToProps = state => ({ | ||
todos: getVisibleTodos(state.todos, state.visibilityFilter) | ||
}) | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
markComplete: id => dispatch(markComplete(id)) | ||
}) | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(TodoList) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { combineReducers } from 'redux' | ||
import todos from './todos' | ||
import visibilityFilter from './visibilityFilter' | ||
|
||
export default combineReducers({ | ||
todos, | ||
visibilityFilter | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const todos = (state = [], action) => { | ||
switch (action.type) { | ||
case 'ADD_TODO': | ||
return [ | ||
...state, | ||
{ | ||
id: action.id, | ||
text: action.text, | ||
completed: false | ||
} | ||
] | ||
case 'MARK_COMPLETE': | ||
return state.map(todo => | ||
(todo.id === action.id) | ||
? { ...todo, completed: !todo.completed } | ||
: todo | ||
) | ||
case 'DEL_TODO': | ||
return Object.assign({}, state, { | ||
todos: state.todos.filter((todo) => { | ||
return todo.id !== action.id | ||
}) | ||
}) | ||
default: | ||
return state | ||
} | ||
} | ||
|
||
export default todos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { VisibilityFilters } from '../actions/todolist_action' | ||
|
||
const visibilityFilter = (state = VisibilityFilters.SHOW_ALL, action) => { | ||
switch (action.type) { | ||
case 'SET_VISIBILITY_FILTER': | ||
return action.filter | ||
default: | ||
return state | ||
} | ||
} | ||
|
||
export default visibilityFilter |