generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 224
London | 26-ITP-Jan | Abdul Moiz | Sprint 3 | ToDo List #952
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
A-Moiz
wants to merge
1
commit into
CodeYourFuture:main
Choose a base branch
from
A-Moiz:todo-list
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.
+117
−57
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,55 @@ | ||
| <!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> | ||
| <div class="todo-input"> | ||
| <input | ||
| type="text" | ||
| id="new-task-input" | ||
| placeholder="Enter a new task..." | ||
| /> | ||
| <input type="date" id="new-task-deadline" /> | ||
| <button id="add-task-btn">Add</button> | ||
| </div> | ||
|
|
||
| <ul id="todo-list" class="todo-list"> | ||
| </ul> | ||
| <ul id="todo-list" class="todo-list"></ul> | ||
|
|
||
| <!-- | ||
| <!-- | ||
| 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> | ||
| <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> | ||
| <button class="clear-completed" id="clear-completed"> | ||
| Delete completed tasks | ||
| </button> | ||
| </div> | ||
| </body> | ||
| </html> | ||
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // Store everything imported from './todos.mjs' module as properties of an object named Todos | ||
| // Store everything imported from './todos.mjs' module as properties of an object named Todos | ||
| import * as Todos from "./todos.mjs"; | ||
|
|
||
| // To store the todo tasks | ||
|
|
@@ -7,26 +7,31 @@ 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("clear-completed") | ||
| .addEventListener("click", deleteCompletedTasks); | ||
|
|
||
| // Populate sample data | ||
| Todos.addTask(todos, "Wash the dishes", false); | ||
| Todos.addTask(todos, "Wash the dishes", false); | ||
| Todos.addTask(todos, "Do the shopping", true); | ||
|
|
||
| render(); | ||
| }); | ||
|
|
||
|
|
||
| // A callback that reads the task description from an input field and | ||
| // A callback that reads the task description from an input field and | ||
| // 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) { | ||
|
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. This works. To improve the user experience, please throw an error to the user if there is no valid input (task in this case). |
||
| Todos.addTask(todos, task, false); | ||
| Todos.addTask(todos, task, false, deadline); | ||
| render(); | ||
| } | ||
|
|
||
| taskInput.value = ""; | ||
| deadlineInput.value = ""; | ||
| } | ||
|
|
||
| // Note: | ||
|
|
@@ -45,32 +50,40 @@ function render() { | |
| }); | ||
| } | ||
|
|
||
|
|
||
| // Note: | ||
| // - First child of #todo-item-template is a <li> element. | ||
| // We will create each ToDo list item as a clone of this node. | ||
| // - This variable is declared here to be close to the only function that uses it. | ||
| const todoListItemTemplate = | ||
| const todoListItemTemplate = | ||
| document.getElementById("todo-item-template").content.firstElementChild; | ||
|
|
||
| // Create a <li> element for the given todo task | ||
| function createListItem(todo, index) { | ||
| const li = todoListItemTemplate.cloneNode(true); // true => Do a deep copy of the node | ||
| const deadline = li.querySelector(".deadline"); | ||
| if (todo.deadline && !todo.completed) { | ||
| deadline.textContent = `Deadline: ${todo.deadline}`; | ||
| } | ||
|
|
||
| li.querySelector(".description").textContent = todo.task; | ||
| if (todo.completed) { | ||
| li.classList.add("completed"); | ||
| } | ||
|
|
||
| li.querySelector('.complete-btn').addEventListener("click", () => { | ||
| li.querySelector(".complete-btn").addEventListener("click", () => { | ||
| Todos.toggleCompletedOnTask(todos, index); | ||
| render(); | ||
| }); | ||
| li.querySelector('.delete-btn').addEventListener("click", () => { | ||
|
|
||
| li.querySelector(".delete-btn").addEventListener("click", () => { | ||
| Todos.deleteTask(todos, index); | ||
| render(); | ||
| }); | ||
|
|
||
| return li; | ||
| } | ||
| } | ||
|
|
||
| function deleteCompletedTasks() { | ||
| Todos.deleteCompleted(todos); | ||
| render(); | ||
| } | ||
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
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.
This works fine, and I know you are doing some validation with JavaScript. But since this is a required field, you can do some validation with HTML only. Check on how to do simple validation on input fields using HTML.