fix(chat): prevent reloading chat&community sections

Lazily load chat and community sections but do not unload them,
otherwise all temporary data such as scroll position, text input,
cursor position, etc., would vanish

iterates: #10286
This commit is contained in:
Patryk Osmaczko 2023-04-17 22:45:17 +02:00 committed by osmaczko
parent ec7bd963e9
commit 869c3937df
1 changed files with 62 additions and 52 deletions

View File

@ -2,7 +2,6 @@ import QtQuick 2.15
import QtQuick.Controls 2.13 import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13 import QtQuick.Layouts 1.13
import QtMultimedia 5.13 import QtMultimedia 5.13
import Qt.labs.qmlmodels 1.0
import Qt.labs.platform 1.1 import Qt.labs.platform 1.1
import QtQml.Models 2.14 import QtQml.Models 2.14
import QtQml 2.15 import QtQml 2.15
@ -843,7 +842,7 @@ Item {
Loader { Loader {
id: personalChatLayoutLoader id: personalChatLayoutLoader
asynchronous: true asynchronous: true
active: appView.currentIndex === Constants.appViewStackIndex.chat active: false
sourceComponent: { sourceComponent: {
if (appMain.rootStore.mainModuleInst.chatsLoadingFailed) { if (appMain.rootStore.mainModuleInst.chatsLoadingFailed) {
return errorStateComponent return errorStateComponent
@ -853,6 +852,15 @@ Item {
} }
return loadingStateComponent return loadingStateComponent
} }
// Do not unload section data from the memory in order not
// to reset scroll, not send text input and etc during the
// sections switching
Binding on active {
when: appView.currentIndex === Constants.appViewStackIndex.chat
value: true
restoreMode: Binding.RestoreNone
}
Component { Component {
id: loadingStateComponent id: loadingStateComponent
@ -920,14 +928,7 @@ Item {
onCreateCommunityClicked: { onCreateCommunityClicked: {
popups.openPopup(communitiesPortalLayoutContainer.createCommunitiesPopup); popups.openPopup(communitiesPortalLayoutContainer.createCommunitiesPopup);
} }
Component.onCompleted: {
// Do not unload section data from the memory in order not
// to reset scroll, not send text input and etc during the
// sections switching
personalChatLayoutLoader.active = true
}
} }
} }
} }
@ -987,59 +988,68 @@ Item {
} }
Repeater { Repeater {
model: appMain.rootStore.mainModuleInst.sectionsModel model: SortFilterProxyModel {
sourceModel: appMain.rootStore.mainModuleInst.sectionsModel
filters: ValueFilter {
roleName: "sectionType"
value: Constants.appSection.community
}
}
delegate: DelegateChooser { delegate: Loader {
role: "sectionType" id: communityLoader
DelegateChoice {
roleValue: Constants.appSection.community
delegate: Loader { readonly property string sectionId: model.id
id: communityLoader
readonly property string sectionId: model.id
asynchronous: true Layout.fillWidth: true
active: model.loaderActive Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillHeight: true
Layout.fillWidth: true asynchronous: true
Layout.alignment: Qt.AlignLeft | Qt.AlignTop active: false
Layout.fillHeight: true
sourceComponent: ChatLayout { // Do not unload section data from the memory in order not
id: chatLayoutComponent // to reset scroll, not send text input and etc during the
// sections switching
Binding on active {
when: sectionId === appMain.rootStore.mainModuleInst.activeSection.id
value: true
restoreMode: Binding.RestoreNone
}
Binding { sourceComponent: ChatLayout {
target: rootDropAreaPanel id: chatLayoutComponent
property: "enabled"
value: chatLayoutComponent.currentIndex === 0 // Meaning: Chats / channels view
when: visible
restoreMode: Binding.RestoreBindingOrValue
}
emojiPopup: statusEmojiPopup Binding {
stickersPopup: statusStickersPopupLoader.item target: rootDropAreaPanel
sectionItemModel: model property: "enabled"
value: chatLayoutComponent.currentIndex === 0 // Meaning: Chats / channels view
when: visible
restoreMode: Binding.RestoreBindingOrValue
}
rootStore: ChatStores.RootStore { emojiPopup: statusEmojiPopup
contactsStore: appMain.rootStore.contactStore stickersPopup: statusStickersPopupLoader.item
communityTokensStore: appMain.communityTokensStore sectionItemModel: model
emojiReactionsModel: appMain.rootStore.emojiReactionsModel
openCreateChat: createChatView.opened
chatCommunitySectionModule: {
appMain.rootStore.mainModuleInst.prepareCommunitySectionModuleForCommunityId(model.id)
return appMain.rootStore.mainModuleInst.getCommunitySectionModule()
}
}
onProfileButtonClicked: { rootStore: ChatStores.RootStore {
Global.changeAppSectionBySectionType(Constants.appSection.profile); contactsStore: appMain.rootStore.contactStore
} communityTokensStore: appMain.communityTokensStore
emojiReactionsModel: appMain.rootStore.emojiReactionsModel
onOpenAppSearch: { openCreateChat: createChatView.opened
appSearch.openSearchPopup() chatCommunitySectionModule: {
} appMain.rootStore.mainModuleInst.prepareCommunitySectionModuleForCommunityId(model.id)
return appMain.rootStore.mainModuleInst.getCommunitySectionModule()
} }
} }
onProfileButtonClicked: {
Global.changeAppSectionBySectionType(Constants.appSection.profile);
}
onOpenAppSearch: {
appSearch.openSearchPopup()
}
} }
} }
} }