status-desktop/ui/app/AppLayouts/Chat/CommunityComponents/ImportCommunityPopup.qml

78 lines
1.8 KiB
QML
Raw Normal View History

2020-12-18 20:55:33 +00:00
import QtQuick 2.12
import QtQuick.Controls 2.3
import QtGraphicalEffects 1.13
import QtQuick.Dialogs 1.3
import "../../../../imports"
import "../../../../shared"
import "../../../../shared/status"
ModalPopup {
property string keyValidationError: ""
id: popup
height: 300
onOpened: {
keyInput.forceActiveFocus(Qt.MouseFocusReason)
}
function validate() {
keyValidationError = ""
if (keyInput.text === "") {
2021-02-18 16:36:05 +00:00
//% "You need to enter a key"
keyValidationError = qsTrId("you-need-to-enter-a-key")
2020-12-18 20:55:33 +00:00
}
return !keyValidationError
}
2021-02-18 16:36:05 +00:00
//% "Import a community"
title: qsTrId("import-community")
2020-12-18 20:55:33 +00:00
Input {
id: keyInput
2021-02-18 16:36:05 +00:00
//% "Community key"
label: qsTrId("community-key")
//% "0x..."
placeholderText: qsTrId("0x---")
2020-12-18 20:55:33 +00:00
validationError: popup.keyValidationError
2021-01-06 16:26:13 +00:00
pasteFromClipboard: true
2020-12-18 20:55:33 +00:00
}
footer: StatusButton {
2021-02-18 16:36:05 +00:00
//% "Import"
text: qsTrId("import")
2020-12-18 20:55:33 +00:00
anchors.right: parent.right
onClicked: {
if (!validate()) {
return
}
let communityKey = keyInput.text
if (!communityKey.startsWith("0x")) {
communityKey = "0x" + communityKey
}
const error = chatsModel.importCommunity(communityKey)
if (error) {
creatingError.text = error
return creatingError.open()
}
2020-12-22 20:23:21 +00:00
popup.close()
2020-12-18 20:55:33 +00:00
}
MessageDialog {
id: creatingError
2021-02-18 16:36:05 +00:00
//% "Error importing the community"
title: qsTrId("error-importing-the-community")
2020-12-18 20:55:33 +00:00
icon: StandardIcon.Critical
standardButtons: StandardButton.Ok
}
}
}