diff --git a/frontend/index.html b/frontend/index.html index 915426f..d2ced7f 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -12,6 +12,12 @@

Task List

+
diff --git a/frontend/script.js b/frontend/script.js index a519ccf..f88ca03 100644 --- a/frontend/script.js +++ b/frontend/script.js @@ -2,7 +2,9 @@ const API_URL = 'http://localhost:3000/api/tasks'; const taskList = document.getElementById('taskList'); const taskForm = document.getElementById('taskForm'); const taskInput = document.getElementById('taskInput'); +const taskFilter = document.getElementById('taskFilter'); const themeToggle = document.getElementById('themeToggle'); +let currentTasks = []; // Theme functionality function initTheme() { @@ -29,9 +31,16 @@ initTheme(); async function fetchTasks() { const res = await fetch(API_URL); - const tasks = await res.json(); + currentTasks = await res.json(); + renderTasks(); +} + +function renderTasks() { + const filterValue = taskFilter.value.trim().toLowerCase(); taskList.innerHTML = ''; - tasks.forEach(addTaskToDOM); + currentTasks + .filter(task => task.title.toLowerCase().includes(filterValue)) + .forEach(addTaskToDOM); } function addTaskToDOM(task) { @@ -55,10 +64,13 @@ taskForm.addEventListener('submit', async e => { body: JSON.stringify({ title }) }); const task = await res.json(); - addTaskToDOM(task); + currentTasks.push(task); + renderTasks(); taskInput.value = ''; }); +taskFilter.addEventListener('input', renderTasks); + async function toggleComplete(id, completed) { await fetch(`${API_URL}/${id}`, { method: 'PUT', diff --git a/frontend/style.css b/frontend/style.css index d351594..8535e47 100644 --- a/frontend/style.css +++ b/frontend/style.css @@ -103,6 +103,23 @@ form { #taskInput:focus { box-shadow: 0 2px 8px var(--input-focus-shadow); } +#taskFilter { + width: 100%; + box-sizing: border-box; + margin-bottom: 1em; + padding: 0.75em 1em; + border: none; + border-radius: 4px; + background: var(--input-bg); + color: var(--text-color); + box-shadow: 0 1px 2px var(--input-shadow); + font-size: 1em; + outline: none; + transition: box-shadow 0.2s; +} +#taskFilter:focus { + box-shadow: 0 2px 8px var(--input-focus-shadow); +} button[type="submit"] { background: var(--primary-color); color: #fff;