diff --git a/src/Components/TodoList.jsx b/src/Components/TodoList.jsx index a3f8bffe..d27eb973 100644 --- a/src/Components/TodoList.jsx +++ b/src/Components/TodoList.jsx @@ -1,8 +1,37 @@ -import React, { useState } from 'react'; +import { useState } from 'react'; import './TodoList.css'; const TodoList = () => { + const [todos, setTodos] = useState([]); + const [headingInput, setHeadingInput] = useState(''); + const [listInputs, setListInputs] = useState({}); + + const handleAddTodo = () => { + if (headingInput.trim() !== '') { + setTodos([...todos, { heading: headingInput, lists: [] }]); + setHeadingInput(''); + } + }; + + 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}); + } + + const handleDeleteTodo = (index) =>{ + const newTodos = [...todos]; + newTodos.splice(index, 1); + setTodos(newTodos); + }; return ( <> @@ -13,13 +42,38 @@ const TodoList = () => { type="text" className="heading-input" placeholder="Enter heading" - + value={headingInput} + onChange={(e)=>{setHeadingInput(e.target.value);}} /> - +
- + {todos.map((todo, index) => ( +
+
+

{todo.heading}

{/* Display the heading here */} + +
+ +
+ handleListInputChange(index, e.target.value)} + /> + +
+
+ ))}
);