From 4ad4455172252707968d443cb37d4f36e67c46a2 Mon Sep 17 00:00:00 2001 From: Abhishek-Prasad-git Date: Thu, 12 Dec 2024 13:17:21 +0530 Subject: [PATCH] Added to todo_list --- src/Components/TodoList.jsx | 95 +++++++++++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 21 deletions(-) diff --git a/src/Components/TodoList.jsx b/src/Components/TodoList.jsx index a3f8bffe..4bf7c4e8 100644 --- a/src/Components/TodoList.jsx +++ b/src/Components/TodoList.jsx @@ -2,27 +2,80 @@ import React, { useState } from 'react'; import './TodoList.css'; const TodoList = () => { - + const [todos, setTodos] = useState([]); + const [headingInput, setHeadingInput] = useState(''); + const [listInputs, setListInputs] = useState({}); - return ( - <> -
-

My Todo List

-
- - -
-
-
- -
- - ); + const handleAddTodo = () => { + if (headingInput.trim() !== '') { + setTodos([...todos, { heading: headingInput, lists: [] }]); + setHeadingInput(''); + } + }; + + const handleDeleteTodo = (index) => { + const newTodos = [...todos]; + newTodos.splice(index, 1); + setTodos(newTodos); + }; + + const handleAddList = (index) => { + if (listInputs[index] && listInputs[index].trim() !== '') { + const newTodos = [...todos]; + newTodos[index].lists.push(listInputs[index]); + setTodos(newTodos); + setListInputs({ ...listInputs, [index]: '' }); + } + }; + + const handleListInputChange = (index, value) => { + setListInputs({ ...listInputs, [index]: value }); + }; + + return ( + <> +
+

My Todo List

+
+ setHeadingInput(e.target.value)} + /> + +
+
+
+ {todos.map((todo, index) => ( +
+
+

{todo.heading}

+ +
+
    + {todo.lists.map((list, listIndex) => ( +
  • +

    {list}

    +
  • + ))} +
+
+ handleListInputChange(index, e.target.value)} + /> + +
+
+ ))} +
+ + ); }; -export default TodoList; +export default TodoList; \ No newline at end of file