Repository navigation
Manchester | 26-ITP-Sep | Precious Moses | Sprint 3 | Todo list #1523
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
base: main
Are you sure you want to change the base?
Changes from all commits
3b4ae69
c2e02c1
4e8361c
36b055f
fb01341
fe74b0a
ca95b41
d300a88
23683f9
3f29e85
cfa258e
e7ef918
794e8ba
b7b9be1
a78ca87
178fd7b
0e9a900
b088ca0
066ae04
c302acb
c1b510f
4ec3342
413ad50
438dbff
ab1448e
ecbf2f4
31d069d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,52 @@ | ||
| <!DOCTYPE html> | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"/> | ||
| <title>ToDo List</title> | ||
| <link rel="stylesheet" href="style.css" /> | ||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>ToDo List</title> | ||
| <link rel="stylesheet" href="style.css" /> | ||
| <link | ||
| href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" | ||
| rel="stylesheet" | ||
| /> | ||
|
|
||
| <script type="module" src="script.mjs"></script> | ||
| </head> | ||
| <body> | ||
| <div class="todo-container"> | ||
| <h1>My ToDo List</h1> | ||
| <script type="module" src="script.mjs"></script> | ||
| </head> | ||
| <body> | ||
| <div class="todo-container"> | ||
| <h1>My ToDo List</h1> | ||
|
|
||
| <div class="todo-input"> | ||
| <input type="text" id="new-task-input" placeholder="Enter a new task..." /> | ||
| <button id="add-task-btn">Add</button> | ||
| </div> | ||
|
|
||
| <ul id="todo-list" class="todo-list"> | ||
| </ul> | ||
| <div class="todo-input"> | ||
| <label for="new-task-input" class="visually-hidden">Task</label> | ||
| <input | ||
| type="text" | ||
| id="new-task-input" | ||
| placeholder="Enter a new task..." | ||
| /> | ||
| <label for="new-task-deadline" class="visually-hidden" | ||
| >Deadline (optional)</label | ||
| > | ||
| <input type="date" id="new-task-deadline" /> | ||
| <button id="add-task-btn">Add</button> | ||
| </div> | ||
|
|
||
| <!-- | ||
| This is a template for the To-do list item. | ||
| It can simplify the creation of list item node in JS script. | ||
| --> | ||
| <template id="todo-item-template"> | ||
| <li class="todo-item"> <!-- include class "completed" if the task completed state is true --> | ||
| <span class="description">Task description</span> | ||
| <div class="actions"> | ||
| <button class="complete-btn"><span class="fa-solid fa-check" aria-hidden="true"></span></button> | ||
| <button class="delete-btn"><span class="fa-solid fa-trash" aria-hidden="true"></span></button> | ||
| </div> | ||
| </li> | ||
| </template> | ||
| <ul id="todo-list" class="todo-list"></ul> | ||
| <button id="delete-completed-btn">Delete completed tasks</button> | ||
|
|
||
| </div> | ||
| </body> | ||
| <template id="todo-item-template"> | ||
| <li class="todo-item"> | ||
| <span class="description">Task description</span> | ||
| <span class="deadline"></span> | ||
| <div class="actions"> | ||
| <button class="complete-btn"> | ||
| <span class="fa-solid fa-check" aria-hidden="true"></span> | ||
| </button> | ||
| <button class="delete-btn"> | ||
| <span class="fa-solid fa-trash" aria-hidden="true"></span> | ||
| </button> | ||
| </div> | ||
| </li> | ||
| </template> | ||
| </div> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,8 +10,12 @@ | |
| */ | ||
|
|
||
| // Append a new task to todos[] | ||
| export function addTask(todos, task, completed = false) { | ||
| todos.push({ task, completed }); | ||
| export function addTask(todos, task, completed = false, deadline) { | ||
| const todo = { task, completed }; | ||
| if (deadline) { | ||
| todo.deadline = deadline; | ||
| } | ||
| todos.push(todo); | ||
| } | ||
|
|
||
| // Delete todos[taskIndex] if it exists | ||
|
|
@@ -26,4 +30,46 @@ export function toggleCompletedOnTask(todos, taskIndex) { | |
| if (todos[taskIndex]) { | ||
| todos[taskIndex].completed = !todos[taskIndex].completed; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Remove every task whose "completed" property is true | ||
| export function deleteCompleted(todos) { | ||
| for (let i = todos.length - 1; i >= 0; i--) { | ||
| if (todos[i].completed) { | ||
| todos.splice(i, 1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export function daysLeft(deadline, today = new Date()) { | ||
| const [year, month, day] = deadline.split("-").map(Number); | ||
| const deadlineDate = new Date(year, month - 1, day); | ||
|
|
||
| if ( | ||
| deadlineDate.getFullYear() !== year || | ||
| deadlineDate.getMonth() !== month - 1 || | ||
| deadlineDate.getDate() !== day | ||
| ) { | ||
| return NaN; | ||
| } | ||
|
|
||
| const todaysDate = new Date( | ||
|
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. What does To "like" or "dislike" this comment, please follow this link
Author
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. For date:
Author
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. I have refactored my code to handle invalid dates and added a test for it. |
||
| today.getFullYear(), | ||
| today.getMonth(), | ||
| today.getDate() | ||
| ); | ||
| const MS_PER_DAY = 24 * 60 * 60 * 1000; | ||
|
|
||
| return Math.round((deadlineDate - todaysDate) / MS_PER_DAY); | ||
| } | ||
|
|
||
| export function describeDeadline(deadline, today = new Date()) { | ||
| const days = daysLeft(deadline, today); | ||
|
|
||
| if (Number.isNaN(days)) return "Invalid date"; | ||
| if (days < 0) return `Overdue by ${-days} day${days === -1 ? "" : "s"}`; | ||
| if (days === 0) return "Due today"; | ||
|
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. What text does this branch produce when a deadline was yesterday? To "like" or "dislike" this comment, please follow this link
Author
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. It returns |
||
| if (days === 1) return "Due tomorrow"; | ||
|
|
||
| return `${days} days left`; | ||
| } | ||
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.
What accessible name does this new date input expose to someone using a screen reader?
To "like" or "dislike" this comment, please follow this link
Uh oh!
There was an error while loading. Please reload this page.
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.
It exposes nothing as the date input has no accessible name, so a screen reader only announces its type without saying what the field is for.
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.
I have refactored my code for screen users accessibility.