From 1630a97e508f8fa2c43693eb8adfdd2412004821 Mon Sep 17 00:00:00 2001
From: Cristiano Magro <cristiano.magro@vola.it>
Date: Mon, 30 Dec 2024 20:14:37 +0100
Subject: [PATCH] delete contact

---
 07 - development setup/vue-cli-01-a-new-vue-project/src/components/FriendContact.vue |    6 +++++-
 07 - development setup/vue-cli-01-a-new-vue-project/src/App.vue                      |   12 ++++++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/07 - development setup/vue-cli-01-a-new-vue-project/src/App.vue b/07 - development setup/vue-cli-01-a-new-vue-project/src/App.vue
index 9859157..bdc3f3f 100644
--- a/07 - development setup/vue-cli-01-a-new-vue-project/src/App.vue
+++ b/07 - development setup/vue-cli-01-a-new-vue-project/src/App.vue
@@ -12,7 +12,10 @@
         :phone-number="friend.phone" 
         :email-address="friend.email" 
         :is-favorite="friend.isFavorite"
-        @toggle-favorite="toggleFavoriteStatus"></friend-contact>
+        @toggle-favorite="toggleFavoriteStatus"
+        @delete="deleteContact" 
+        >
+      </friend-contact>
     </ul>
   </section>
 </template>
@@ -59,7 +62,12 @@
       };
 
       this.friends.push(newFriendContact);
-    }
+    },
+    deleteContact (friendId){
+        this.friends = this.friends.filter(
+          (friend) => friend.id != friendId
+        );
+    },
 
   }
 };
diff --git a/07 - development setup/vue-cli-01-a-new-vue-project/src/components/FriendContact.vue b/07 - development setup/vue-cli-01-a-new-vue-project/src/components/FriendContact.vue
index 630e9f7..eb4fdc0 100644
--- a/07 - development setup/vue-cli-01-a-new-vue-project/src/components/FriendContact.vue
+++ b/07 - development setup/vue-cli-01-a-new-vue-project/src/components/FriendContact.vue
@@ -12,6 +12,7 @@
             <li><strong>Phone:</strong> {{ phoneNumber }}</li>
             <li><strong>Email:</strong> {{ emailAddress }}</li>
         </ul>
+        <button @click="$emit('delete', id)">Delete</button>
     </li>
 </template>
 
@@ -49,7 +50,7 @@
             // }
         },
     },
-    emits:['toggle-favorite'],
+    emits:['toggle-favorite', 'delete'],
     // emits: {
     //     'toggle-favorite': function (id) {
     //         if (id) {
@@ -71,6 +72,9 @@
         toggleFavorite() {
             this.$emit('toggle-favorite', this.id);
         },
+        // deleteFriend(){
+        //     this.$emit('delete', this.id);
+        // }
     },
 };
 </script>
\ No newline at end of file

--
Gitblit v1.8.0