feat: add the Add favorite popup

This commit is contained in:
Jonathan Rainville 2020-10-29 11:19:27 -04:00 committed by Iuri Matias
parent 7242409bfa
commit ff0a96c02b
4 changed files with 79 additions and 2 deletions

View File

@ -0,0 +1,69 @@
import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
import "../../../imports"
import "../../../shared"
ModalPopup {
property string urlError: ""
property string nameError: ""
id: popup
width: 480
height: 480
onOpened: {
urlInput.forceActiveFocus(Qt.MouseFocusReason)
}
function validate() {
urlError = ""
if (!urlInput.text) {
urlError = qsTr("Please enter a URL")
} else if (!Utils.isURL(urlInput.text)) {
urlError = qsTr("This fields needs to be a valid URL")
}
nameError = !nameInput.text ? qsTr("Please enter a Name") : ""
return !urlError && !nameError
}
title: qsTr("Add favorite")
Column {
width: parent.width
spacing: Style.current.padding
Input {
id: urlInput
label: qsTr("URL")
placeholderText: qsTr("Paste URL")
pasteFromClipboard: true
validationError: popup.urlError
}
Input {
id: nameInput
label: qsTr("Name")
placeholderText: qsTr("Name the website")
validationError: popup.nameError
}
}
footer: StyledButton {
id: addBtn
anchors.right: parent.right
anchors.rightMargin: Style.current.smallPadding
label: qsTr("Add")
anchors.bottom: parent.bottom
onClicked: {
if (!validate()) {
return
}
browserModel.addBookmark(urlInput.text, nameInput.text)
popup.close()
}
}
}

View File

@ -91,6 +91,10 @@ Rectangle {
standardButtons: StandardButton.Ok
}
AddFavoriteModal {
id: addFavoriteModal
}
QtObject {
id: provider
WebChannel.id: "backend"
@ -637,8 +641,7 @@ Rectangle {
id: addBookmarkBtn
text: qsTr("Add favorite")
onClicked: {
// TODO add a popup
browserModel.addBookmark("https://dap.ps/", "dap.ps")
addFavoriteModal.open()
}
anchors.left: bookmarkList.right
anchors.leftMargin: bookmarkList.spacing

View File

@ -150,6 +150,10 @@ QtObject {
return (/^[a-z0-9\-]+$/.test(channelName))
}
function isURL(text) {
return (/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/.test(text))
}
function isSpace(c) {
return (/( |\t|\n|\r)/.test(c))
}

View File

@ -121,6 +121,7 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
DISTFILES += \
app/AppLayouts/Browser/AddFavoriteModal.qml \
app/AppLayouts/Browser/BrowserConnectionModal.qml \
app/AppLayouts/Browser/BrowserHeader.qml \
app/AppLayouts/Browser/BrowserSettingsMenu.qml \