Skip to content

Commit

Permalink
Merge pull request #38 from cse110-sp24-group25/delete-branch
Browse files Browse the repository at this point in the history
Add delete functionality
  • Loading branch information
qiwenkevin authored Apr 25, 2024
2 parents 77f8598 + 1f2e775 commit 98bc5bd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
3 changes: 3 additions & 0 deletions task-list/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<link rel="stylesheet" href="styles/index.css">
</head>
<body>
<div class="main-body">
<main>
<h1 class="title">Tasks</h1>
<div class="insert-task-manually">
Expand All @@ -24,4 +25,6 @@ <h1 class="title">Tasks</h1>
</main>
</body>
<script src="scripts/index.js"></script>
<button>Delete Selected Task</button>
</div>
</html>
30 changes: 26 additions & 4 deletions task-list/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ function addJSONData() {
taskList.appendChild(newTask);
newTask.insertAdjacentHTML("afterbegin",
`
<input type="checkbox" id="toggle-btn">
<input type="checkbox" id="toggle-btn" onclick="updateCompleted(this)">
<label for="toggle-btn">Mark as Complete</label>
<p>${task.name}</p>
<p>Due: ${task.deadline}</p>
<button type="delete">Delete</button>
<button type="delete" onclick="deleteCompleted()">Delete</button>
`
);
}
Expand All @@ -42,6 +42,27 @@ function addJSONData() {

addJSONData();

/**
* Deletes all tasks that are marked as completed from the task list
*/
function deleteCompleted() {
const taskList = document.querySelector(".task-list-flex");
let completedTask = document.querySelector(".completed");
while (completedTask !== null){
taskList.removeChild(completedTask);
completedTask = document.querySelector(".completed");
}
}

/**
* Toggles the "completed" class of the parent task of the checkbox
* @param checkbox
*/
function updateCompleted(checkbox) {
checkbox.parentElement.classList.toggle("completed");
}


// html has two boxes, one for deadline, and one for task?
/**
*
Expand All @@ -59,13 +80,14 @@ function addTask() {
const newTask = document.createElement("div");

newTask.setAttribute("class","task");
newTask.classList.add("completed");
taskList.appendChild(newTask);
newTask.insertAdjacentHTML("beforeend",
`<input type="checkbox" id="toggle-btn">
`<input type="checkbox" id="toggle-btn" onclick="updateCompleted(this)">
<label for="toggle-btn">Mark as Complete</label>
<p>${taskName.value}</p>
<p>Due: ${taskDeadline.value}</p>
<button type="delete">Delete</button>`
<button type="delete" onclick="deleteCompleted">Delete</button>`
);

taskName.value = "";
Expand Down

0 comments on commit 98bc5bd

Please sign in to comment.