-
-
Notifications
You must be signed in to change notification settings - Fork 283
London | 26-ITP-Jan | Carlos Abreu |Sprint 3 | Todo List #1147
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 6 commits
426d6eb
6b1ae1a
b7e0ecf
e529e16
3ad8ce9
3ca4d4b
00a584b
e3b382f
0c06712
1669629
958fcfe
196ca03
bf2eb25
fbca2df
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,152 @@ | ||
| <!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> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Todo List App</title> | ||
| <style> | ||
| body { | ||
| font-family: Arial, sans-serif; | ||
| max-width: 600px; | ||
| margin: 50px auto; | ||
| padding: 20px; | ||
| background-color: #f5f5f5; | ||
| } | ||
|
|
||
| h1 { | ||
| color: #333; | ||
| text-align: center; | ||
| } | ||
|
|
||
| .add-task-form { | ||
| background: white; | ||
| padding: 20px; | ||
| border-radius: 8px; | ||
| margin-bottom: 20px; | ||
| box-shadow: 0 2px 4px rgba(0,0,0,0.1); | ||
| } | ||
|
|
||
| .add-task-form input { | ||
| width: 100%; | ||
| padding: 10px; | ||
| margin: 10px 0; | ||
| border: 1px solid #ddd; | ||
| border-radius: 4px; | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| .add-task-form input[type="text"] { | ||
| font-size: 16px; | ||
| } | ||
|
|
||
| .add-task-form input[type="datetime-local"] { | ||
| font-size: 14px; | ||
| } | ||
|
|
||
| .add-task-form button { | ||
| width: 100%; | ||
| padding: 10px; | ||
| background-color: #4CAF50; | ||
| color: white; | ||
| border: none; | ||
| border-radius: 4px; | ||
| cursor: pointer; | ||
| font-size: 16px; | ||
| } | ||
|
|
||
| .add-task-form button:hover { | ||
| background-color: #45a049; | ||
| } | ||
|
|
||
| .todo-list { | ||
| background: white; | ||
| border-radius: 8px; | ||
| padding: 20px; | ||
| box-shadow: 0 2px 4px rgba(0,0,0,0.1); | ||
| } | ||
|
|
||
| .todo-item { | ||
| padding: 15px; | ||
| margin: 10px 0; | ||
| border: 1px solid #ddd; | ||
| border-radius: 4px; | ||
| display: flex; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| gap: 10px; | ||
| flex-wrap: wrap; | ||
| } | ||
|
|
||
| .todo-item span { | ||
| flex: 1; | ||
| word-break: break-word; | ||
| } | ||
|
|
||
| .completed { | ||
| background-color: #e8f5e8; | ||
| text-decoration: line-through; | ||
| color: #666; | ||
| } | ||
|
|
||
| .todo-item button { | ||
| padding: 5px 10px; | ||
| border: none; | ||
| border-radius: 4px; | ||
| cursor: pointer; | ||
| font-size: 14px; | ||
| } | ||
|
|
||
| .todo-item button:first-of-type { | ||
| background-color: #2196F3; | ||
| color: white; | ||
| } | ||
|
|
||
| .todo-item button:first-of-type:hover { | ||
| background-color: #0b7dda; | ||
| } | ||
|
|
||
| .todo-item button:last-of-type { | ||
| background-color: #f44336; | ||
| color: white; | ||
| } | ||
|
|
||
| .todo-item button:last-of-type:hover { | ||
| background-color: #da190b; | ||
| } | ||
|
|
||
| @media (max-width: 500px) { | ||
| .todo-item { | ||
| flex-direction: column; | ||
| align-items: stretch; | ||
| } | ||
|
|
||
| .todo-item button { | ||
| width: 100%; | ||
| margin: 5px 0; | ||
| } | ||
| } | ||
|
|
||
| .empty-message { | ||
| text-align: center; | ||
| color: #999; | ||
| padding: 20px; | ||
| } | ||
| </style> | ||
| </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> | ||
| <h1>📝 Todo List</h1> | ||
|
|
||
| <div class="add-task-form"> | ||
| <input type="text" id="taskInput" placeholder="Enter task description (e.g., Finish project report)"> | ||
| <input type="datetime-local" id="deadlineInput"> | ||
| <button id="addBtn">➕ Add Task</button> | ||
|
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. The add task button does not work for me. Nothing happens when I click it |
||
| </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> | ||
| </div> | ||
| </li> | ||
| </template> | ||
|
|
||
| </div> | ||
|
|
||
| <div class="todo-list"> | ||
| <h3>Your Tasks</h3> | ||
| <div id="todoList"></div> | ||
| </div> | ||
|
|
||
| <script type="module" src="web-app.js"></script> | ||
|
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 did you change the name of the script file? |
||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,27 +3,26 @@ | |
| the following manner: | ||
|
|
||
| [ | ||
| { task: "Description of task 1", completed: false}, | ||
| { task: "Description of task 2", completed: true} | ||
| { task: "Description of task 1", completed: false, deadline: null }, | ||
| { task: "Description of task 2", completed: true, deadline: "2026-12-31T23:59" } | ||
| ] | ||
|
|
||
| */ | ||
|
|
||
| // 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 = null) { | ||
|
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. How can a user choose a deadline for the task?
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. If addTask function had a deadline parameter but the function body doesn't actually use it (it still only creates { task, completed }), there are a few ways a user could choose a deadline: Modify the function to include deadline in the task object // Updated todos.mjs Then a user could specify a deadline when calling the function: // Pass deadline as the 4th parameter // Or with different deadlines 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. How would an end user call a function when using the web page?
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. That's an interesting question. Here's how I could build a web interface using HTML and CSS: <title>Todo List App</title> <style> .todo-item { margin: 10px 0; padding: 10px; border: 1px solid #ccc; } .completed { text-decoration: line-through; background-color: #e0ffe0; } button { margin-left: 10px; } </style>Todo ListJavaScript Frontend (web-app.js): // Import the todos module // Initialize empty todo list // DOM elements // Function to render the todo list to the page } // Add task function (connects UI to the todos module) } // Event listeners // Initial render The end users would interact adding a task with deadline: 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 didn't you commit this changes? At the moment the code includes parts that are not really functional. They should either be removed or additional code should be added to make it work
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. You're absolutely right! |
||
| todos.push({ task, completed, deadline }); | ||
| } | ||
|
|
||
| // Delete todos[taskIndex] if it exists | ||
| // Delete todos[taskIndex] | ||
| export function deleteTask(todos, taskIndex) { | ||
| if (todos[taskIndex]) { | ||
| todos.splice(taskIndex, 1); | ||
| } | ||
| } | ||
|
|
||
| // Toggle the "completed" property of todos[taskIndex] if the task exists. | ||
| // Toggle the "completed" property of todos[taskIndex] | ||
| export function toggleCompletedOnTask(todos, taskIndex) { | ||
| if (todos[taskIndex]) { | ||
| todos[taskIndex].completed = !todos[taskIndex].completed; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,15 +10,15 @@ import * as Todos from "./todos.mjs"; | |
| // Return a mock ToDo List data with exactly 4 elements. | ||
| function createMockTodos() { | ||
| return [ | ||
| { task: "Task 1 description", completed: true }, | ||
| { task: "Task 2 description", completed: false }, | ||
| { task: "Task 3 description", completed: true }, | ||
| { task: "Task 4 description", completed: false }, | ||
| { task: "Task 1 description", completed: true, deadline: "2026-04-01" }, | ||
| { task: "Task 2 description", completed: false, deadline: null }, | ||
| { task: "Task 3 description", completed: true, deadline: "2026-04-05" }, | ||
| { task: "Task 4 description", completed: false, deadline: null }, | ||
| ]; | ||
| } | ||
|
|
||
| // A mock task to simulate user input | ||
| const theTask = { task: "The Task", completed: false }; | ||
| const theTask = { task: "The Task", completed: false, deadline: null }; | ||
|
|
||
| describe("addTask()", () => { | ||
| test("Add a task to an empty ToDo list", () => { | ||
|
|
@@ -130,3 +130,44 @@ describe("toggleCompletedOnTask()", () => { | |
| }); | ||
| }); | ||
|
|
||
| describe("deleteCompleted()", () => { | ||
|
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. All 3 tests fail for me with the error "Todos.deleteCompleted is not a function" 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. The tests are still failing. |
||
|
|
||
| test("Remove all completed tasks", () => { | ||
| const todos = createMockTodos(); | ||
|
|
||
| Todos.deleteCompleted(todos); | ||
|
|
||
| // Only incomplete tasks should remain | ||
| expect(todos).toHaveLength(2); | ||
| expect(todos[0].completed).toBe(false); | ||
| expect(todos[1].completed).toBe(false); | ||
|
|
||
| expect(todos[0].task).toBe("Task 2 description"); | ||
| expect(todos[1].task).toBe("Task 4 description"); | ||
| }); | ||
|
|
||
| test("No change if no tasks are completed", () => { | ||
| const todos = [ | ||
| { task: "Task A", completed: false }, | ||
| { task: "Task B", completed: false } | ||
| ]; | ||
|
|
||
| const before = JSON.parse(JSON.stringify(todos)); | ||
|
|
||
| Todos.deleteCompleted(todos); | ||
|
|
||
| expect(todos).toEqual(before); | ||
| }); | ||
|
|
||
| test("All tasks removed if all are completed", () => { | ||
| const todos = [ | ||
| { task: "Task A", completed: true }, | ||
| { task: "Task B", completed: true } | ||
| ]; | ||
|
|
||
| Todos.deleteCompleted(todos); | ||
|
|
||
| expect(todos).toHaveLength(0); | ||
| }); | ||
|
|
||
| }); | ||
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.
Why did you move the styles to the html file?