-
-
Notifications
You must be signed in to change notification settings - Fork 321
Birmingham | 26-ITP-May | Tobias Amaechina | Sprint 3 | Sprint-3/todo-list #1327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Tobias-Amaechina
wants to merge
16
commits into
CodeYourFuture:main
Choose a base branch
from
Tobias-Amaechina:group-data-sprint-todo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
924fde0
Added a button id for deletedcompleted job in the index .html file
Tobias-Amaechina 3c084ca
implement the function deleteCompleted to handle the deletion of mas…
Tobias-Amaechina 9455547
Add a click listener to the window button in script.mjs file
Tobias-Amaechina ff96587
Declare the function to handle deletion of completed task
Tobias-Amaechina ee44b03
Install the package.json
Tobias-Amaechina 9e82873
Wrote a test to check that the implemention deletedcompleted task p…
Tobias-Amaechina 56d0053
update the template to have date picker Id
Tobias-Amaechina 902445b
extended the addtask function to include deadline
Tobias-Amaechina 60f6e05
update the addNewTodo() to include deadline when creating task
Tobias-Amaechina 03d89a6
Updated sample data to handle deadline
Tobias-Amaechina 074dd2c
Added a span for deadline in the template file
Tobias-Amaechina 251083e
set deadline text in the script.mjs file
Tobias-Amaechina fd329c5
Add helper function to show the remaining days
Tobias-Amaechina 85a63c8
Updated list item of deadline to handle remaing days
Tobias-Amaechina 71aac32
Wrote a test to pass Deadline feature
Tobias-Amaechina fe7adc4
Merge branch 'main' into group-data-sprint-todo
Tobias-Amaechina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -7,10 +7,14 @@ const todos = []; | |
| // Set up tasks to be performed once on page load | ||
| window.addEventListener("load", () => { | ||
| document.getElementById("add-task-btn").addEventListener("click", addNewTodo); | ||
| document.getElementById("delete-completed-btn") | ||
| .addEventListener("click", deleteCompletedTodos); | ||
|
|
||
|
|
||
| // Populate sample data | ||
| Todos.addTask(todos, "Wash the dishes", false); | ||
| Todos.addTask(todos, "Do the shopping", true); | ||
| Todos.addTask(todos, "Wash the dishes", false, null); | ||
| Todos.addTask(todos, "Do the shopping", true, "2026-07-30"); | ||
|
|
||
|
|
||
| render(); | ||
| }); | ||
|
|
@@ -20,15 +24,31 @@ window.addEventListener("load", () => { | |
| // append a new task to the todo list. | ||
| function addNewTodo() { | ||
| const taskInput = document.getElementById("new-task-input"); | ||
| const deadlineInput = document.getElementById("new-task-deadline"); | ||
|
|
||
| const task = taskInput.value.trim(); | ||
| const deadline = deadlineInput.value || null; | ||
|
|
||
| if (task) { | ||
| Todos.addTask(todos, task, false); | ||
| Todos.addTask(todos, task, false, deadline); | ||
| render(); | ||
| } | ||
|
|
||
| taskInput.value = ""; | ||
| deadlineInput.value = ""; | ||
| } | ||
|
|
||
| function deleteCompletedTodos() { | ||
| const newTodos = Todos.deleteCompleted(todos); | ||
|
|
||
| // Replace the old array contents | ||
| todos.length = 0; | ||
| todos.push(...newTodos); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not perform the operations on lines 45-46 in |
||
| render(); | ||
| } | ||
|
|
||
|
|
||
| // Note: | ||
| // - Store the reference to the <ul> element with id "todo-list" here | ||
| // to avoid querying the DOM repeatedly inside render(). | ||
|
|
@@ -52,6 +72,28 @@ function render() { | |
| // - This variable is declared here to be close to the only function that uses it. | ||
| const todoListItemTemplate = | ||
| document.getElementById("todo-item-template").content.firstElementChild; | ||
| function getDaysRemainingText(deadline) { | ||
| if (!deadline) return ""; | ||
|
|
||
| const today = new Date(); | ||
| today.setHours(0, 0, 0, 0); | ||
|
|
||
| const deadlineDate = new Date(deadline); | ||
| deadlineDate.setHours(0, 0, 0, 0); | ||
|
|
||
| const msPerDay = 1000 * 60 * 60 * 24; | ||
| const diffDays = Math.round((deadlineDate - today) / msPerDay); | ||
|
|
||
| if (diffDays === 0) { | ||
| return "Due today"; | ||
| } else if (diffDays > 0) { | ||
| return `${diffDays} day${diffDays === 1 ? "" : "s"} left`; | ||
| } else { | ||
| const overdueDays = Math.abs(diffDays); | ||
| return `Overdue by ${overdueDays} day${overdueDays === 1 ? "" : "s"}`; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // Create a <li> element for the given todo task | ||
| function createListItem(todo, index) { | ||
|
|
@@ -61,6 +103,13 @@ function createListItem(todo, index) { | |
| if (todo.completed) { | ||
| li.classList.add("completed"); | ||
| } | ||
| const deadlineEl = li.querySelector(".deadline"); | ||
| if (todo.deadline) { | ||
| deadlineEl.textContent = getDaysRemainingText(todo.deadline); | ||
| } else { | ||
| deadlineEl.textContent = ""; | ||
| } | ||
|
|
||
|
|
||
| li.querySelector('.complete-btn').addEventListener("click", () => { | ||
| Todos.toggleCompletedOnTask(todos, index); | ||
|
|
||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is off.