Skip to content

Commit

Permalink
Fixed Delete Note Functionality and Updated the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
MoustafaShaaban committed Jun 20, 2024
1 parent 05ea069 commit ce79a57
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/NoteDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function confirm(id) {

<q-card-actions>
<q-btn color="primary" type="button" size="sm" @click="isEditing = true">Edit</q-btn>
<q-btn color="negative" type="button" size="sm" @click="confirm">Delete</q-btn>
<q-btn color="negative" type="button" size="sm" @click="confirm(note.id)">Delete</q-btn>
</q-card-actions>
</q-card>

Expand Down
2 changes: 1 addition & 1 deletion src/components/NoteForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function handleSubmit() {
<q-card-section>
<q-form @submit.prevent="handleSubmit">
<q-input autocomplete filled v-model="noteTitle" label="Note Title" required lazy-rules
:rules="[val => val && val.length > 0 || 'Note Title is required']" />
:rules="[val => val && val.length > 0 || 'Note Title is required']" autofocus />

<q-input filled v-model="noteContent" type="textarea" required label="Note Content" lazy-rules
:rules="[val => val && val.length > 0 || 'Note Content is required']" />
Expand Down
2 changes: 1 addition & 1 deletion src/components/TagForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function handleSubmit() {
<q-card-section>
<q-form @submit.prevent="handleSubmit">
<q-input filled v-model="tagName" label="Tag Name" required lazy-rules
:rules="[val => val && val.length > 0 || 'Tag Name is required']" />
:rules="[val => val && val.length > 0 || 'Tag Name is required']" autofocus />

<q-page-sticky position="bottom-right" :offset="[18, 18]">
<q-btn type="submit" fab icon="done" color="primary">
Expand Down
10 changes: 8 additions & 2 deletions src/stores/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
37 changes: 35 additions & 2 deletions src/views/HomeView.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
import { computed } from 'vue';
import { date } from 'quasar';
import { date, Dialog, Notify } from 'quasar';
import { useNotesStore } from '../stores/notes';
const notesStore = useNotesStore();
Expand All @@ -13,6 +13,36 @@ const searchResult = computed(() => {
});
});
function confirm(id) {
Dialog.create({
dark: true,
title: 'Confirm',
color: 'primary',
message: 'Are you sure you want to delete this note?',
cancel: true,
persistent: true
}).onOk(() => {
try {
notesStore.deleteNote(id)
Notify.create({
message: 'Note Deleted Successfully',
type: "positive",
actions: [
{ icon: 'close', color: 'white', round: true, }
]
})
} catch (error) {
Notify.create({
message: error.message,
type: "negative",
actions: [
{ icon: 'close', color: 'white', round: true, }
]
})
}
})
};
</script>

<template>
Expand All @@ -39,8 +69,11 @@ const searchResult = computed(() => {
<q-btn color="grey-7" round flat icon="more_vert">
<q-menu cover auto-close>
<q-list>
<q-item clickable :to="{ name: 'note-detail', params: { id: note.id } }">
<q-item-section>Details</q-item-section>
</q-item>
<q-item clickable>
<q-item-section color="negative">Remove Card</q-item-section>
<q-item-section color="negative" @click="confirm(note.id)">Delete</q-item-section>
</q-item>
</q-list>
</q-menu>
Expand Down

0 comments on commit ce79a57

Please sign in to comment.