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

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
@ -854,6 +853,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
Item { Item {
@ -921,13 +929,6 @@ 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,24 +988,35 @@ Item {
} }
Repeater { Repeater {
model: appMain.rootStore.mainModuleInst.sectionsModel model: SortFilterProxyModel {
sourceModel: appMain.rootStore.mainModuleInst.sectionsModel
delegate: DelegateChooser { filters: ValueFilter {
role: "sectionType" roleName: "sectionType"
DelegateChoice { value: Constants.appSection.community
roleValue: Constants.appSection.community }
}
delegate: Loader { delegate: Loader {
id: communityLoader id: communityLoader
readonly property string sectionId: model.id
asynchronous: true readonly property string sectionId: model.id
active: model.loaderActive
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft | Qt.AlignTop Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillHeight: true Layout.fillHeight: true
asynchronous: true
active: false
// 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: sectionId === appMain.rootStore.mainModuleInst.activeSection.id
value: true
restoreMode: Binding.RestoreNone
}
sourceComponent: ChatLayout { sourceComponent: ChatLayout {
id: chatLayoutComponent id: chatLayoutComponent
@ -1042,8 +1054,6 @@ Item {
} }
} }
} }
}
}
Loader { Loader {
id: createChatView id: createChatView