From 8cb67965e363a9ea602a51d6bdee1c4d1e067c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Oliva?= Date: Thu, 18 May 2023 13:53:06 -0600 Subject: Now we can change the done state. --- src/features/todo/reducer.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/features/todo/reducer.js') diff --git a/src/features/todo/reducer.js b/src/features/todo/reducer.js index 0e17412..daba8bc 100644 --- a/src/features/todo/reducer.js +++ b/src/features/todo/reducer.js @@ -21,10 +21,19 @@ export const todo_slice = createSlice({ }, ]; }, + + change_done: (state, action) => { + let selected_todo = state.todos.findIndex( + (x) => x.id == action.payload.id + ); + if (selected_todo == -1) return; + + state.todos[selected_todo].done = action.payload.done; + }, }, }); -export const { add_todo } = todo_slice.actions; +export const { add_todo, change_done } = todo_slice.actions; export const select_todos = (state) => state.todo_list.todos; export const select_last_index = (state) => state.todo_list.last_id; -- cgit v1.2.3