2023-06-15 18:16:56 +03:00
|
|
|
const todos = (state = [], action) => {
|
2025-05-30 19:59:02 +00:00
|
|
|
if (action.type == "ADD_TODO") {
|
2023-06-16 00:22:31 +03:00
|
|
|
return [
|
|
|
|
|
...state,
|
|
|
|
|
{
|
|
|
|
|
id: action.id,
|
|
|
|
|
text: action.text,
|
2025-05-30 19:59:02 +00:00
|
|
|
completed: false,
|
|
|
|
|
},
|
2023-06-16 00:22:31 +03:00
|
|
|
]
|
2025-05-30 19:59:02 +00:00
|
|
|
} else if (action.type == "TOGGLE_TODO") {
|
2023-06-16 00:22:31 +03:00
|
|
|
return state.map(todo =>
|
2025-05-30 19:59:02 +00:00
|
|
|
todo.id === action.id ? { ...todo, completed: !todo.completed } : todo,
|
2023-06-16 00:22:31 +03:00
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
return state
|
2023-06-15 18:16:56 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default todos
|