From 26cd9baa49d525af7e8c749ccf72be2c351d1a10 Mon Sep 17 00:00:00 2001 From: Yavor Date: Tue, 23 Apr 2024 18:33:42 +0300 Subject: [PATCH] re-added Clear All button --- index.html | 4 ++++ src/app.js | 2 +- src/note_management.js | 21 ++++++++++++++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 94db65a..5509685 100644 --- a/index.html +++ b/index.html @@ -47,6 +47,10 @@

Welcome to The Best Not + + diff --git a/src/app.js b/src/app.js index d081d5a..dcca1ba 100644 --- a/src/app.js +++ b/src/app.js @@ -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); }); diff --git a/src/note_management.js b/src/note_management.js index 54ce8c3..0c8e712 100644 --- a/src/note_management.js +++ b/src/note_management.js @@ -32,7 +32,7 @@ function addNoteToArray(note) { showNotes(); } else { - console.log("No note entered!"); + console.error("No note entered!"); } } @@ -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) { @@ -66,6 +72,10 @@ async function showNotes() { // creates a note element from the note template te notesList.append(noteElement); }); + + clearAllNotesButton.addEventListener("click", function() { + deleteAllNotes(); + }); } @@ -74,7 +84,12 @@ 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(); @@ -82,4 +97,4 @@ function handleEnterKey(event) { } -export { setupNotesManager, notesArray, addNoteToArray, setupAddNoteListener, showNotes, deleteNote, handleEnterKey }; \ No newline at end of file +export { setupNotesManager, notesArray, addNoteToArray, setupAddNoteListener, showNotes, deleteNote, handleKeydown }; \ No newline at end of file