aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/App.jsx17
-rw-r--r--src/api/axios_methods.js14
-rw-r--r--src/features/todo/reducer.js5
3 files changed, 34 insertions, 2 deletions
diff --git a/src/App.jsx b/src/App.jsx
index 6f1b14f..b39d5d9 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -4,9 +4,13 @@ import { NewToDo } from "./ToDo-UI/NewToDo";
import { ListToDos } from "./ToDo-UI/ListToDo";
import { useDispatch } from "react-redux";
-import { set_todo, refresh_filtered_todos } from "./features/todo/reducer";
+import {
+ set_last_id,
+ set_todo,
+ refresh_filtered_todos,
+} from "./features/todo/reducer";
-import { get_todos_function } from "./api/axios_methods";
+import { get_todos_function, get_last_id_function } from "./api/axios_methods";
function App() {
const get_todos = get_todos_function();
@@ -37,6 +41,15 @@ function App() {
}
get_todos(handler);
+ const last_id_api = get_last_id_function();
+ last_id_api((response) => {
+ dispatch(
+ set_last_id({
+ id: response,
+ })
+ );
+ });
+
return (
<div>
<Search />
diff --git a/src/api/axios_methods.js b/src/api/axios_methods.js
index ffc0c28..f983157 100644
--- a/src/api/axios_methods.js
+++ b/src/api/axios_methods.js
@@ -86,3 +86,17 @@ export function set_undone_function() {
}
};
}
+
+// giveMeLastID().
+export function get_last_id_function() {
+ // Retrieve last index used.
+ // GET "/todos/lastIndex"
+ return async (handler) => {
+ try {
+ const response = await api.get("/todos/lastIndex");
+ handler(response.data);
+ } catch (err) {
+ console.log(err);
+ }
+ };
+}
diff --git a/src/features/todo/reducer.js b/src/features/todo/reducer.js
index 16fc427..118e482 100644
--- a/src/features/todo/reducer.js
+++ b/src/features/todo/reducer.js
@@ -17,6 +17,10 @@ export const todo_slice = createSlice({
},
reducers: {
+ set_last_id: (state, action) => {
+ state.last_id = action.payload.id;
+ },
+
add_todo: (state, action) => {
state.todos = [
...state.todos,
@@ -196,6 +200,7 @@ export const todo_slice = createSlice({
});
export const {
+ set_last_id,
add_todo,
set_todo,
change_done,