In this episode, we dive into how to create a brand new note when clicking the New Note button in our app. We notice that a lot of the functionality for this is already set up from our app's initialization, where we create a fresh note, set it into the editor, and update the timestamp.
We start off by cleaning up our demo data—removing the example notes that we initially forced. This way, we're starting with just one untitled note, ready for editing. Then, we focus on hooking up the New Note button to our CreateNote
method. At first, if nothing happens when you click, we see it's because the button isn't part of an Alpine component yet. So, we make the button (or even the whole thing) an Alpine component, making it easier to add more functionality like showing the count of notes in the future.
After updating and refreshing, we confirm that clicking New Note does exactly what we want: It creates a new note that we can edit, and everything works as expected—the latest edited note moves to the top, and we can freely switch and edit notes.
To finish up, we tidy things by removing the old init method since it's no longer needed. Now, we can create as many notes as we like! The only downside? Our notes still aren't persistent—refreshing the page wipes them out. We'll tackle saving notes between reloads in the next episode!