Commit a669e450 by Madhankumar

close button issue on edit

parent 71c65516
{
"liveServer.settings.port": 5502
}
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-icons": "^4.10.1", "react-icons": "^4.10.1",
"react-router-dom": "^6.15.0", "react-router-dom": "^6.15.0",
"react-scripts": "5.0.1", "react-scripts": "^2.1.3",
"web-vitals": "^2.1.4" "web-vitals": "^2.1.4"
}, },
"scripts": { "scripts": {
......
...@@ -12,6 +12,7 @@ function App() { ...@@ -12,6 +12,7 @@ function App() {
const [editTodo, setEditTodo] = useState(null); const [editTodo, setEditTodo] = useState(null);
const [isedit, setIsEdit] = useState(false); const [isedit, setIsEdit] = useState(false);
const deleteTask = async (id) => { const deleteTask = async (id) => {
await fetch(`http://192.168.1.91:5000/task/${id}`, { method: "DELETE" }); await fetch(`http://192.168.1.91:5000/task/${id}`, { method: "DELETE" });
setTask(task.filter((e) => e.id !== id)); setTask(task.filter((e) => e.id !== id));
...@@ -53,14 +54,17 @@ function App() { ...@@ -53,14 +54,17 @@ function App() {
return response; return response;
}; };
const editTask = async (id) => { const editTask = async (id) => {
console.log("dskdn")
const res = await getTaskById(id); const res = await getTaskById(id);
setEditTodo(res); if(res){
setIsEdit(!isedit); setEditTodo(res);
setShowAddTask(!showAddTask); setIsEdit(true);
setShowAddTask(true);
}
}; };
const editTodoTask = async (datas) => { const editTodoTask = async (datas) => {
console.log(datas);
const response = await fetch( const response = await fetch(
`http://192.168.1.91:5000/task/${editTodo.id}`, `http://192.168.1.91:5000/task/${editTodo.id}`,
{ {
...@@ -70,8 +74,9 @@ function App() { ...@@ -70,8 +74,9 @@ function App() {
} }
); );
const data = await response.json(); const data = await response.json();
setTask(task.map((e) => (e.id === data.id ? data : e))); setTask(task.map((e) => (e.id === data.id ? data : e)));
setIsEdit(!isedit);
}; };
...@@ -84,7 +89,7 @@ function App() { ...@@ -84,7 +89,7 @@ function App() {
<Router> <Router>
<div className="container"> <div className="container">
<Header <Header
addtask={() => setShowAddTask(!showAddTask)} addtask={() => {setShowAddTask(!showAddTask);setIsEdit(false)}}
showAdd={showAddTask} showAdd={showAddTask}
/> />
...@@ -95,14 +100,15 @@ function App() { ...@@ -95,14 +100,15 @@ function App() {
exact exact
element={ element={
<> <>
{showAddTask && (
<Form <Form
addtask={addTask} addtask={addTask}
onEdit={editTodoTask} onEdit={editTodoTask}
onEditData={editTodo} onEditData={editTodo}
iseditTask={isedit} iseditTask={isedit}
isAddClose={showAddTask}
/> />
)}
{task.length > 0 ? ( {task.length > 0 ? (
<Tasks <Tasks
task={task} task={task}
......
...@@ -2,7 +2,7 @@ import React, { useState,useEffect } from "react"; ...@@ -2,7 +2,7 @@ import React, { useState,useEffect } from "react";
function Form({addtask,onEdit,iseditTask,onEditData}) { function Form({addtask,onEdit,iseditTask,onEditData,isAddClose}) {
const [text ,setText]=useState(""); const [text ,setText]=useState("");
const [day ,setDay]=useState(""); const [day ,setDay]=useState("");
const [remainder ,setRemainder]=useState(false); const [remainder ,setRemainder]=useState(false);
...@@ -24,15 +24,27 @@ function Form({addtask,onEdit,iseditTask,onEditData}) { ...@@ -24,15 +24,27 @@ function Form({addtask,onEdit,iseditTask,onEditData}) {
useEffect(()=>{ useEffect(()=>{
console.log(iseditTask)
if(iseditTask){ console.log("hello",onEditData,iseditTask,isAddClose)
if(onEditData!=null && iseditTask){
setText(onEditData.text); setText(onEditData.text);
setDay(onEditData.day); setDay(onEditData.day);
setRemainder(onEditData.remainder); setRemainder(onEditData.remainder);
} }
},[onEditData])
if(!iseditTask){
setText('');
setDay('');
setRemainder(false)
}
},[onEditData,iseditTask])
return ( return (
<div> <div className={!isAddClose ? "form" :""}>
<form onSubmit={onsubmit} className="form-control"> <form onSubmit={onsubmit} className="form-control">
<div className="form-input"> <div className="form-input">
<label>Task</label> <label>Task</label>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment