From 666309fa70459b33c3190aafa89adbd5c9324d7e Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Sat, 13 Jan 2024 14:22:36 +0000 Subject: [PATCH] delete contact --- src/components/ContactForm.tsx | 2 +- src/components/ContactViewer.tsx | 24 ++++++++++++++++++++++++ src/routes/Activity.tsx | 12 +++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/components/ContactForm.tsx b/src/components/ContactForm.tsx index 06548841..b06fc9af 100644 --- a/src/components/ContactForm.tsx +++ b/src/components/ContactForm.tsx @@ -38,7 +38,7 @@ export function ContactForm(props: { return (
diff --git a/src/components/ContactViewer.tsx b/src/components/ContactViewer.tsx index 92536137..cf33afb4 100644 --- a/src/components/ContactViewer.tsx +++ b/src/components/ContactViewer.tsx @@ -5,6 +5,7 @@ import { createSignal, Match, Show, Switch } from "solid-js"; import { Button, + ConfirmDialog, ContactForm, KeyValue, MiniStringShower, @@ -27,12 +28,14 @@ export function ContactViewer(props: { contact: TagItem; gradient: string; saveContact: (id: string, contact: ContactFormValues) => void; + deleteContact: (id: string) => Promise; }) { const i18n = useI18n(); const [isOpen, setIsOpen] = createSignal(false); const [isEditing, setIsEditing] = createSignal(false); const [state, actions] = useMegaStore(); const navigate = useNavigate(); + const [confirmOpen, setConfirmOpen] = createSignal(false); const handleSubmit: SubmitHandler = ( c: ContactFormValues @@ -43,6 +46,13 @@ export function ContactViewer(props: { setIsEditing(false); }; + const handleDelete = async () => { + const id = props.contact.id; + + await props.deleteContact(id); + setIsOpen(false); + }; + const handlePay = () => { const network = state.mutiny_wallet?.get_network() || "signet"; @@ -101,6 +111,20 @@ export function ContactViewer(props: { handleSubmit={handleSubmit} initialValues={props.contact} /> + + setConfirmOpen(false)} + > + Are you sure you want to delete this contact? +
diff --git a/src/routes/Activity.tsx b/src/routes/Activity.tsx index 773649bf..04ae3da0 100644 --- a/src/routes/Activity.tsx +++ b/src/routes/Activity.tsx @@ -71,7 +71,6 @@ function ContactRow() { refetch(); } - // async function saveContact(id: string, contact: ContactFormValues) { console.log("saving contact", id, contact); const hexpub = await hexpubFromNpub(contact.npub?.trim()); @@ -95,6 +94,16 @@ function ContactRow() { refetch(); } + async function deleteContact(id: string) { + try { + await state.mutiny_wallet?.delete_contact(id); + } catch (e) { + console.error(e); + showToast(eify(e)); + } + refetch(); + } + return (
@@ -106,6 +115,7 @@ function ContactRow() { contact={contact} gradient={gradients()?.get(contact.name)} saveContact={saveContact} + deleteContact={deleteContact} /> )}