generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 193
West Midlands | ITP-Sept-2025 | Ali Naru | Sprint 3 | Todo list #893
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
MohammedNaru
wants to merge
2
commits into
CodeYourFuture:main
Choose a base branch
from
MohammedNaru: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.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,45 @@ | ||
| <!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"> | ||
|
|
||
| <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> | ||
|
|
||
| <!-- | ||
| 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> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| <title>To Do List App</title> | ||
| <link | ||
| href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" | ||
| rel="stylesheet" | ||
| /> | ||
| <link rel="stylesheet" href="style.css" /> | ||
| <link | ||
| rel="stylesheet" | ||
| href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" | ||
| /> | ||
| </head> | ||
| <body> | ||
| <div class="todo-container"> | ||
| <form onsubmit="addNewTodo(event)" id="todo-form"> | ||
| <div> | ||
| <input | ||
| id="todoInput" | ||
| type="text" | ||
| placeholder="New todo..." | ||
| class="form-control" | ||
| /> | ||
| </div> | ||
| <div> | ||
| <button type="button" id="add-btn" class="btn btn-primary mt-2"> | ||
| Add Todo | ||
| </button> | ||
| <button | ||
| type="button" | ||
| id="remove-all-completed" | ||
| class="btn btn-danger mt-2" | ||
| > | ||
| Remove all completed | ||
| </button> | ||
| </div> | ||
| </li> | ||
| </template> | ||
|
|
||
| </div> | ||
| </body> | ||
| </html> | ||
| </form> | ||
| <ul id="todo-list" class="list-group mt-3"></ul> | ||
| </div> | ||
| <script src="script.js"></script> | ||
| </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 |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| function toggleTodoCompletion(todo) { | ||
| todo.completed = !todo.completed; | ||
| } | ||
|
|
||
| function removeTodo(todos, todo) { | ||
| return todos.filter((t) => t !== todo); | ||
| } | ||
|
|
||
| function deleteAllCompletedTodos() { | ||
| todos = todos.filter((todo) => !todo.completed); | ||
| populateTodoList(todos); | ||
| } | ||
|
|
||
| function createTodoElement(todo, todos) { | ||
| let li = document.createElement("li"); | ||
| li.textContent = todo.task; | ||
| li.className = `list-group-item ${todo.completed ? "completed" : ""}`; | ||
|
|
||
| let span = document.createElement("span"); | ||
| span.className = "badge bg-light rounded-pill"; | ||
|
|
||
| let checkIcon = document.createElement("i"); | ||
| checkIcon.className = "fa fa-check todo-icon"; | ||
| checkIcon.setAttribute("aria-hidden", "true"); | ||
| checkIcon.addEventListener("click", () => { | ||
| toggleTodoCompletion(todo); | ||
| li.classList.toggle("completed"); | ||
| }); | ||
|
|
||
| let trashIcon = document.createElement("i"); | ||
| trashIcon.className = "fa fa-trash todo-icon"; | ||
| trashIcon.setAttribute("aria-hidden", "true"); | ||
| trashIcon.addEventListener("click", () => { | ||
| todos = removeTodo(todos, todo); | ||
|
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. Line 34 only assigns an array to the local variable |
||
| populateTodoList(todos); | ||
| }); | ||
|
|
||
| span.appendChild(checkIcon); | ||
| span.appendChild(trashIcon); | ||
| li.appendChild(span); | ||
|
|
||
| return li; | ||
| } | ||
|
|
||
| function populateTodoList(todos) { | ||
| let list = document.getElementById("todo-list"); | ||
| list.innerHTML = ""; | ||
| todos.forEach((todo) => { | ||
| list.appendChild(createTodoElement(todo, todos)); | ||
| }); | ||
| } | ||
|
|
||
| let todos = [ | ||
| { task: "Wash the dishes", completed: false }, | ||
| { task: "Do the shopping", completed: false }, | ||
| ]; | ||
|
|
||
| function addNewTodo(event) { | ||
| event.preventDefault(); | ||
| let input = document.getElementById("todoInput"); | ||
| let newTask = input.value.trim(); | ||
|
|
||
| if (newTask === "") { | ||
| alert("Input field cannot be empty."); | ||
| return; | ||
| } | ||
|
|
||
| if (/[^A-Za-z\s]/.test(newTask)) { | ||
| alert("Please enter letters and spaces only."); | ||
| input.value = ""; | ||
| return; | ||
| } | ||
|
|
||
| todos.push({ task: newTask, completed: false }); | ||
| populateTodoList(todos); | ||
| input.value = ""; | ||
| } | ||
|
|
||
| document.getElementById("add-btn").addEventListener("click", addNewTodo); | ||
| document | ||
| .getElementById("remove-all-completed") | ||
| .addEventListener("click", deleteAllCompletedTodos); | ||
|
|
||
| populateTodoList(todos); | ||
This file was deleted.
Oops, something went wrong.
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,107 +1,65 @@ | ||
| * { | ||
| box-sizing: border-box; | ||
| margin: 0; | ||
| padding: 0; | ||
| font-family: Arial, sans-serif; | ||
| .completed { | ||
| text-decoration: line-through; | ||
| color: gray; | ||
| } | ||
|
|
||
| body { | ||
| background-color: #f4f4f4; | ||
| padding: 40px; | ||
| .todo-icon { | ||
| cursor: pointer; | ||
| margin-left: 8px; | ||
| font-size: 1.2rem; | ||
| padding: 8px; | ||
| color: inherit; | ||
| } | ||
|
|
||
| .todo-container { | ||
| max-width: 500px; | ||
| margin: 0 auto; | ||
| background: white; | ||
| border-radius: 10px; | ||
| padding: 20px; | ||
| box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); | ||
| .completed .fa-check { | ||
| color: green; | ||
| } | ||
|
|
||
| .todo-icon:hover { | ||
| opacity: 0.7; | ||
| } | ||
|
|
||
| h1 { | ||
| .todo-container { | ||
| max-width: 400px; | ||
| margin: 50px auto; | ||
| text-align: center; | ||
| margin-bottom: 20px; | ||
| } | ||
|
|
||
| .todo-input { | ||
| display: flex; | ||
| gap: 10px; | ||
| margin-bottom: 20px; | ||
| .todo-container form > div { | ||
| margin-bottom: 15px; | ||
| } | ||
|
|
||
| .todo-input input { | ||
| flex: 1; | ||
| #todoInput { | ||
| width: 100%; | ||
| padding: 10px; | ||
| font-size: 16px; | ||
| border-radius: 6px; | ||
| border: 1px solid #ccc; | ||
| font-size: 1rem; | ||
| } | ||
|
|
||
| .todo-input button { | ||
| padding: 10px 20px; | ||
| font-size: 16px; | ||
| background-color: #4CAF50; | ||
| color: white; | ||
| border: none; | ||
| border-radius: 6px; | ||
| button { | ||
| border-radius: 5px; | ||
| padding: 12px 20px; | ||
| font-size: 1rem; | ||
| cursor: pointer; | ||
| min-height: 44px; | ||
| } | ||
|
|
||
| .todo-input button:hover { | ||
| background-color: #45a049; | ||
| } | ||
|
|
||
| .todo-list { | ||
| list-style-type: none; | ||
| padding-left: 0; | ||
| button:hover { | ||
| opacity: 0.9; | ||
| } | ||
|
|
||
| .todo-item { | ||
| .list-group-item { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: space-between; | ||
| padding: 12px 10px; | ||
| margin-bottom: 10px; | ||
| border: 1px solid #ddd; | ||
| border-radius: 6px; | ||
| background-color: #fff; | ||
| } | ||
|
|
||
| .description { | ||
| flex: 1; | ||
| margin-right: 10px; | ||
| white-space: nowrap; | ||
| overflow: hidden; | ||
| text-overflow: ellipsis; | ||
| } | ||
|
|
||
| .actions { | ||
| display: flex; | ||
| gap: 10px; | ||
| } | ||
|
|
||
| .actions button { | ||
| background: none; | ||
| border: none; | ||
| cursor: pointer; | ||
| font-size: 18px; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| width: 32px; | ||
| height: 32px; | ||
| padding: 10px 15px; | ||
| margin-bottom: 8px; | ||
| } | ||
|
|
||
| .complete-btn i { | ||
| color: green; | ||
| } | ||
|
|
||
| .delete-btn i { | ||
| color: red; | ||
| } | ||
|
|
||
| .todo-item.completed .description { | ||
| text-decoration: line-through; | ||
| color: gray; | ||
| } | ||
| .badge { | ||
| display: flex; | ||
| gap: 8px; | ||
| padding: 6px 10px; | ||
| background-color: #f8f9fa; | ||
| color: #000; | ||
| border-radius: 50px; | ||
| } |
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.
.filter()creates a new array. The originaltodos[]is not updated accordingly.