aboutsummaryrefslogtreecommitdiff
path: root/src/features/todo
diff options
context:
space:
mode:
authorAdrián Oliva <adrian.oliva@cimat.mx>2023-05-27 14:16:12 -0600
committerAdrián Oliva <adrian.oliva@cimat.mx>2023-05-27 14:16:12 -0600
commite04bff29bf8146bb709a76fc187e0683065e4f03 (patch)
treeacb7a81dd4d362f3bdac09e0d3e5723d413a5c67 /src/features/todo
parent5fc5f300463f606c948ec10fc5554e3c60a8ec36 (diff)
downloadToDo-App-FE-e04bff29bf8146bb709a76fc187e0683065e4f03.tar.gz
ToDo-App-FE-e04bff29bf8146bb709a76fc187e0683065e4f03.zip
List of to dos is initialized on database.
At the beginning, the app will fetch the to dos from the back end and write all of them on Redux.
Diffstat (limited to '')
-rw-r--r--src/features/todo/reducer.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/features/todo/reducer.js b/src/features/todo/reducer.js
index 960ab97..d62e599 100644
--- a/src/features/todo/reducer.js
+++ b/src/features/todo/reducer.js
@@ -31,6 +31,31 @@ export const todo_slice = createSlice({
];
},
+ set_todo: (state, action) => {
+ let selected_todo = state.todos.findIndex(
+ (x) => x.id == action.payload.id
+ );
+ if (selected_todo == -1) {
+ state.todos = [
+ ...state.todos,
+ {
+ id: action.payload.id,
+ text: action.payload.text,
+ due_date: action.payload.due_date,
+ done: action.payload.done,
+ priority: action.payload.priority,
+ creation_date: action.payload.creation_date,
+ },
+ ];
+ state.last_id++;
+ } else {
+ 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;
+ }
+ },
+
change_done: (state, action) => {
let selected_todo = state.todos.findIndex(
(x) => x.id == action.payload.id
@@ -173,6 +198,7 @@ export const todo_slice = createSlice({
export const {
add_todo,
+ set_todo,
change_done,
remove_todo,
edit_todo,