From ff4cc46041251972634a28c1f780541fd105aadc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Oliva?= Date: Fri, 19 May 2023 15:19:11 -0600 Subject: Edit button almost done. Noticed some bugs. Will patch on later commits. --- src/features/todo/reducer.js | 15 ++++++++++++++- 1 file changed, 14 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 f12f740..a13810b 100644 --- a/src/features/todo/reducer.js +++ b/src/features/todo/reducer.js @@ -36,10 +36,23 @@ export const todo_slice = createSlice({ (todo) => todo.id != action.payload ); }, + + edit_todo: (state, action) => { + let selected_todo = state.todos.findIndex( + (x) => x.id == action.payload.id + ); + if (selected_todo == -1) return; + + state.todos[selected_todo].text = action.payload.text; + state.todos[selected_todo].due_date = action.payload.due_date; + state.todos[selected_todo].done = action.payload.done; + state.todos[selected_todo].priority = action.payload.priority; + }, }, }); -export const { add_todo, change_done, remove_todo } = todo_slice.actions; +export const { add_todo, change_done, remove_todo, edit_todo } = + 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