refactor(app-search): app search moved to a new component on the qml side
This commit is contained in:
parent
9e60b4ecfe
commit
ed09f82305
|
@ -32,6 +32,7 @@ StatusAppThreePanelLayout {
|
|||
property alias chatColumn: chatColumn
|
||||
property bool stickersLoaded: false
|
||||
signal profileButtonClicked()
|
||||
signal openAppSearch()
|
||||
|
||||
Connections {
|
||||
target: root.rootStore.chatsModelInst.stickers
|
||||
|
@ -49,121 +50,6 @@ StatusAppThreePanelLayout {
|
|||
messageStore: root.messageStore
|
||||
}
|
||||
|
||||
StatusSearchLocationMenu {
|
||||
id: searchPopupMenu
|
||||
searchPopup: searchPopup
|
||||
locationModel: mainModule.appSearchModule.locationMenuModel
|
||||
|
||||
onItemClicked: {
|
||||
mainModule.appSearchModule.setSearchLocation(firstLevelItemValue, secondLevelItemValue)
|
||||
if(searchPopup.searchText !== "")
|
||||
searchMessages(searchPopup.searchText)
|
||||
}
|
||||
}
|
||||
|
||||
property var searchMessages: Backpressure.debounce(searchPopup, 400, function (value) {
|
||||
mainModule.appSearchModule.searchMessages(value)
|
||||
})
|
||||
|
||||
Connections {
|
||||
target: mainModule.appSearchModule.locationMenuModel
|
||||
onModelAboutToBeReset: {
|
||||
for (var i = 2; i <= searchPopupMenu.count; i++) {
|
||||
//clear menu
|
||||
if (!!searchPopupMenu.takeItem(i)) {
|
||||
searchPopupMenu.removeItem(searchPopupMenu.takeItem(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StatusSearchPopup {
|
||||
id: searchPopup
|
||||
|
||||
noResultsLabel: qsTr("No results")
|
||||
defaultSearchLocationText: qsTr("Anywhere")
|
||||
|
||||
searchOptionsPopupMenu: searchPopupMenu
|
||||
searchResults: mainModule.appSearchModule.resultModel
|
||||
|
||||
formatTimestampFn: function (ts) {
|
||||
return new Date(parseInt(ts, 10)).toLocaleString(Qt.locale(localAppSettings.locale))
|
||||
}
|
||||
|
||||
onSearchTextChanged: {
|
||||
searchMessages(searchPopup.searchText);
|
||||
}
|
||||
onAboutToHide: {
|
||||
if (searchPopupMenu.visible) {
|
||||
searchPopupMenu.close();
|
||||
}
|
||||
}
|
||||
onClosed: {
|
||||
searchPopupMenu.dismiss();
|
||||
}
|
||||
onOpened: {
|
||||
searchPopup.resetSearchSelection();
|
||||
searchPopup.forceActiveFocus()
|
||||
mainModule.appSearchModule.prepareLocationMenuModel()
|
||||
|
||||
const jsonObj = mainModule.appSearchModule.getSearchLocationObject()
|
||||
|
||||
if (!jsonObj) {
|
||||
return
|
||||
}
|
||||
|
||||
let obj = JSON.parse(jsonObj)
|
||||
if (obj.location === "") {
|
||||
if(obj.subLocation === "") {
|
||||
mainModule.appSearchModule.setSearchLocation("", "")
|
||||
}
|
||||
else {
|
||||
searchPopup.setSearchSelection(obj.subLocation.text,
|
||||
"",
|
||||
obj.subLocation.imageSource,
|
||||
obj.subLocation.isIdenticon,
|
||||
obj.subLocation.iconName,
|
||||
obj.subLocation.identiconColor)
|
||||
|
||||
mainModule.appSearchModule.setSearchLocation("", obj.subLocation.value)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (obj.location.title === "Chat") {
|
||||
searchPopup.setSearchSelection(obj.subLocation.text,
|
||||
"",
|
||||
obj.subLocation.imageSource,
|
||||
obj.subLocation.isIdenticon,
|
||||
obj.subLocation.iconName,
|
||||
obj.subLocation.identiconColor)
|
||||
|
||||
mainModule.appSearchModule.setSearchLocation(obj.location.value, obj.subLocation.value)
|
||||
}
|
||||
else {
|
||||
searchPopup.setSearchSelection(obj.location.title,
|
||||
obj.subLocation.text,
|
||||
obj.location.imageSource,
|
||||
obj.location.isIdenticon,
|
||||
obj.location.iconName,
|
||||
obj.location.identiconColor)
|
||||
|
||||
mainModule.appSearchModule.setSearchLocation(obj.location.value, obj.subLocation.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
onResultItemClicked: {
|
||||
searchPopup.close()
|
||||
|
||||
root.rootStore.chatsModelInst.switchToSearchedItem(itemId)
|
||||
}
|
||||
|
||||
onResultItemTitleClicked: {
|
||||
const pk = titleId
|
||||
const userProfileImage = appMain.getProfileImage(pk)
|
||||
return openProfilePopup(root.rootStore.chatsModelInst.userNameOrAlias(pk), pk, userProfileImage || root.rootStore.utilsModelInst.generateIdenticon(pk))
|
||||
}
|
||||
}
|
||||
|
||||
leftPanel: Loader {
|
||||
id: contactColumnLoader
|
||||
sourceComponent: localAccountSensitiveSettings.communitiesEnabled && root.rootStore.chatsModelInst.communities.activeCommunity.active ? communtiyColumnComponent : contactsColumnComponent
|
||||
|
@ -173,6 +59,10 @@ StatusAppThreePanelLayout {
|
|||
id: chatColumn
|
||||
rootStore: root.rootStore
|
||||
chatGroupsListViewCount: contactColumnLoader.item.chatGroupsListViewCount
|
||||
|
||||
onOpenAppSearch: {
|
||||
root.openAppSearch()
|
||||
}
|
||||
}
|
||||
|
||||
showRightPanel: (localAccountSensitiveSettings.expandUsersList && (localAccountSensitiveSettings.showOnlineUsers || chatsModel.communities.activeCommunity.active)
|
||||
|
@ -213,6 +103,10 @@ StatusAppThreePanelLayout {
|
|||
onOpenProfileClicked: {
|
||||
root.profileButtonClicked();
|
||||
}
|
||||
|
||||
onOpenAppSearch: {
|
||||
root.openAppSearch()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@ Item {
|
|||
stackLayoutChatMessages.children[stackLayoutChatMessages.currentIndex].chatInput.textInput.forceActiveFocus(Qt.MouseFocusReason)
|
||||
}
|
||||
|
||||
signal openAppSearch()
|
||||
|
||||
function hideChatInputExtendedArea () {
|
||||
if(stackLayoutChatMessages.currentIndex >= 0 && stackLayoutChatMessages.currentIndex < stackLayoutChatMessages.children.length)
|
||||
stackLayoutChatMessages.children[stackLayoutChatMessages.currentIndex].chatInput.hideExtendedArea()
|
||||
|
@ -206,7 +208,7 @@ Item {
|
|||
notificationButton.tooltip.offset: localAccountSensitiveSettings.expandUsersList ? 0 : 14
|
||||
notificationCount: root.rootStore.chatsModelInst.activityNotificationList.unreadCount
|
||||
|
||||
onSearchButtonClicked: searchPopup.open()
|
||||
onSearchButtonClicked: root.openAppSearch()
|
||||
|
||||
onMembersButtonClicked: localAccountSensitiveSettings.expandUsersList = !localAccountSensitiveSettings.expandUsersList
|
||||
onNotificationButtonClicked: activityCenter.open()
|
||||
|
|
|
@ -24,6 +24,7 @@ Item {
|
|||
property var store
|
||||
property int chatGroupsListViewCount: channelList.chatListItems.count
|
||||
signal openProfileClicked()
|
||||
signal openAppSearch()
|
||||
|
||||
Component.onCompleted: {
|
||||
appMain.openContactsPopup.connect(function(){
|
||||
|
@ -76,7 +77,7 @@ Item {
|
|||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: searchPopup.open()
|
||||
onClicked: root.openAppSearch()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -186,6 +186,11 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
AppSearch{
|
||||
id: appSearch
|
||||
store: mainModule.appSearchModule
|
||||
}
|
||||
|
||||
StatusAppLayout {
|
||||
id: appLayout
|
||||
|
||||
|
@ -434,6 +439,10 @@ Item {
|
|||
appMain.changeAppSectionBySectionType(Constants.appSection.profile);
|
||||
}
|
||||
|
||||
onOpenAppSearch: {
|
||||
appSearch.openSearchPopup()
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
chatSectionModule = mainModule.getChatSectionModule()
|
||||
}
|
||||
|
@ -529,6 +538,10 @@ Item {
|
|||
appMain.changeAppSectionBySectionType(Constants.appSection.profile);
|
||||
}
|
||||
|
||||
onOpenAppSearch: {
|
||||
appSearch.openSearchPopup()
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
// we cannot return QVariant if we pass another parameter in a function call
|
||||
// that's why we're using it this way
|
||||
|
|
|
@ -0,0 +1,131 @@
|
|||
import QtQuick 2.13
|
||||
import QtQuick.Controls 2.13
|
||||
|
||||
import utils 1.0
|
||||
import StatusQ.Popups 0.1
|
||||
|
||||
Item {
|
||||
id: appSearch
|
||||
|
||||
property var store
|
||||
readonly property var searchMessages: Backpressure.debounce(searchPopup, 400, function (value) {
|
||||
store.searchMessages(value)
|
||||
})
|
||||
|
||||
function openSearchPopup(){
|
||||
searchPopup.open()
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: store.locationMenuModel
|
||||
onModelAboutToBeReset: {
|
||||
for (var i = 2; i <= searchPopupMenu.count; i++) {
|
||||
//clear menu
|
||||
if (!!searchPopupMenu.takeItem(i)) {
|
||||
searchPopupMenu.removeItem(searchPopupMenu.takeItem(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StatusSearchLocationMenu {
|
||||
id: searchPopupMenu
|
||||
searchPopup: searchPopup
|
||||
locationModel: store.locationMenuModel
|
||||
|
||||
onItemClicked: {
|
||||
store.setSearchLocation(firstLevelItemValue, secondLevelItemValue)
|
||||
if(searchPopup.searchText !== "")
|
||||
searchMessages(searchPopup.searchText)
|
||||
}
|
||||
}
|
||||
|
||||
StatusSearchPopup {
|
||||
id: searchPopup
|
||||
|
||||
noResultsLabel: qsTr("No results")
|
||||
defaultSearchLocationText: qsTr("Anywhere")
|
||||
|
||||
searchOptionsPopupMenu: searchPopupMenu
|
||||
searchResults: store.resultModel
|
||||
|
||||
formatTimestampFn: function (ts) {
|
||||
return new Date(parseInt(ts, 10)).toLocaleString(Qt.locale(localAppSettings.locale))
|
||||
}
|
||||
|
||||
onSearchTextChanged: {
|
||||
searchMessages(searchPopup.searchText);
|
||||
}
|
||||
onAboutToHide: {
|
||||
if (searchPopupMenu.visible) {
|
||||
searchPopupMenu.close();
|
||||
}
|
||||
}
|
||||
onClosed: {
|
||||
searchPopupMenu.dismiss();
|
||||
}
|
||||
onOpened: {
|
||||
searchPopup.resetSearchSelection();
|
||||
searchPopup.forceActiveFocus()
|
||||
store.prepareLocationMenuModel()
|
||||
|
||||
const jsonObj = store.getSearchLocationObject()
|
||||
|
||||
if (!jsonObj) {
|
||||
return
|
||||
}
|
||||
|
||||
let obj = JSON.parse(jsonObj)
|
||||
if (obj.location === "") {
|
||||
if(obj.subLocation === "") {
|
||||
store.setSearchLocation("", "")
|
||||
}
|
||||
else {
|
||||
searchPopup.setSearchSelection(obj.subLocation.text,
|
||||
"",
|
||||
obj.subLocation.imageSource,
|
||||
obj.subLocation.isIdenticon,
|
||||
obj.subLocation.iconName,
|
||||
obj.subLocation.identiconColor)
|
||||
|
||||
store.setSearchLocation("", obj.subLocation.value)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (obj.location.title === "Chat") {
|
||||
searchPopup.setSearchSelection(obj.subLocation.text,
|
||||
"",
|
||||
obj.subLocation.imageSource,
|
||||
obj.subLocation.isIdenticon,
|
||||
obj.subLocation.iconName,
|
||||
obj.subLocation.identiconColor)
|
||||
|
||||
store.setSearchLocation(obj.location.value, obj.subLocation.value)
|
||||
}
|
||||
else {
|
||||
searchPopup.setSearchSelection(obj.location.title,
|
||||
obj.subLocation.text,
|
||||
obj.location.imageSource,
|
||||
obj.location.isIdenticon,
|
||||
obj.location.iconName,
|
||||
obj.location.identiconColor)
|
||||
|
||||
store.setSearchLocation(obj.location.value, obj.subLocation.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
onResultItemClicked: {
|
||||
searchPopup.close()
|
||||
|
||||
// Not Refactored
|
||||
//root.rootStore.chatsModelInst.switchToSearchedItem(itemId)
|
||||
}
|
||||
|
||||
onResultItemTitleClicked: {
|
||||
// Not Refactored
|
||||
//const pk = titleId
|
||||
//const userProfileImage = appMain.getProfileImage(pk)
|
||||
//return openProfilePopup(root.rootStore.chatsModelInst.userNameOrAlias(pk), pk, userProfileImage || root.rootStore.utilsModelInst.generateIdenticon(pk))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue