From fdac4f26652c0370b9b3e2d24a5610bb25b58565 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Mon, 20 Mar 2023 19:29:58 -0600 Subject: [PATCH] allow deletion of a contact --- src/views/ContactsView.vue | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/views/ContactsView.vue b/src/views/ContactsView.vue index 9c67299..6500b80 100644 --- a/src/views/ContactsView.vue +++ b/src/views/ContactsView.vue @@ -96,7 +96,12 @@ {{ contact.name || "(no name)" }}
{{ contact.did }}
-
{{ contact.publicKeyBase64 }}
+
+ Public Key (base 64): {{ contact.publicKeyBase64 }} +
+
to: {{ givenByMeTotals[contact.did] || 0 }} @@ -183,7 +188,11 @@ export default class ContactsView extends Vue { if (this.showGiveTotals) { this.loadGives(); } - this.contacts = await db.contacts.toArray(); + const allContacts = await db.contacts.toArray(); + this.contacts = R.sort( + (a: Contact, b) => (a.name || "").localeCompare(b.name || ""), + allContacts + ); } async onClickNewContact(): Promise { @@ -206,7 +215,11 @@ export default class ContactsView extends Vue { } const newContact = { did, name, publicKeyBase64 }; await db.contacts.add(newContact); - this.contacts = this.contacts.concat([newContact]); + const allContacts = this.contacts.concat([newContact]); + this.contacts = R.sort( + (a: Contact, b) => (a.name || "").localeCompare(b.name || ""), + allContacts + ); } async loadGives() { @@ -281,6 +294,22 @@ export default class ContactsView extends Vue { } } + async deleteContact(contact: Contact) { + if ( + confirm( + "Are you sure you want to delete " + + this.nameForDid(this.contacts, contact.did) + + " with DID " + + contact.did + + "?" + ) + ) { + await db.open(); + await db.contacts.delete(contact.did); + this.contacts = R.without([contact], this.contacts); + } + } + // from https://stackoverflow.com/a/175787/845494 // private isNumeric(str: string): boolean {