2021-11-10 08:09:31 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
|
2022-04-01 10:30:55 +00:00
|
|
|
import shared.stores 1.0
|
2021-11-10 08:09:31 +00:00
|
|
|
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) {
|
2022-01-27 11:28:27 +00:00
|
|
|
appSearch.store.searchMessages(value)
|
2021-11-10 08:09:31 +00:00
|
|
|
})
|
2022-02-16 16:13:45 +00:00
|
|
|
property alias opened: searchPopup.opened
|
2021-11-10 08:09:31 +00:00
|
|
|
|
|
|
|
function openSearchPopup(){
|
|
|
|
searchPopup.open()
|
|
|
|
}
|
|
|
|
|
2022-02-16 16:13:45 +00:00
|
|
|
function closeSearchPopup(){
|
|
|
|
searchPopup.close()
|
|
|
|
}
|
|
|
|
|
2021-11-10 08:09:31 +00:00
|
|
|
Connections {
|
2022-01-27 11:28:27 +00:00
|
|
|
target: appSearch.store.locationMenuModel
|
2021-11-10 08:09:31 +00:00
|
|
|
onModelAboutToBeReset: {
|
2022-02-16 16:13:45 +00:00
|
|
|
while (searchPopupMenu.takeItem(searchPopupMenu.numDefaultItems)) {
|
|
|
|
// Delete the item right after the default items
|
|
|
|
// If takeItem returns null, it means there was nothing to remove
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-27 11:28:27 +00:00
|
|
|
Connections {
|
|
|
|
target: appSearch.store.appSearchModule
|
|
|
|
onAppSearchCompleted: searchPopup.loading = false
|
|
|
|
}
|
|
|
|
|
2021-11-10 08:09:31 +00:00
|
|
|
StatusSearchLocationMenu {
|
|
|
|
id: searchPopupMenu
|
|
|
|
searchPopup: searchPopup
|
2022-01-27 11:28:27 +00:00
|
|
|
locationModel: appSearch.store.locationMenuModel
|
2021-11-10 08:09:31 +00:00
|
|
|
|
|
|
|
onItemClicked: {
|
2022-01-27 11:28:27 +00:00
|
|
|
appSearch.store.setSearchLocation(firstLevelItemValue, secondLevelItemValue)
|
2021-11-10 08:09:31 +00:00
|
|
|
if(searchPopup.searchText !== "")
|
|
|
|
searchMessages(searchPopup.searchText)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusSearchPopup {
|
|
|
|
id: searchPopup
|
|
|
|
noResultsLabel: qsTr("No results")
|
|
|
|
defaultSearchLocationText: qsTr("Anywhere")
|
|
|
|
searchOptionsPopupMenu: searchPopupMenu
|
2022-01-27 11:28:27 +00:00
|
|
|
searchResults: appSearch.store.resultModel
|
2021-11-10 08:09:31 +00:00
|
|
|
formatTimestampFn: function (ts) {
|
2022-04-01 10:30:55 +00:00
|
|
|
return Utils.formatLongDateTime(parseInt(ts, 10), RootStore.accountSensitiveSettings.isDDMMYYDateFormat, RootStore.accountSensitiveSettings.is24hTimeFormat)
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
|
|
|
onSearchTextChanged: {
|
2022-03-28 11:54:32 +00:00
|
|
|
if (searchPopup.searchText !== "") {
|
|
|
|
searchPopup.loading = true
|
|
|
|
searchMessages(searchPopup.searchText);
|
|
|
|
}
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
|
|
|
onAboutToHide: {
|
|
|
|
if (searchPopupMenu.visible) {
|
|
|
|
searchPopupMenu.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onClosed: {
|
|
|
|
searchPopupMenu.dismiss();
|
|
|
|
}
|
|
|
|
onOpened: {
|
|
|
|
searchPopup.resetSearchSelection();
|
|
|
|
searchPopup.forceActiveFocus()
|
2022-01-27 11:28:27 +00:00
|
|
|
appSearch.store.prepareLocationMenuModel()
|
2021-11-10 08:09:31 +00:00
|
|
|
|
2022-01-27 11:28:27 +00:00
|
|
|
const jsonObj = appSearch.store.getSearchLocationObject()
|
2021-11-10 08:09:31 +00:00
|
|
|
|
|
|
|
if (!jsonObj) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let obj = JSON.parse(jsonObj)
|
|
|
|
if (obj.location === "") {
|
|
|
|
if(obj.subLocation === "") {
|
2022-01-27 11:28:27 +00:00
|
|
|
appSearch.store.setSearchLocation("", "")
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
searchPopup.setSearchSelection(obj.subLocation.text,
|
|
|
|
"",
|
|
|
|
obj.subLocation.imageSource,
|
2022-03-30 15:30:28 +00:00
|
|
|
false,
|
2021-11-10 08:09:31 +00:00
|
|
|
obj.subLocation.iconName,
|
|
|
|
obj.subLocation.identiconColor)
|
|
|
|
|
2022-01-27 11:28:27 +00:00
|
|
|
appSearch.store.setSearchLocation("", obj.subLocation.value)
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (obj.location.title === "Chat") {
|
|
|
|
searchPopup.setSearchSelection(obj.subLocation.text,
|
|
|
|
"",
|
|
|
|
obj.subLocation.imageSource,
|
2022-03-30 15:30:28 +00:00
|
|
|
false,
|
2021-11-10 08:09:31 +00:00
|
|
|
obj.subLocation.iconName,
|
|
|
|
obj.subLocation.identiconColor)
|
|
|
|
|
2022-01-27 11:28:27 +00:00
|
|
|
appSearch.store.setSearchLocation(obj.location.value, obj.subLocation.value)
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
searchPopup.setSearchSelection(obj.location.title,
|
|
|
|
obj.subLocation.text,
|
|
|
|
obj.location.imageSource,
|
2022-03-30 15:30:28 +00:00
|
|
|
false,
|
2021-11-10 08:09:31 +00:00
|
|
|
obj.location.iconName,
|
|
|
|
obj.location.identiconColor)
|
|
|
|
|
2022-01-27 11:28:27 +00:00
|
|
|
appSearch.store.setSearchLocation(obj.location.value, obj.subLocation.value)
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onResultItemClicked: {
|
|
|
|
searchPopup.close()
|
2022-01-27 11:28:27 +00:00
|
|
|
appSearch.store.resultItemClicked(itemId)
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
2022-02-16 16:13:45 +00:00
|
|
|
acceptsTitleClick: function (titleId) {
|
|
|
|
return Utils.isChatKey(titleId)
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
2022-02-16 16:13:45 +00:00
|
|
|
onResultItemTitleClicked: Global.openProfilePopup(titleId)
|
2021-11-10 08:09:31 +00:00
|
|
|
}
|
|
|
|
}
|