-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
52 lines (43 loc) · 1.57 KB
/
main.js
File metadata and controls
52 lines (43 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Task, TaskManager } from "./task.js";
import { updateScreenwithTasks } from "./dom.js";
let taskManager = new TaskManager();
// Adding event listener for the "Add Task" button
const addBtn = document.getElementById("addBtn");
addBtn.addEventListener("click", () => {
const taskName = document.getElementById("taskName").value;
const taskDesc = document.getElementById("taskDesc").value;
// Debugging line to check input values
console.log("Adding task with name:", taskName, "and description:", taskDesc);
// Only add the task if both fields are filled
if (taskName && taskDesc) {
taskManager.addTask(taskName, taskDesc, false);
displayTasks(); // Display updated task list
// Clear the input fields after adding the task
document.getElementById("taskName").value = "";
document.getElementById("taskDesc").value = "";
}
});
// Handle delete and update of tasks
function handleDeleteTask(id) {
console.log("Handling delete for task ID:", id); // Debugging line
taskManager.deleteTask(id);
displayTasks();
}
function handleUpdateTask(id, newName, newDescription) {
console.log(
"Handling update for task ID:",
id,
"New name:",
newName,
"New description:",
newDescription
); // Debugging line
taskManager.updateTask(id, newName, newDescription);
displayTasks();
}
function displayTasks() {
const tasks = taskManager.getAllTask();
console.log("Displaying tasks:", tasks); // Debugging line
updateScreenwithTasks(tasks, handleDeleteTask, handleUpdateTask);
}
displayTasks(); // Initial call to display tasks if any