From e225605ff433ba2ebbfcf5d0d6889e1fd45d6d32 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 15 Aug 2021 12:19:11 +0000 Subject: Make it possible to create contacts --- qml/NewChatPage.qml | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'qml') diff --git a/qml/NewChatPage.qml b/qml/NewChatPage.qml index d848c17..aee1393 100644 --- a/qml/NewChatPage.qml +++ b/qml/NewChatPage.qml @@ -6,15 +6,16 @@ import org.kde.kirigami 2.13 as Kirigami import DeltaChat 1.0 Kirigami.ScrollablePage { - id: newChatPageRoot + id: root title: "New chat" required property DcContext context function updateContacts() { - let contacts = context.getContacts(0, ""); + let contacts = context.getContacts(0, searchField.text); + contactsModel.clear() for (let i = 0; i < contacts.length; i++) { let contactId = contacts[i] @@ -26,7 +27,13 @@ Kirigami.ScrollablePage { } Component.onCompleted: { - newChatPageRoot.updateContacts() + root.updateContacts() + } + + header: Kirigami.SearchField { + id: searchField + + onTextChanged: root.updateContacts() } ListModel { @@ -69,10 +76,25 @@ Kirigami.ScrollablePage { Kirigami.PlaceholderMessage { anchors.centerIn: parent - visible: contactsList.count == 0 + visible: contactsList.count == 0 && searchField.text == "" text: "You have no contacts in addressbook yet" } + Kirigami.PlaceholderMessage { + anchors.centerIn: parent + visible: contactsList.count == 0 && searchField.text != "" + helpfulAction: Kirigami.Action { + icon.name: "list-add" + text: "Add contact" + onTriggered: { + let contactId = root.context.createContact("", searchField.text) + context.createChatByContactId(contactId); + pageStack.layers.pop(); + } + } + text: "Contact " + searchField.text + " is not in your address book." + } + onCurrentItemChanged: { if (currentIndex == -1) { return; -- cgit v1.2.3-70-g09d2