Commit 93121693 by Manivasagam S

my commit

parent c43ffe6c
...@@ -37,6 +37,11 @@ p{ ...@@ -37,6 +37,11 @@ p{
.task ul{ .task ul{
margin: 0; margin: 0;
padding: 0; padding: 0;
}
ul{
max-height: 250px;
overflow-y: auto;
} }
.list{ .list{
display: flex; display: flex;
...@@ -51,7 +56,18 @@ p{ ...@@ -51,7 +56,18 @@ p{
color: rgb(94, 93, 93); color: rgb(94, 93, 93);
} }
.todo-content{
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 17px;
font-weight: 400;
color: rgb(94, 93, 93);
}
.todo-content:focus{
border: none !important;
outline: none !important;
box-shadow: none !important;
}
.list button{ .list button{
background: none; background: none;
border: none; border: none;
...@@ -66,6 +82,7 @@ p{ ...@@ -66,6 +82,7 @@ p{
.list input[type="checkbox"]{ .list input[type="checkbox"]{
height: 18px; height: 18px;
min-width: 36px; min-width: 36px;
} }
.list span{ .list span{
flex-grow: 1; flex-grow: 1;
...@@ -97,6 +114,7 @@ input::placeholder{ ...@@ -97,6 +114,7 @@ input::placeholder{
padding-left: 10px; padding-left: 10px;
} }
.formtext:focus{ .formtext:focus{
outline: none; outline: none;
border: none; border: none;
...@@ -111,8 +129,9 @@ form button{ ...@@ -111,8 +129,9 @@ form button{
padding: 8px; padding: 8px;
font-size: 15px; font-size: 15px;
width: 90px; width: 90px;
height: 43px; height: 42px;
} }
.deletebutton{ .deletebutton{
height: 45px; height: 45px;
min-width: 30px; min-width: 30px;
...@@ -125,10 +144,23 @@ form button{ ...@@ -125,10 +144,23 @@ form button{
outline: none; outline: none;
border: none; border: none;
} }
span{ .error{
max-width:85%; color: red;
margin-left: auto; font-size: 0.9rem;
} display: block;
margin-top: 40px;
width:450rem;
margin-right: auto;
}
.content{
display: flex;
flex-direction: column;
align-items: flex-start;
}
.input-error::placeholder{
color: red;
}
@media (max-width: 600px) { @media (max-width: 600px) {
.formtext { .formtext {
max-width: 40rem; max-width: 40rem;
......
...@@ -3,47 +3,63 @@ import axios from "axios"; ...@@ -3,47 +3,63 @@ import axios from "axios";
import { TiDelete } from "react-icons/ti"; import { TiDelete } from "react-icons/ti";
import "../src/App.css"; import "../src/App.css";
const API_URL = "http://192.168.1.59:3000/todos"; const URL = "http://192.168.1.59:3000/todos";
function App() { function App() {
const [todo, setTodo] = useState([]); const [todo, setTodo] = useState([]);
const [input, setInput] = useState(""); const [input, setInput] = useState("");
const[updateErrors,setUpdateErrors]=useState({});
const[error,setError]=useState("")
useEffect(() => { useEffect(() => {
axios.get(API_URL).then((res) => setTodo(res.data)); axios.get(URL).then((res) => setTodo(res.data));
}, []); }, []);
const handleSubmit = async (e) => { const handleSubmit = async (e) => {
e.preventDefault(); e.preventDefault();
if (input.trim() === "") return; if (input.trim() === ""){
setError("Please enter this field");
setTimeout(() => setError(""), 3000);
return;
}
setError("");
const newTodo = { text: input, completed: false }; const newTodo = { text: input, completed: false };
const res = await axios.post(API_URL, newTodo); const res = await axios.post(URL, newTodo);
setTodo([...todo, res.data]); setTodo([...todo, res.data]);
setInput(""); setInput("");
console.log(res.data)
}; };
const handleDelete = async (id) => { const handleDelete = async (id) => {
await axios.delete(`${API_URL}/${id}`); await axios.delete(`${URL}/${id}`);
setTodo(todo.filter((item) => item.id !== id)); setTodo(todo.filter((item) => item.id !== id));
}; };
const handleUpdate = async (id, updatedText) => { const handleUpdate = async (id, updatedText) => {
const updatedTodo = todo.find((item) => item.id === id); const updatedTodo = todo.find((item) => item.id === id);
if (!updatedTodo) return;
const newTodo = { ...updatedTodo, text: updatedText }; const newTodo = { ...updatedTodo, text: updatedText };
await axios.put(`${API_URL}/${id}`, newTodo); await axios.put(`${URL}/${id}`, newTodo);
setTodo(todo.map((item) => setTodo(todo.map((item) =>
item.id === id ? { ...item, text: updatedText } : item item.id === id ? { ...item, text: updatedText } : item
)); ));
if (updatedText === '') {
setUpdateErrors((prev) => ({ ...prev, [id]: "Todo cannot be empty" }));
return;
}
setUpdateErrors((prev) => ({ ...prev, [id]: null }));
}; };
const handleToggleComplete = async (id, completed) => { const handleToggleComplete = async (id, completed) => {
const updatedTodo = todo.find((item) => item.id === id); const updatedTodo = todo.find((item) => item.id === id);
if (!updatedTodo) return; if (!updatedTodo) return;
const newTodo = { ...updatedTodo, completed }; const newTodo = { ...updatedTodo, completed };
await axios.put(`${API_URL}/${id}`, newTodo); await axios.put(`${URL}/${id}`, newTodo);
setTodo(todo.map((item) => setTodo(todo.map((item) =>
item.id === id ? { ...item, completed } : item item.id === id ? { ...item, completed } : item
...@@ -66,7 +82,16 @@ function App() { ...@@ -66,7 +82,16 @@ function App() {
checked={item.completed} checked={item.completed}
onChange={() => handleToggleComplete(item.id, !item.completed)} onChange={() => handleToggleComplete(item.id, !item.completed)}
/> />
<span <input type="text" value={item.text} className="todo-content" style={{width:"100%",border:"none",textDecoration: item.completed ? "line-through" : "none"}} onChange={(e)=>{
handleUpdate(item.id,e.target.value);
}}/>
{updateErrors[item.id] && (
<div className="error">
{updateErrors[item.id]}
</div>
)}
{/* <span
style={{ textDecoration: item.completed ? "line-through" : "none" }} style={{ textDecoration: item.completed ? "line-through" : "none" }}
className="editable-text" className="editable-text"
contentEditable contentEditable
...@@ -74,7 +99,7 @@ function App() { ...@@ -74,7 +99,7 @@ function App() {
onBlur={(e) => handleUpdate(item.id, e.target.textContent)} onBlur={(e) => handleUpdate(item.id, e.target.textContent)}
> >
{item.text} {item.text}
</span> </span> */}
<button> <button>
<TiDelete <TiDelete
className="deletebutton" className="deletebutton"
...@@ -87,14 +112,16 @@ function App() { ...@@ -87,14 +112,16 @@ function App() {
)} )}
<form onSubmit={handleSubmit}> <form onSubmit={handleSubmit}>
<input <input
type="text" type="text"
value={input} value={input}
className="formtext" className="formtext"
placeholder="Enter Item" placeholder={error ? error : "Enter Item"}
onChange={(e) => setInput(e.target.value)} onChange={(e) => setInput(e.target.value)}
/> style={{ border: error ? "1px solid red" : undefined }}
<button type="submit">Submit</button> />
<button type="submit" >Submit</button>
</form> </form>
</div> </div>
); );
......
{ {
"todos": [ "todos": [
{ {
"id": "e05e", "id": "b924",
"text": "Buy Groceries Tomorrowsdfgfdsdfgsdfgsdfgsdf  gsdfgsdfgsdfgsdfgsdfgsdfgsdfgdfg sdfgsdfgsdfgsd fgsdfgsdfgsdfgsdfgsdfsfdfdgsfdg  fsdfgsdfgsdfgsdfgsdfgdsg", "text": "Buy Groceries tomorrow",
"completed": false "completed": false
}, },
{ {
"id": "54ef", "id": "9166",
"text": "Travel to Head Office", "text": "Travel to Head office",
"completed": false
},
{
"id": "d7f1",
"text": "Get Phone from the repair shop",
"completed": false "completed": false
} }
] ]
......
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