From 5c034f545d0f936a24f9aa7d2f5567649610c591 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Fri, 4 Feb 2022 09:43:55 +0100 Subject: [PATCH] chore(@desktop/general): add avatar change functionality Fixes #4669 --- .../Profile/popups/ChangeProfilePicModal.qml | 27 ++++++++++--------- .../Profile/views/MyProfileView.qml | 17 +----------- ui/app/AppMain.qml | 10 +++++++ ui/imports/shared/popups/ProfilePopup.qml | 9 ++++++- ui/imports/utils/Global.qml | 1 + 5 files changed, 35 insertions(+), 29 deletions(-) diff --git a/ui/app/AppLayouts/Profile/popups/ChangeProfilePicModal.qml b/ui/app/AppLayouts/Profile/popups/ChangeProfilePicModal.qml index c4c6d8b067..b872040a3c 100644 --- a/ui/app/AppLayouts/Profile/popups/ChangeProfilePicModal.qml +++ b/ui/app/AppLayouts/Profile/popups/ChangeProfilePicModal.qml @@ -11,20 +11,19 @@ import shared.popups 1.0 // TODO: replace with StatusModal ModalPopup { - property string selectedImage // selectedImage is for us to be able to analyze it before setting it as current - property string uploadError - id: popup - - property url largeImage: "" - property bool hasIdentityImage: false - - signal cropFinished(string selectedImage, var aX, var aY, var bX, var bY) - signal removeImageButtonClicked() - //% "Profile picture" title: qsTrId("profile-picture") + property var profileStore + + property string selectedImage // selectedImage is for us to be able to analyze it before setting it as current + property string uploadError + property url largeImage: !popup.profileStore.isIdenticon? + popup.profileStore.profileLargeImage : + popup.profileStore.icon + property bool hasIdentityImage: !popup.profileStore.isIdenticon + onClosed: { destroy() } @@ -71,7 +70,9 @@ ModalPopup { selectedImage: popup.selectedImage ratio: "1:1" - onCropFinished: popup.cropFinished(selectedImage, aX, aY, bX, bY) + onCropFinished: { + popup.uploadError = popup.profileStore.uploadImage(selectedImage, aX, aY, bX, bY) + } } } @@ -87,7 +88,9 @@ ModalPopup { anchors.right: uploadBtn.left anchors.rightMargin: Style.current.padding anchors.bottom: parent.bottom - onClicked: popup.removeImageButtonClicked() + onClicked: { + popup.uploadError = popup.profileStore.removeImage() + } } StatusButton { diff --git a/ui/app/AppLayouts/Profile/views/MyProfileView.qml b/ui/app/AppLayouts/Profile/views/MyProfileView.qml index 5eb556fe2b..079a27f3a1 100644 --- a/ui/app/AppLayouts/Profile/views/MyProfileView.qml +++ b/ui/app/AppLayouts/Profile/views/MyProfileView.qml @@ -26,20 +26,6 @@ Item { height: parent.height Layout.fillWidth: true - Component { - id: changeProfileModalComponent - ChangeProfilePicModal { - largeImage: !root.profileStore.isIdenticon? root.profileStore.profileLargeImage : root.profileStore.icon - hasIdentityImage: !root.profileStore.isIdenticon - onCropFinished: { - uploadError = root.profileStore.uploadImage(selectedImage, aX, aY, bX, bY) - } - onRemoveImageButtonClicked: { - uploadError = root.profileStore.removeImage() - } - } - } - Item { id: profileImgNameContainer anchors.top: parent.top @@ -82,8 +68,7 @@ Item { anchors.fill: parent cursorShape: Qt.PointingHandCursor onClicked: { - const popup = changeProfileModalComponent.createObject(root); - popup.open() + Global.openChangeProfilePicPopup() } } } diff --git a/ui/app/AppMain.qml b/ui/app/AppMain.qml index 16bb3a2b49..c39e480cc0 100644 --- a/ui/app/AppMain.qml +++ b/ui/app/AppMain.qml @@ -80,6 +80,10 @@ Item { popup.openPopup(publicKey); Global.profilePopupOpened = true; } + onOpenChangeProfilePicPopup: { + var popup = changeProfilePicComponent.createObject(appMain); + popup.open(); + } onOpenBackUpSeedPopup : { var popup = backupSeedModalComponent.createObject(appMain) popup.open() @@ -170,6 +174,12 @@ Item { } } + property Component changeProfilePicComponent: Component { + ChangeProfilePicModal { + profileStore: appMain.rootStore.profileSectionStore.profileStore + } + } + Audio { id: sendMessageSound store: rootStore diff --git a/ui/imports/shared/popups/ProfilePopup.qml b/ui/imports/shared/popups/ProfilePopup.qml index 01f05b3a59..a47e27d6e0 100644 --- a/ui/imports/shared/popups/ProfilePopup.qml +++ b/ui/imports/shared/popups/ProfilePopup.qml @@ -66,10 +66,17 @@ StatusModal { popup.open() } + onHeaderImageClicked: { + Global.openChangeProfilePicPopup() + } + header.title: userDisplayName header.subTitle: userIsEnsVerified ? userName : userPublicKey header.subTitleElide: Text.ElideMiddle - header.image.source: userIcon + // In the following line we need to use `icon` property as that's the easiest way + // to update image on change (in case of logged in user) + header.image.source: isCurrentUser? popup.profileStore.icon : userIcon + header.headerImageEditable: isCurrentUser headerActionButton: StatusFlatRoundButton { type: StatusFlatRoundButton.Type.Secondary diff --git a/ui/imports/utils/Global.qml b/ui/imports/utils/Global.qml index 0a498426c2..d9760229ae 100644 --- a/ui/imports/utils/Global.qml +++ b/ui/imports/utils/Global.qml @@ -27,6 +27,7 @@ QtObject { signal openBackUpSeedPopup() signal openProfilePopupRequested(string publicKey, var parentPopup) + signal openChangeProfilePicPopup() function openProfilePopup(publicKey, parentPopup){ openProfilePopupRequested(publicKey, parentPopup);