status-desktop/ui/app/AppLayouts/Chat/popups/NicknamePopup.qml

108 lines
3.6 KiB
QML
Raw Normal View History

2020-09-16 16:00:21 +00:00
import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
import QtGraphicalEffects 1.13
import utils 1.0
import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
import StatusQ.Controls 0.1
import StatusQ.Popups 0.1
import "../../../../shared/controls"
2020-09-16 16:00:21 +00:00
StatusModal {
2020-09-16 16:00:21 +00:00
property int nicknameLength: nicknameInput.textField.text.length
readonly property int maxNicknameLength: 32
property bool nicknameTooLong: nicknameLength > maxNicknameLength
property var changeUsername: function () {}
property var changeNickname: function () {}
anchors.centerIn: parent
2020-09-16 16:00:21 +00:00
id: popup
width: 400
height: 390
onOpened: {
nicknameInput.forceActiveFocus(Qt.MouseFocusReason)
}
2020-09-16 16:00:21 +00:00
header.title: qsTr("Nickname")
header.subTitle: isEnsVerified ? alias : fromAuthor
header.subTitleElide: !isEnsVerified ? Text.ElideMiddle : Text.ElideNone
2020-09-16 16:00:21 +00:00
contentItem: Item {
width: popup.width
height: childrenRect.height
2020-09-16 16:00:21 +00:00
Column {
anchors.top: parent.top
anchors.topMargin: 16
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - 32
spacing: 16
StatusBaseText {
id: descriptionText
//% "Nicknames help you identify others in Status. Only you can see the nicknames youve added"
text: qsTrId("nicknames-help-you-identify-others-in-status--only-you-can-see-the-nicknames-you-ve-added")
font.pixelSize: 15
wrapMode: Text.WordWrap
color: Theme.palette.baseColor1
width: parent.width
}
2020-09-16 16:00:21 +00:00
Input {
id: nicknameInput
//% "Nickname"
placeholderText: qsTrId("nickname")
text: nickname
//% "Your nickname is too long"
validationError: popup.nicknameTooLong ? qsTrId("your-nickname-is-too-long") : ""
Keys.onReleased: {
if (event.key === Qt.Key_Return) {
doneBtn.onClicked();
}
}
2020-09-16 16:00:21 +00:00
StatusBaseText {
id: lengthLimitText
text: popup.nicknameLength + "/" + popup.maxNicknameLength
font.pixelSize: 15
anchors.top: parent.bottom
anchors.topMargin: 12
anchors.right: parent.right
color: popup.nicknameTooLong ? Theme.palette.dangerColro1 : Theme.palette.baseColor1
}
}
}
2020-09-16 16:00:21 +00:00
}
rightButtons: [
StatusButton {
id: doneBtn
//% "Done"
text: qsTrId("done")
enabled: !popup.nicknameTooLong
onClicked: {
if (!isEnsVerified) {
// Change username title only if it was not an ENS name
if (nicknameInput.textField.text === "") {
// If we removed the nickname, go back to showing the alias
popup.changeUsername(alias)
} else {
popup.changeUsername(nicknameInput.textField.text)
}
}
popup.changeNickname(nicknameInput.textField.text)
profileModel.contacts.changeContactNickname(fromAuthor, nicknameInput.textField.text)
popup.close()
if (!!chatsModel.communities.activeCommunity) {
chatsModel.communities.activeCommunity.triggerMembersUpdate()
}
}
2020-09-16 16:00:21 +00:00
}
]
2020-09-16 16:00:21 +00:00
}