We'll be building this SO FANCY todo app.
Using the back end we've built, let's implement the following features on the FRONT END:
- Show priorities in addition to text.
- Show only not complete items.
- Show only high priority items.
- Move completed items to the bottom.
- Move high priority items to the top.
For those last two, we'll ALSO have to finish the sorting portion of our back end. Run npm test
when you're ready to do a little back-end work!
We highly recommend you familiarize yourself with the code we've got before you get started. There's a lot already there, so don't spend time writing code that already exists!
- How can we toggle the completeness of a todo by clicking on it?
- How can we change the text of the buttons that are toggling? For example, when we click "Show Priorities", it changes to "Hide Priorities" so that we can toggle that feature back off.
- How can we access the pulldown menu for adding priority to a todo?
You should be using INLINE functions for your event listeners. No more having to make (and name!) helper functions.
So instead of this:
const listener = function(event) {
// ...
}
document.querySelector('.some-class').addEventListener('click', listener);
We can do this:
document.querySelector('.some-class').addEventListener('click', function(event) {
// ...
})
Let us know if you have any questions about that syntax!
- an
id
field to each todo object - and a
currentTodos
array you can reassign to (declared withlet
intodos.js
) without changing your underlying data. - We've also separated our functions into separate files. Feel free to do the same with any new functions you make, but at the least, try navigating these files and see if you find it easier or harder than scrolling through one large one.
- And that includes some files we'd suggest for your buttons' event listeners. Feel free to make those files or different files... but remember to link them in your
index.html
if you use different files!
- You can use the
id
field of each object, which, inprintTodo
, also gets put on the DOM as theli
'sid
. Now you can find the right todo to edit no matter what order your todos are in. You may not end up using it, but remember that it's there!
This is a more fine-grained step-by-step guide to making Todata happen, for those who don't want to figure it out all on their lonesome.
Create a new add-todos-button-controller.js
file and let's get cracking!
- Query the button for adding todos and add an event listener function. This can be done in one line using 1) dot-chaining and 2) an anonymouse function as the second parameter to
addEventListener
. - Inside that event listener function, query the todo user input box and save it to a variable. We'll need to use it a few times!
- Now We're ready to create our todo object. It needs four fields: the
text
,completeness
,id
, andpriority
. You can grab thepriority
andtext
's values from the DOM. Where would they be located? I'll leave you to think about the values forcomplete
(easy to figure out) andid
(a bit harder). - Now push that object into
todos
. And maybe currentTodos? We'll have to figure out when or even whether to use this copy-of-todos (find it intodos.js
). - Finally, let's update the DOM. Call
refreshTodos
--it takes no parameters and simply erases the list and rewrites it to bring it in line with whatever's intodos
. (Or maybe it should becurrentTodos
? Hey, I'm just the idea man. That's YOUR job.)