|
1 | | -# Todo-list |
| 1 | +# ToDo List App |
2 | 2 |
|
3 | | -## Explanation |
| 3 | +The files in this folder implements a ToDo List App that allows a user to |
| 4 | +- Create a new ToDo task |
| 5 | +- Delete a ToDo task |
| 6 | +- Display all ToDo tasks |
| 7 | +- Changing the "completed" status of a ToDo task |
4 | 8 |
|
5 | | -This is a super handy, super simple to do list. |
| 9 | +Each ToDo task has two properties: |
| 10 | + - `task`: A string describing the task |
| 11 | + - `completed`: a Boolean value that indicates whether the task is completed or not |
6 | 12 |
|
7 | | -You will be given a list of tasks which are "To Do". We call these tasks "ToDos" |
| 13 | +## Installation |
8 | 14 |
|
9 | | -Each item in the list should have 2 buttons: |
| 15 | +Run the following command in this directory to install all required dependencies: |
| 16 | +``` |
| 17 | + npm install |
| 18 | +``` |
| 19 | +> This will install |
| 20 | +- `jest` - for running unix test |
| 21 | +- `http-server` - for serving `index.html` over HTTP |
| 22 | + |
| 23 | +**Note:** If you are using a Windows CLI, replace `package.json` by `package.json-windows`. |
10 | 24 |
|
11 | | -- One to click when the ToDo has been completed - it will apply a line-through style to the text of the ToDo. |
12 | | -- A second to delete the ToDo. This could be used to delete completed ToDos from the list, or remove ToDos that we are no longer interested in doing. |
| 25 | +## Running the App |
13 | 26 |
|
14 | | -We also want to be able to add ToDos to the list using an input field and a button. When ToDos are created this way they should be added to the list with the 2 above buttons. |
| 27 | +Since the app uses **ES modules**, the HTML file **must be loaded via HTTP/HTTPS** rather than |
| 28 | +directly from the file system. |
15 | 29 |
|
16 | | -More details for the implementation of this challenge can be found in `script.js` |
| 30 | +Make sure you run the server in this directory where `index.html` is located. |
17 | 31 |
|
18 | | -## Installation |
| 32 | +Two possible ways to serve `index.html` over HTTP: |
19 | 33 |
|
20 | | -To view the website, open index.html in a browser. |
| 34 | +#### Option 1: `http-server` |
21 | 35 |
|
22 | | -## Example Solution |
| 36 | +1. Run |
| 37 | + ``` |
| 38 | + npm run serve |
| 39 | + ``` |
| 40 | + > Here, `serve` is a shortcut defined in `package.json` for running `http-server`. |
| 41 | + |
| 42 | + |
| 43 | +2. Open one of the URLs shown in the terminal (e.g., `http://127.0.0.1:8080`). |
23 | 44 |
|
24 | | -A basic example of this can website can be found here |
25 | 45 |
|
26 | | -https://chrisowen101.github.io/ToDoListSolution/ |
| 46 | +#### Option 2: Open `index.html` with Live Server in VSCode. |
27 | 47 |
|
28 | | -This covers only the basic tasks, not the advanced tasks. |
29 | 48 |
|
30 | | -## Instructions |
| 49 | +## Understanding how the code is organized as ES modules |
31 | 50 |
|
32 | | -The `populateTodoList()` function should iterate over the list of todos that we are given at the start, it should create a `<li>` for the todo along with some other stuff that you can find in index.html and below. |
| 51 | +- [What is ES Modules?](00-what_is_ES_modules.md) |
| 52 | +- [How to use ES modules with Node.js and Jest?](01-using_esm_with_nodejs_and_jest.md) |
| 53 | +- [A guide to modularize a web app](02-guide_to_modularize_code.md) |
33 | 54 |
|
34 | | -The items in the todo list are currently hard-coded into the HTML, refactor the code so that this function creates them and adds the following functionality to them: |
| 55 | +--- |
35 | 56 |
|
36 | | -Each todo should have this HTML inside it: |
| 57 | +## Exercise Instructions |
37 | 58 |
|
38 | | -```html |
39 | | -<span class="badge bg-primary rounded-pill"> |
40 | | - <i class="fa fa-check" aria-hidden="true"></i> |
41 | | - <i class="fa fa-trash" aria-hidden="true"></i> |
42 | | -</span> |
43 | | -``` |
| 59 | +In this exercise, your objective is to extend the ToDo app by implementing new features. |
| 60 | +Start with the main feature and then try the stretch goals if you have extra time. |
| 61 | + |
| 62 | +### Main Feature: Mass delete of completed ToDos |
| 63 | + |
| 64 | +Add a button that deletes all completed tasks at once. |
| 65 | + |
| 66 | +Steps: |
| 67 | +1. In `index.html`, add a "Delete completed tasks" button. |
44 | 68 |
|
45 | | -The first `<i>` tag needs an event listener that applies a line-through text-decoration styling to the text of the todo. It should remove the styling if it is clicked again. |
| 69 | +2. In `todos.mjs`, implement a function `deleteCompleted(todoList)` that removes all completed |
| 70 | + ToDos from the given list. |
46 | 71 |
|
47 | | -The second `<i>` tag needs an event listener that deletes the parent `<li>` element from the `<ul>`. |
| 72 | +3. In `todos.test.mjs`, write a Jest test that verifies `deleteCompleted()` works correctly. |
48 | 73 |
|
49 | | -## Advanced Challenge |
| 74 | +4. In `script.js`, call `deleteCompleted()` whenever the new button is clicked. |
| 75 | + - ⚠️ You should not need to modify the `render()` function. |
50 | 76 |
|
51 | | -### Mass delete of completed ToDos |
| 77 | +### Stretch 1: Add deadlines for ToDos |
52 | 78 |
|
53 | | -Develop the ToDo list further and allow users to delete all completed ToDos. |
| 79 | +Allow users to set and view deadlines for their tasks. |
| 80 | + - When creating a ToDo, let the user select a deadline using an HTML **datepicker** input. |
| 81 | + - If no date is selected, the ToDo has **no deadline**. |
| 82 | + - When rendering a ToDo in the list, display the deadline only if it exists. |
54 | 83 |
|
55 | | -Add a button that users can click that will iterate through the list of ToDos and then delete them only if they have been completed. |
| 84 | +### Stretch 2: Extra Challenge – Show time remaining |
56 | 85 |
|
57 | | -## Extra Advanced Challenge |
| 86 | +Instead of showing the deadline as a date, display how many days are left until the |
| 87 | +deadline (relative to today). |
| 88 | + - Decide how overdue ToDos should be handled and then implement your chosen solution. |
58 | 89 |
|
59 | | -### Set deadlines for ToDos |
| 90 | +👉 Hint: You can use the [JavaScript Date API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
| 91 | +to calculate the difference. |
60 | 92 |
|
61 | | -We want users to be able to set, and see, deadlines for their ToDos. |
62 | 93 |
|
63 | | -When creating ToDos we want the user to be able to use a datepicker input so they can see when they need to complete the ToDo. The date can be added to the ToDo in the list. If there is no date set when the ToDo is created then this can be skipped. |
64 | 94 |
|
65 | | -EXTRA CHALLENGE: instead of displaying the date on the ToDo, implement a countdown of days left until the deadline. You can use the Javascript Date reference to accomplish this: |
66 | | -https://www.w3schools.com/jsref/jsref_obj_date.asp |
|
0 commit comments