Skip to content

Commit

Permalink
re-added Clear All button
Browse files Browse the repository at this point in the history
  • Loading branch information
yavor-kaludov committed Apr 23, 2024
1 parent fca7fcd commit 26cd9ba
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ <h1 class="self-center text-3xl font-bold z-10 font-jaq">Welcome to The Best Not


</div>

<div id="clear_all_button" class="hidden pt-10 text-center">
<button>Clear All</button>
</div>
</div>

</div>
Expand Down
2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ document.addEventListener("DOMContentLoaded", function() {

document.addEventListener("DOMContentLoaded", function() {
const noteInput = document.getElementById("note_input");
noteInput.addEventListener('keydown', NoteManager.handleEnterKey);
noteInput.addEventListener('keydown', NoteManager.handleKeydown);
});
21 changes: 18 additions & 3 deletions src/note_management.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function addNoteToArray(note) {
showNotes();

} else {
console.log("No note entered!");
console.error("No note entered!");
}

}
Expand All @@ -47,10 +47,16 @@ function setupAddNoteListener() {

async function showNotes() { // creates a note element from the note template text + detete button
const notesList = document.getElementById("notes_list");
const clearAllNotesButton = document.getElementById("clear_all_button");

if (notesArray.length > 0) {
notesList.className = "visible space-y-2 mt-10"
clearAllNotesButton.className = "visible pt-10 text-center"
} else {
notesList.className = "hidden space-y-2 mt-10"
clearAllNotesButton.className = "hidden pt-10 text-center"
}

notesList.innerHTML = "";

if (!noteTemplateContent) {
Expand All @@ -66,6 +72,10 @@ async function showNotes() { // creates a note element from the note template te

notesList.append(noteElement);
});

clearAllNotesButton.addEventListener("click", function() {
deleteAllNotes();
});

}

Expand All @@ -74,12 +84,17 @@ function deleteNote(index) {
showNotes(); // Refresh the list to show the updated notes
}

function handleEnterKey(event) {
function deleteAllNotes() { // deletes all notes in notesArray
notesArray.length = 0;
showNotes();
}

function handleKeydown(event) { // handles all keysdown events, just add more ifs to add more keys:)
if (event.keyCode == 13) {
event.preventDefault();
addNoteToArray();
}
}


export { setupNotesManager, notesArray, addNoteToArray, setupAddNoteListener, showNotes, deleteNote, handleEnterKey };
export { setupNotesManager, notesArray, addNoteToArray, setupAddNoteListener, showNotes, deleteNote, handleKeydown };

0 comments on commit 26cd9ba

Please sign in to comment.