In this episode, we tackle how to keep track of when each note in our notes app was last edited. This is a pretty standard feature in any decent notes application and super useful for sorting and displaying our notes by recent activity.
Here's what we do: Every time you change the title or content of a note, we automatically update a last edited
timestamp on that note. To keep things efficient and not bog down the app, we use a little debounce trick—so the timestamp only updates if you pause typing for about 200 milliseconds, rather than updating after each keystroke.
We wire up this logic to both the note title input and the main text area. Then, we adjust the note data structure to have a last edited
property, and display that value in the UI. To make it readable, we format the timestamp to show hours and minutes, with some nice zero-padding so it always looks like a clock (e.g., 21:09 instead of 21:9).
We also make sure that when you create a new note, its last edited
time is set right away—so even fresh notes show up with the correct timestamp. At the end of the episode, the groundwork is in place for sorting your notes by when they were last touched, and we preview how to move on to actually ordering the list using that timestamp in the next episode.