refactor: simplify ProfilePopup usage

This commit is contained in:
Richard Ramos 2020-10-02 10:37:51 -04:00 committed by Iuri Matias
parent 2fb9d569f7
commit cdcb928a0c
5 changed files with 61 additions and 47 deletions

View File

@ -52,29 +52,9 @@ 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
// % "Remove contact"

View File

@ -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();
}
}
}

View File

@ -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 {

View File

@ -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

View File

@ -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 {