From cdcb928a0c89a7066ccd2bad33bee7e7c4c1c0e7 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Fri, 2 Oct 2020 10:37:51 -0400 Subject: [PATCH] refactor: simplify ProfilePopup usage --- ui/app/AppLayouts/Chat/ChatLayout.qml | 20 ------- .../Chat/components/ProfilePopup.qml | 57 +++++++++++++++---- .../Profile/Sections/Contacts/ContactList.qml | 28 ++++----- ui/shared/BlockContactConfirmationDialog.qml | 1 - ui/shared/ConfirmationDialog.qml | 2 + 5 files changed, 61 insertions(+), 47 deletions(-) diff --git a/ui/app/AppLayouts/Chat/ChatLayout.qml b/ui/app/AppLayouts/Chat/ChatLayout.qml index 215978396f..4bcc871a7b 100644 --- a/ui/app/AppLayouts/Chat/ChatLayout.qml +++ b/ui/app/AppLayouts/Chat/ChatLayout.qml @@ -52,28 +52,8 @@ SplitView { } destroy() } - onBlockButtonClicked: { - blockContactConfirmationDialog.contactName = name; - blockContactConfirmationDialog.contactAddress = address; - blockContactConfirmationDialog.parentPopup = profilePopup; - blockContactConfirmationDialog.open(); - } - onRemoveButtonClicked: { - chatColumn.contactToRemove = address; - removeContactConfirmationDialog.parentPopup = profilePopup; - removeContactConfirmationDialog.open(); - } } - - BlockContactConfirmationDialog { - id: blockContactConfirmationDialog - onBlockButtonClicked: { - profileModel.blockContact(blockContactConfirmationDialog.contactAddress) - blockContactConfirmationDialog.parentPopup.close() - blockContactConfirmationDialog.close(); - } - } ConfirmationDialog { id: removeContactConfirmationDialog diff --git a/ui/app/AppLayouts/Chat/components/ProfilePopup.qml b/ui/app/AppLayouts/Chat/components/ProfilePopup.qml index 3a052f8be2..a574f633a3 100644 --- a/ui/app/AppLayouts/Chat/components/ProfilePopup.qml +++ b/ui/app/AppLayouts/Chat/components/ProfilePopup.qml @@ -26,8 +26,11 @@ ModalPopup { signal blockButtonClicked(name: string, address: string) signal removeButtonClicked(address: string) - function setPopupData(userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam) { - showQR = false + signal contactBlocked(publicKey: string) + signal contactAdded(publicKey: string) + signal contactRemoved(publicKey: string) + + function openPopup(showFooter, userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam) { userName = userNameParam || "" nickname = nicknameParam || "" fromAuthor = fromAuthorParam || "" @@ -35,10 +38,8 @@ ModalPopup { text = textParam || "" isEnsVerified = chatsModel.isEnsVerified(this.fromAuthor) alias = chatsModel.alias(this.fromAuthor) || "" - } - - function openPopup(showFooter, userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam) { - setPopupData(userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam) + + showQR = false noFooter = !showFooter; popup.open() } @@ -124,6 +125,36 @@ ModalPopup { } } + Item { + BlockContactConfirmationDialog { + id: blockContactConfirmationDialog + onBlockButtonClicked: { + profileModel.blockContact(fromAuthor) + blockContactConfirmationDialog.close(); + popup.close() + + contactBlocked(fromAuthor) + } + } + + ConfirmationDialog { + id: removeContactConfirmationDialog + // % "Remove contact" + title: qsTrId("remove-contact") + //% "Are you sure you want to remove this contact?" + confirmationText: qsTrId("are-you-sure-you-want-to-remove-this-contact-") + onConfirmButtonClicked: { + if (profileModel.isAdded(fromAuthor)) { + profileModel.removeContact(fromAuthor); + } + removeContactConfirmationDialog.close(); + popup.close(); + + contactRemoved(fromAuthor); + } + } + } + Item { anchors.fill: parent visible: showQR @@ -349,7 +380,11 @@ ModalPopup { //% "Block User" label: qsTrId("block-user") anchors.bottom: parent.bottom - onClicked: popup.blockButtonClicked(userName, fromAuthor) + onClicked: { + blockContactConfirmationDialog.contactName = userName; + blockContactConfirmationDialog.contactAddress = fromAuthor; + blockContactConfirmationDialog.open(); + } } StyledButton { @@ -364,10 +399,12 @@ ModalPopup { anchors.bottom: parent.bottom onClicked: { if (profileModel.isAdded(fromAuthor)) { - popup.removeButtonClicked(fromAuthor) + removeContactConfirmationDialog.parentPopup = profilePopup; + removeContactConfirmationDialog.open(); } else { - profileModel.addContact(fromAuthor) - profilePopup.close() + profileModel.addContact(fromAuthor); + contactAdded(fromAuthor); + profilePopup.close(); } } } diff --git a/ui/app/AppLayouts/Profile/Sections/Contacts/ContactList.qml b/ui/app/AppLayouts/Profile/Sections/Contacts/ContactList.qml index a81cc44052..c216266fe8 100644 --- a/ui/app/AppLayouts/Profile/Sections/Contacts/ContactList.qml +++ b/ui/app/AppLayouts/Profile/Sections/Contacts/ContactList.qml @@ -20,6 +20,7 @@ ListView { width: parent.width model: contacts + delegate: Contact { name: Utils.removeStatusEns(model.name) address: model.address @@ -38,28 +39,16 @@ ListView { blockContactConfirmationDialog.open() } onRemoveContactActionTriggered: { - contactList.contactToRemove = address + removeContactConfirmationDialog.value = address removeContactConfirmationDialog.open() } } ProfilePopup { id: profilePopup - onBlockButtonClicked: { - blockContactConfirmationDialog.contactName = name - blockContactConfirmationDialog.contactAddress = address - blockContactConfirmationDialog.open() - } - onRemoveButtonClicked: { - contactList.contactToRemove = address - removeContactConfirmationDialog.open() - } - } - - ButtonGroup { - id: contactGroup } + // TODO: Make BlockContactConfirmationDialog a dynamic component on a future refactor BlockContactConfirmationDialog { id: blockContactConfirmationDialog onBlockButtonClicked: { @@ -68,18 +57,25 @@ ListView { } } + // TODO: Make ConfirmationDialog a dynamic component on a future refactor ConfirmationDialog { id: removeContactConfirmationDialog title: qsTrId("remove-contact") //% "Are you sure you want to remove this contact?" confirmationText: qsTrId("are-you-sure-you-want-to-remove-this-contact-") onConfirmButtonClicked: { - if (profileModel.isAdded(contactList.contactToRemove)) { - profileModel.removeContact(contactList.contactToRemove) + if (profileModel.isAdded(removeContactConfirmationDialog.value)) { + profileModel.removeContact(removeContactConfirmationDialog.value); } removeContactConfirmationDialog.close() } } + + + + ButtonGroup { + id: contactGroup + } } /*##^## Designer { diff --git a/ui/shared/BlockContactConfirmationDialog.qml b/ui/shared/BlockContactConfirmationDialog.qml index 6ab50dc066..c8b579b752 100644 --- a/ui/shared/BlockContactConfirmationDialog.qml +++ b/ui/shared/BlockContactConfirmationDialog.qml @@ -18,7 +18,6 @@ ModalPopup { title: qsTrId("block-user") StyledText { - //% text: qsTr("Blocking will remove any messages you received from %1 and stop new messages from reaching you.").arg(contactName) font.pixelSize: 15 anchors.left: parent.left diff --git a/ui/shared/ConfirmationDialog.qml b/ui/shared/ConfirmationDialog.qml index 24040f09d7..2c0c94ae48 100644 --- a/ui/shared/ConfirmationDialog.qml +++ b/ui/shared/ConfirmationDialog.qml @@ -20,6 +20,8 @@ ModalPopup { //% "Are you sure you want to this?" property string confirmationText: qsTrId("are-you-sure-you-want-to-this-") + property var value + signal confirmButtonClicked() Text {