aboutsummaryrefslogtreecommitdiff
path: root/src/features/todo/reducer.js
diff options
context:
space:
mode:
authorAdrián Oliva <adrian.oliva@cimat.mx>2023-05-17 21:26:50 -0600
committerAdrián Oliva <adrian.oliva@cimat.mx>2023-05-17 21:26:50 -0600
commit593ab2d7d4ef972594131b125d9320c618e54691 (patch)
tree1d44587b3785f987e41d807370d8a04f27565170 /src/features/todo/reducer.js
parent163398f68444d278eb83543ba9798a6441c8af9f (diff)
downloadToDo-App-FE-593ab2d7d4ef972594131b125d9320c618e54691.tar.gz
ToDo-App-FE-593ab2d7d4ef972594131b125d9320c618e54691.zip
Redux used to add ToDos
WE MADE IT!! I don't know how, but it is functional. :'3
Diffstat (limited to '')
-rw-r--r--src/features/todo/reducer.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/features/todo/reducer.js b/src/features/todo/reducer.js
new file mode 100644
index 0000000..29422e9
--- /dev/null
+++ b/src/features/todo/reducer.js
@@ -0,0 +1,32 @@
+import { createSlice } from "@reduxjs/toolkit";
+
+export const todo_slice = createSlice({
+ name: "todo_list",
+ initialState: {
+ todos: [],
+ last_id: 0,
+ },
+
+ reducers: {
+ add_todo: (state, action) => {
+ state.todos = [
+ ...state.todos,
+ {
+ id: ++state.last_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,
+ },
+ ];
+ console.log(state.todos);
+ },
+ },
+});
+
+export const { add_todo } = todo_slice.actions;
+
+export const select_todos = (state) => state.todo_list.todos;
+
+export default todo_slice.reducer;