feat: implement new design for the nickname popup

This commit is contained in:
Jonathan Rainville 2020-09-24 14:12:50 -04:00 committed by Iuri Matias
parent 577dbba831
commit 6a57eeccb2
4 changed files with 24 additions and 11 deletions

View File

@ -281,7 +281,10 @@ QtObject:
return self.status.contacts.addContact(pk) return self.status.contacts.addContact(pk)
proc changeContactNickname*(self: ProfileView, publicKey: string, nickname: string) {.slot.} = proc changeContactNickname*(self: ProfileView, publicKey: string, nickname: string) {.slot.} =
discard self.status.contacts.addContact(publicKey, nickname) var nicknameToSet = nickname
if (nicknameToSet == ""):
nicknameToSet = DELETE_CONTACT
discard self.status.contacts.addContact(publicKey, nicknameToSet)
proc unblockContact*(self: ProfileView, id: string) {.slot.} = proc unblockContact*(self: ProfileView, id: string) {.slot.} =
discard self.status.contacts.unblockContact(id) discard self.status.contacts.unblockContact(id)

View File

@ -2,6 +2,8 @@ import eventemitter, json, sequtils
import libstatus/contacts as status_contacts import libstatus/contacts as status_contacts
import profile/profile import profile/profile
const DELETE_CONTACT* = "__deleteThisContact__"
type type
ContactModel* = ref object ContactModel* = ref object
events*: EventEmitter events*: EventEmitter
@ -45,6 +47,8 @@ proc addContact*(self: ContactModel, id: string, localNickname: string): string
let nickname = let nickname =
if (localNickname == ""): if (localNickname == ""):
contact.localNickname contact.localNickname
elif (localNickname == DELETE_CONTACT):
""
else: else:
localNickname localNickname
result = status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, contact.systemTags, nickname) result = status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, contact.systemTags, nickname)

View File

@ -12,7 +12,12 @@ ModalPopup {
property bool nicknameTooLong: nicknameLength > maxNicknameLength property bool nicknameTooLong: nicknameLength > maxNicknameLength
id: popup id: popup
height: 325 width: 400
height: 390
onOpened: {
nicknameInput.forceActiveFocus(Qt.MouseFocusReason)
}
header: Item { header: Item {
height: childrenRect.height height: childrenRect.height
@ -80,12 +85,17 @@ ModalPopup {
//% "Done" //% "Done"
label: qsTrId("done") label: qsTrId("done")
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
disabled: popup.nicknameLength === 0 || popup.nicknameTooLong disabled: popup.nicknameTooLong
onClicked: { onClicked: {
if (!userName.startsWith("@")) { if (!isEnsVerified) {
// Replace username only if it was not an ENS name // 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
userName = alias
} else {
userName = nicknameInput.textField.text userName = nicknameInput.textField.text
} }
}
nickname = nicknameInput.textField.text nickname = nicknameInput.textField.text
profileModel.changeContactNickname(fromAuthor, nicknameInput.textField.text) profileModel.changeContactNickname(fromAuthor, nicknameInput.textField.text)
popup.close() popup.close()

View File

@ -10,7 +10,7 @@ ModalPopup {
id: popup id: popup
property var identicon: "" property var identicon: ""
property var userName: "" property var userName: ""
property var nickname: "" property string nickname: ""
property var fromAuthor: "" property var fromAuthor: ""
property var text: "" property var text: ""
property var alias: "" property var alias: ""
@ -300,15 +300,11 @@ ModalPopup {
anchors.bottom: nicknameTitle.bottom anchors.bottom: nicknameTitle.bottom
onClicked: { onClicked: {
nicknamePopup.open() nicknamePopup.open()
popup.close()
} }
} }
NicknamePopup { NicknamePopup {
id: nicknamePopup id: nicknamePopup
onClosed: {
popup.open()
}
} }
} }