fix(@desktop/browser): fix paste button in favorites modal

This fixes the base button in the favorites modal by replacing the legacy
`Input` component with StatusQ's `StatusInput` and `StatusButton` components.

It also updates the validation mechanism to use the one provided by StatusQ.
The `height` of the modal has been adjusted due to its content growing when
validation errors are shown.

This will go away as soon as we replace `ModalPopup` with `StatusModal`.

Fixes #3977
This commit is contained in:
Pascal Precht 2021-11-02 11:29:51 +01:00 committed by Iuri Matias
parent 068715ad44
commit 313208cfd4
2 changed files with 49 additions and 45 deletions

@ -1 +1 @@
Subproject commit ea9a56027786ed5a4910b5bf1f90fd4f495305d8 Subproject commit 9ece4967f720ef08aa6aaf53c8c9b226dfca8823

View File

@ -6,7 +6,9 @@ import QtGraphicalEffects 1.13
import utils 1.0 import utils 1.0
import shared.controls 1.0 import shared.controls 1.0
import StatusQ.Core.Theme 0.1
import StatusQ.Controls 0.1 import StatusQ.Controls 0.1
import StatusQ.Controls.Validators 0.1
import shared 1.0 import shared 1.0
import shared.popups 1.0 import shared.popups 1.0
@ -14,8 +16,6 @@ import "../stores"
// TODO: replace with StatusModal // TODO: replace with StatusModal
ModalPopup { ModalPopup {
property string urlError: ""
property string nameError: ""
property string ogUrl property string ogUrl
property string ogName property string ogName
property bool modifiyModal: false property bool modifiyModal: false
@ -23,7 +23,7 @@ ModalPopup {
id: popup id: popup
width: toolbarMode ? 345 : 480 width: toolbarMode ? 345 : 480
height: toolbarMode ? 345 : 480 height: toolbarMode ? 400 : 480
modal: !toolbarMode modal: !toolbarMode
@ -48,34 +48,18 @@ ModalPopup {
} }
onOpened: { onOpened: {
urlInput.forceActiveFocus(Qt.MouseFocusReason) urlInput.input.forceActiveFocus(Qt.MouseFocusReason)
} }
onClosed: { onClosed: {
reset() reset()
} }
function validate() {
urlError = ""
if (!urlInput.text) {
//% "Please enter a URL"
urlError = qsTrId("please-enter-a-url")
} else if (!Utils.isURL(urlInput.text)) {
//% "This fields needs to be a valid URL"
urlError = qsTrId("this-fields-needs-to-be-a-valid-url")
}
//% "Please enter a Name"
nameError = !nameInput.text ? qsTrId("please-enter-a-name") : ""
return !urlError && !nameError
}
function reset() { function reset() {
modifiyModal = false modifiyModal = false
toolbarMode = false toolbarMode = false
urlError = "" urlInput.reset()
nameError = "" nameInput.reset()
ogUrl = "" ogUrl = ""
ogName = "" ogName = ""
x = Math.round(((parent ? parent.width : 0) - width) / 2) x = Math.round(((parent ? parent.width : 0) - width) / 2)
@ -95,25 +79,48 @@ ModalPopup {
width: parent.width width: parent.width
spacing: Style.current.padding spacing: Style.current.padding
Input { StatusInput {
id: urlInput id: urlInput
//% "URL" anchors.left: parent.left
label: qsTrId("url") anchors.right: parent.right
//% "Paste URL" leftPadding: 0
placeholderText: qsTrId("paste-url") rightPadding: 0
pasteFromClipboard: true label: qsTr("URL")
validationError: popup.urlError input.text: popup.ogurl
text: popup.ogUrl input.placeholderText: qsTr("Paste URL")
input.component: StatusButton {
anchors.verticalCenter: parent.verticalCenter
border.width: 1
border.color: Theme.palette.primaryColor1
size: StatusBaseButton.Size.Tiny
text: qsTr("Paste")
onClicked: {
text = qsTr("Pasted")
urlInput.input.edit.paste()
}
}
validators: [
StatusUrlValidator {
errorMessage: qsTr("Please enter a valid URL")
}
]
} }
Input { StatusInput {
id: nameInput id: nameInput
//% "Name" anchors.left: parent.left
label: qsTrId("name") anchors.right: parent.right
//% "Name the website" leftPadding: 0
placeholderText: qsTrId("name-the-website") rightPadding: 0
validationError: popup.nameError label: qsTr("Name")
text: popup.ogName input.text: popup.ogurl
input.placeholderText: qsTr("Name of the website")
validators: [
StatusMinLengthValidator {
errorMessage: qsTr("Please enter a name")
minLength: 1
}
]
} }
} }
@ -146,18 +153,15 @@ ModalPopup {
//% "Add" //% "Add"
qsTrId("add") qsTrId("add")
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
enabled: nameInput.valid && urlInput.valid
onClicked: { onClicked: {
if (!validate()) {
return
}
if (!popup.modifiyModal) { if (!popup.modifiyModal) {
// remove "add favorite" button at the end, add new bookmark, add "add favorite" button back // remove "add favorite" button at the end, add new bookmark, add "add favorite" button back
BookmarksStore.deleteBookmark("") BookmarksStore.deleteBookmark("")
BookmarksStore.addBookmark(urlInput.text, nameInput.text) BookmarksStore.addBookmark(urlInput.input.text, nameInput.input.text)
BookmarksStore.addBookmark("", qsTr("Add Favorite")) BookmarksStore.addBookmark("", qsTr("Add Favorite"))
} else if (popup.ogName !== nameInput.text || popup.ogUrl !== urlInput.text) { } else if (popup.ogName !== nameInput.input.text || popup.ogUrl !== urlInput.input.text) {
BookmarksStore.updateBookmark(popup.ogUrl, urlInput.text, nameInput.text) BookmarksStore.updateBookmark(popup.ogUrl, urlInput.input.text, nameInput.input.text)
} }
popup.close() popup.close()