-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
89 additions
and
59 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,50 @@ | ||
import InputForm from './components/InputForm' | ||
import InputForm from 'components/InputForm'; | ||
import TodoList from 'components/TodoList'; | ||
import { useState } from 'react'; | ||
|
||
const App = () => { | ||
const [tasks, setTasks] = useState([]); | ||
const [inputValue, setInputValue] = useState(''); | ||
|
||
const addTask = () => { | ||
if (inputValue.trim() !== '') { | ||
const newTask = { | ||
id: tasks.length + 1, | ||
title: inputValue, | ||
completed: false, | ||
}; | ||
setTasks([...tasks, newTask]); | ||
setInputValue(''); | ||
} | ||
}; | ||
|
||
const deleteTask = taskId => { | ||
const updatedTasks = tasks.filter(task => task.id !== taskId); | ||
setTasks(updatedTasks); | ||
}; | ||
|
||
const toggleTaskStatus = taskId => { | ||
const updatedTasks = tasks.map(task => | ||
task.id === taskId ? { ...task, completed: !task.completed } : task, | ||
); | ||
setTasks(updatedTasks); | ||
}; | ||
|
||
function App() { | ||
return ( | ||
<div style={{display: 'flex', justifyContent: 'center'}}> | ||
<InputForm/> | ||
<div className="todo-app"> | ||
<h1>TODO List</h1> | ||
<InputForm | ||
inputValue={inputValue} | ||
setInputValue={setInputValue} | ||
addTask={addTask} | ||
/> | ||
<TodoList | ||
tasks={tasks} | ||
toggleTaskStatus={toggleTaskStatus} | ||
deleteTask={deleteTask} | ||
/> | ||
</div> | ||
); | ||
} | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
import React from 'react'; | ||
|
||
const InputForm = () => { | ||
|
||
const InputForm = ({ inputValue, setInputValue, addTask }) => { | ||
return ( | ||
<form onSubmit={''}> | ||
<h3 style={{ display: 'flex', justifyContent: 'center'}}>To-Do</h3> | ||
<div className="add-task"> | ||
<input | ||
type="text" | ||
value={""} | ||
onChange={''} | ||
required | ||
type="text" | ||
value={inputValue} | ||
onChange={e => setInputValue(e.target.value)} | ||
placeholder="Enter task..." | ||
/> | ||
<button type="submit">Add</button> | ||
</form> | ||
<button onClick={addTask}>Add Task</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default InputForm; | ||
export default InputForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import TodoItem from './TodoItem'; | ||
|
||
const TodoList = ({ tasks, toggleTaskStatus, deleteTask }) => { | ||
return ( | ||
<div className="tasks"> | ||
{tasks.map(task => ( | ||
<TodoItem | ||
key={task.id} | ||
task={task} | ||
toggleTaskStatus={toggleTaskStatus} | ||
deleteTask={deleteTask} | ||
/> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default TodoList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters