From ce79a57818cea4bb7bcef0728c7e9ac9fe79821a Mon Sep 17 00:00:00 2001 From: Moustafa Shaaban Date: Thu, 20 Jun 2024 23:08:50 +0300 Subject: [PATCH] Fixed Delete Note Functionality and Updated the UI --- src/components/NoteDetail.vue | 2 +- src/components/NoteForm.vue | 2 +- src/components/TagForm.vue | 2 +- src/stores/notes.js | 10 ++++++++-- src/views/HomeView.vue | 37 +++++++++++++++++++++++++++++++++-- 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/components/NoteDetail.vue b/src/components/NoteDetail.vue index b75c0a9..4f31952 100644 --- a/src/components/NoteDetail.vue +++ b/src/components/NoteDetail.vue @@ -156,7 +156,7 @@ function confirm(id) { Edit - Delete + Delete diff --git a/src/components/NoteForm.vue b/src/components/NoteForm.vue index e664528..8c83f24 100644 --- a/src/components/NoteForm.vue +++ b/src/components/NoteForm.vue @@ -64,7 +64,7 @@ function handleSubmit() { + :rules="[val => val && val.length > 0 || 'Note Title is required']" autofocus /> diff --git a/src/components/TagForm.vue b/src/components/TagForm.vue index 26b2428..ae795df 100644 --- a/src/components/TagForm.vue +++ b/src/components/TagForm.vue @@ -53,7 +53,7 @@ function handleSubmit() { + :rules="[val => val && val.length > 0 || 'Tag Name is required']" autofocus /> diff --git a/src/stores/notes.js b/src/stores/notes.js index 9d28ac6..cb50ec9 100644 --- a/src/stores/notes.js +++ b/src/stores/notes.js @@ -42,9 +42,15 @@ export const useNotesStore = defineStore("notes", { console.log(noteToEdit.title); }, + // deleteNote(id) { + // const noteToDelete = this.notes.findIndex((note) => note.id === id); + // this.notes.splice(noteToDelete); + // }, + deleteNote(id) { - const noteToDelete = this.notes.findIndex((note) => note.id === id); - this.notes.splice(noteToDelete); + this.notes = this.notes.filter((note) => { + return note.id !== id; + }) }, addTag(tag) { diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index 4dccb55..dedbab0 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -1,6 +1,6 @@