Skip to content

Commit

Permalink
feat: Search tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
bentinata committed Jul 6, 2024
1 parent b0cf1b5 commit bd27406
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function App() {
status: "COMPLETED",
},
]);
const [search, setSearch] = useState("");

function addTask() {
const newTask: Task = {
Expand All @@ -18,6 +19,10 @@ function App() {
setTasks((prevTasks) => [...prevTasks, newTask]);
}

function filterTask() {
return tasks.filter((task) => task.title.includes(search));
}

function deleteTask(deletedTitle: string) {
setTasks((prevTasks) =>
prevTasks.filter((task) => task.title !== deletedTitle),
Expand All @@ -34,9 +39,13 @@ function App() {

return (
<>
<input
placeholder="Input task name"
onChange={(e) => setSearch(e.target.value)}
></input>
<button onClick={addTask}>Add task</button>
<TaskList
tasks={tasks}
tasks={filterTask()}
onDelete={deleteTask}
onCompleted={completeTask}
/>
Expand Down

0 comments on commit bd27406

Please sign in to comment.