From daee56ba5509a4576fa066adfcc0d1bc05f98802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Oliva?= Date: Mon, 29 May 2023 18:28:55 -0600 Subject: Adding new to dos is now synchronized with database. Changed the `refreshToDos` to also refresh the last index used. --- src/ToDo-UI/NewToDo.jsx | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'src/ToDo-UI/NewToDo.jsx') diff --git a/src/ToDo-UI/NewToDo.jsx b/src/ToDo-UI/NewToDo.jsx index dc062db..313456b 100644 --- a/src/ToDo-UI/NewToDo.jsx +++ b/src/ToDo-UI/NewToDo.jsx @@ -1,14 +1,16 @@ import React, { useState } from "react"; import { useSelector, useDispatch } from "react-redux"; import { - add_todo, - sort_todo, - refresh_filtered_todos, select_last_index, + select_current_filters, + select_current_sorting, + select_current_page, } from "../features/todo/reducer"; import { new_todo_function } from "../api/axios_methods"; +import { refresh_todos } from "../refreshToDos"; + function new_button(trigger_id) { return (
@@ -46,6 +48,10 @@ export function NewToDo() { const [new_due_date, set_new_due_date] = useState(""); const [new_priority, set_new_priority] = useState("Low"); + const my_filters = useSelector(select_current_filters); + const my_sorters = useSelector(select_current_sorting); + const my_curr_page = useSelector(select_current_page); + const new_todo_api = new_todo_function(); function handle_exit_modal() { @@ -65,19 +71,9 @@ export function NewToDo() { : new Date(new_due_date).toISOString(), priority: new_priority, }); - dispatch( - add_todo({ - text: new_text, - due_date: - new_due_date.length == 0 - ? "" - : new Date(new_due_date).toISOString(), - priority: new_priority, - creation_date: new Date().toISOString(), - }) - ); - dispatch(sort_todo()); - dispatch(refresh_filtered_todos()); + setTimeout(() => { + refresh_todos(my_filters, my_sorters, my_curr_page, dispatch); + }, 100); handle_exit_modal(); } -- cgit v1.2.3