From e1c9f2f93f85984828262101c4a2e288bbbc4b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tinkl?= Date: Fri, 28 Apr 2023 12:35:18 +0200 Subject: [PATCH] perf(AppMain): wrap CommunitiesPortalLayout in a Loader - CommunitiesPortalLayout was the last piece still unconditionally loaded on startup -> fixed - extract the `communitiesStore` into AppMain to be able to reuse it from other components - move the import/create community dialogs to `Popups` (reusability) - cleanup and remove some dead code, fix warnings Iterates #6204 --- ui/app/AppLayouts/Chat/ChatLayout.qml | 9 --- ui/app/AppLayouts/Chat/views/ChatView.qml | 8 -- .../Chat/views/ContactsColumnView.qml | 4 - .../CommunitiesPortalLayout.qml | 43 +---------- .../CommunitiesPortal/popups/qmldir | 2 + .../AppLayouts/Profile/views/AdvancedView.qml | 24 +----- ui/app/AppLayouts/Wallet/WalletLayout.qml | 1 + .../AppLayouts/Wallet/views/LeftTabView.qml | 2 +- ui/app/mainui/AppMain.qml | 74 ++++++++++--------- ui/app/mainui/Popups.qml | 44 +++++++++++ ui/imports/utils/Global.qml | 2 + 11 files changed, 94 insertions(+), 119 deletions(-) create mode 100644 ui/app/AppLayouts/CommunitiesPortal/popups/qmldir diff --git a/ui/app/AppLayouts/Chat/ChatLayout.qml b/ui/app/AppLayouts/Chat/ChatLayout.qml index 55c24d2b80..a6a174291e 100644 --- a/ui/app/AppLayouts/Chat/ChatLayout.qml +++ b/ui/app/AppLayouts/Chat/ChatLayout.qml @@ -23,8 +23,6 @@ StackLayout { property var emojiPopup property var stickersPopup - signal importCommunityClicked() - signal createCommunityClicked() signal profileButtonClicked() signal openAppSearch() @@ -33,7 +31,6 @@ StackLayout { } Loader { - readonly property var chatItem: root.rootStore.chatCommunitySectionModule sourceComponent: chatItem.isCommunity() && chatItem.requiresTokenPermissionToJoin && !chatItem.amIMember ? joinCommunityViewComponent : chatViewComponent } @@ -116,12 +113,6 @@ StackLayout { onCommunityInfoButtonClicked: root.currentIndex = 1 onCommunityManageButtonClicked: root.currentIndex = 1 - onImportCommunityClicked: { - root.importCommunityClicked(); - } - onCreateCommunityClicked: { - root.createCommunityClicked(); - } onProfileButtonClicked: { root.profileButtonClicked() } diff --git a/ui/app/AppLayouts/Chat/views/ChatView.qml b/ui/app/AppLayouts/Chat/views/ChatView.qml index 50ea5ec021..28d8d2ce62 100644 --- a/ui/app/AppLayouts/Chat/views/ChatView.qml +++ b/ui/app/AppLayouts/Chat/views/ChatView.qml @@ -38,8 +38,6 @@ StatusSectionLayout { signal communityManageButtonClicked() signal profileButtonClicked() signal openAppSearch() - signal importCommunityClicked() - signal createCommunityClicked() Connections { target: root.rootStore.stickersStore.stickersModule @@ -139,12 +137,6 @@ StatusSectionLayout { onOpenAppSearch: { root.openAppSearch() } - onImportCommunityClicked: { - root.importCommunityClicked(); - } - onCreateCommunityClicked: { - root.createCommunityClicked(); - } onAddRemoveGroupMemberClicked: { headerContent.addRemoveGroupMember() } diff --git a/ui/app/AppLayouts/Chat/views/ContactsColumnView.qml b/ui/app/AppLayouts/Chat/views/ContactsColumnView.qml index 6c6950e44c..dc8ab2674f 100644 --- a/ui/app/AppLayouts/Chat/views/ContactsColumnView.qml +++ b/ui/app/AppLayouts/Chat/views/ContactsColumnView.qml @@ -32,12 +32,8 @@ Item { property var contactsStore property var emojiPopup - // Not Refactored Yet - //property int chatGroupsListViewCount: channelList.model.count signal openProfileClicked() signal openAppSearch() - signal importCommunityClicked() - signal createCommunityClicked() signal addRemoveGroupMemberClicked() // main layout diff --git a/ui/app/AppLayouts/CommunitiesPortal/CommunitiesPortalLayout.qml b/ui/app/AppLayouts/CommunitiesPortal/CommunitiesPortalLayout.qml index 827bce038d..28e3236a58 100644 --- a/ui/app/AppLayouts/CommunitiesPortal/CommunitiesPortalLayout.qml +++ b/ui/app/AppLayouts/CommunitiesPortal/CommunitiesPortalLayout.qml @@ -16,8 +16,6 @@ import shared.panels 1.0 import SortFilterProxyModel 0.2 -import AppLayouts.CommunitiesPortal.stores 1.0 - import "controls" import "popups" import "views" @@ -25,16 +23,12 @@ import "views" StatusSectionLayout { id: root - property CommunitiesStore communitiesStore: CommunitiesStore {} - property var importCommunitiesPopup: importCommunitiesPopupComponent - property var createCommunitiesPopup: createCommunitiesPopupComponent - property var discordImportProgressPopup: discordImportProgressDialog + property var communitiesStore property alias assetsModel: communitiesGrid.assetsModel property alias collectiblesModel: communitiesGrid.collectiblesModel objectName: "communitiesPortalLayout" - notificationCount: activityCenterStore.unreadNotificationsCount onNotificationButtonClicked: Global.openActivityCenterPopup() onVisibleChanged: { @@ -133,7 +127,7 @@ StatusSectionLayout { Layout.preferredHeight: 38 text: qsTr("Import using key") verticalPadding: 0 - onClicked: Global.openPopup(importCommunitiesPopupComponent) + onClicked: Global.importCommunityPopupRequested() } StatusButton { @@ -195,28 +189,6 @@ StatusSectionLayout { } } - Component { - id: importCommunitiesPopupComponent - ImportCommunityPopup { - anchors.centerIn: parent - store: root.communitiesStore - onClosed: { - destroy() - } - } - } - - Component { - id: createCommunitiesPopupComponent - CreateCommunityPopup { - anchors.centerIn: parent - store: root.communitiesStore - onClosed: { - destroy() - } - } - } - Component { id: chooseCommunityCreationTypePopupComponent StatusDialog { @@ -236,7 +208,7 @@ StatusSectionLayout { icon.name: "favourite" onButtonClicked: { chooseCommunityCreationTypePopup.close() - Global.openPopup(createCommunitiesPopupComponent) + Global.createCommunityPopupRequested(false /*isDiscordImport*/) } } CommunityBanner { @@ -250,17 +222,10 @@ StatusSectionLayout { buttonLoading: importInProgress onButtonClicked: { chooseCommunityCreationTypePopup.close() - Global.openPopup(createCommunitiesPopupComponent, {isDiscordImport: true}) + Global.createCommunityPopupRequested(true /*isDiscordImport*/) } } } } } - - Component { - id: discordImportProgressDialog - DiscordImportProgressDialog { - store: root.communitiesStore - } - } } diff --git a/ui/app/AppLayouts/CommunitiesPortal/popups/qmldir b/ui/app/AppLayouts/CommunitiesPortal/popups/qmldir new file mode 100644 index 0000000000..ecfed50ab0 --- /dev/null +++ b/ui/app/AppLayouts/CommunitiesPortal/popups/qmldir @@ -0,0 +1,2 @@ +CreateCommunityPopup 1.0 CreateCommunityPopup.qml +DiscordImportProgressDialog 1.0 DiscordImportProgressDialog.qml diff --git a/ui/app/AppLayouts/Profile/views/AdvancedView.qml b/ui/app/AppLayouts/Profile/views/AdvancedView.qml index 8b57662d1d..14488ded95 100644 --- a/ui/app/AppLayouts/Profile/views/AdvancedView.qml +++ b/ui/app/AppLayouts/Profile/views/AdvancedView.qml @@ -133,7 +133,7 @@ SettingsContentBase { } // TODO: replace with StatusQ component - StatusSettingsLineButton { + StatusSettingsLineButton { anchors.leftMargin: 0 anchors.rightMargin: 0 text: qsTr("WakuV2 Store") @@ -515,27 +515,5 @@ SettingsContentBase { close() } } - - Component { - id: errorMessageDialogCmp - StatusDialog { - id: errorMessageDialog - property string errorMessage: "" - title: qsTr("An error occoured") - - StatusBaseText { - anchors.fill: parent - text: { - if (errorMessageDialog.errorMessage.indexOf("address already in use") > -1) { - return qsTr("The specified torrent client port is already in use.") - } - return errorMessageDialog.errorMessage - } - } - - standardButtons: Dialog.Ok - onAccepted: errorMessageDialog.close() - } - } } } diff --git a/ui/app/AppLayouts/Wallet/WalletLayout.qml b/ui/app/AppLayouts/Wallet/WalletLayout.qml index eadd79e636..e5ea16ee95 100644 --- a/ui/app/AppLayouts/Wallet/WalletLayout.qml +++ b/ui/app/AppLayouts/Wallet/WalletLayout.qml @@ -67,6 +67,7 @@ Item { width: root.width backButtonName: RootStore.backButtonName notificationCount: activityCenterStore.unreadNotificationsCount + hasUnseenNotifications: activityCenterStore.hasUnseenNotifications onNotificationButtonClicked: Global.openActivityCenterPopup() onBackButtonClicked: { diff --git a/ui/app/AppLayouts/Wallet/views/LeftTabView.qml b/ui/app/AppLayouts/Wallet/views/LeftTabView.qml index b8d520e1f7..cc905f7132 100644 --- a/ui/app/AppLayouts/Wallet/views/LeftTabView.qml +++ b/ui/app/AppLayouts/Wallet/views/LeftTabView.qml @@ -198,7 +198,7 @@ Rectangle { width: parent.width font.weight: Font.Medium font.pixelSize: 22 - loading: RootStore.currentAccount.assetsLoading + loading: RootStore.assetsLoading visible: !networkConnectionStore.accountBalanceNotAvailable } diff --git a/ui/app/mainui/AppMain.qml b/ui/app/mainui/AppMain.qml index f0018d124b..117a32788f 100644 --- a/ui/app/mainui/AppMain.qml +++ b/ui/app/mainui/AppMain.qml @@ -34,6 +34,7 @@ import StatusQ.Core 0.1 import AppLayouts.Browser.stores 1.0 as BrowserStores import AppLayouts.stores 1.0 import AppLayouts.Chat.stores 1.0 as ChatStores +import AppLayouts.CommunitiesPortal.stores 1.0 import mainui.activitycenter.stores 1.0 import mainui.activitycenter.popups 1.0 @@ -57,6 +58,7 @@ Item { property ActivityCenterStore activityCenterStore: ActivityCenterStore {} property NetworkConnectionStore networkConnectionStore: NetworkConnectionStore {} property CommunityTokensStore communityTokensStore: CommunityTokensStore {} + property CommunitiesStore communitiesStore: CommunitiesStore {} // set from main.qml property var sysPalette @@ -114,6 +116,7 @@ Item { id: popups popupParent: appMain rootStore: appMain.rootStore + communitiesStore: appMain.communitiesStore } Connections { @@ -192,7 +195,7 @@ Item { } function onSwitchToCommunity(communityId: string) { - communitiesPortalLayoutContainer.communitiesStore.setActiveCommunity(communityId) + appMain.communitiesStore.setActiveCommunity(communityId) } } @@ -242,10 +245,13 @@ Item { } } - StatusEmojiPopup { + Loader { id: statusEmojiPopup - width: 360 - height: 440 + active: appMain.rootStore.mainModuleInst.sectionsLoaded + sourceComponent: StatusEmojiPopup { + width: 360 + height: 440 + } } Loader { @@ -558,15 +564,15 @@ Item { ModuleWarning { Layout.fillWidth: true - readonly property int progress: communitiesPortalLayoutContainer.communitiesStore.discordImportProgress - readonly property bool inProgress: (progress > 0 && progress < 100) || communitiesPortalLayoutContainer.communitiesStore.discordImportInProgress + readonly property int progress: appMain.communitiesStore.discordImportProgress + readonly property bool inProgress: (progress > 0 && progress < 100) || appMain.communitiesStore.discordImportInProgress readonly property bool finished: progress >= 100 - readonly property bool cancelled: communitiesPortalLayoutContainer.communitiesStore.discordImportCancelled - readonly property bool stopped: communitiesPortalLayoutContainer.communitiesStore.discordImportProgressStopped - readonly property int errors: communitiesPortalLayoutContainer.communitiesStore.discordImportErrorsCount - readonly property int warnings: communitiesPortalLayoutContainer.communitiesStore.discordImportWarningsCount - readonly property string communityId: communitiesPortalLayoutContainer.communitiesStore.discordImportCommunityId - readonly property string communityName: communitiesPortalLayoutContainer.communitiesStore.discordImportCommunityName + readonly property bool cancelled: appMain.communitiesStore.discordImportCancelled + readonly property bool stopped: appMain.communitiesStore.discordImportProgressStopped + readonly property int errors: appMain.communitiesStore.discordImportErrorsCount + readonly property int warnings: appMain.communitiesStore.discordImportWarningsCount + readonly property string communityId: appMain.communitiesStore.discordImportCommunityId + readonly property string communityName: appMain.communitiesStore.discordImportCommunityName active: !cancelled && (inProgress || finished || stopped) type: errors ? ModuleWarning.Type.Danger : ModuleWarning.Type.Success @@ -595,12 +601,12 @@ Item { return "" } - onLinkActivated: popups.openPopup(communitiesPortalLayoutContainer.discordImportProgressPopup) + onLinkActivated: popups.openDiscordImportProgressPopup() progressValue: progress closeBtnVisible: finished || stopped buttonText: finished && !errors ? qsTr("Visit your Community") : "" onClicked: function() { - communitiesPortalLayoutContainer.communitiesStore.setActiveCommunity(communityId) + appMain.communitiesStore.setActiveCommunity(communityId) } onCloseClicked: { hide(); @@ -610,7 +616,7 @@ Item { ModuleWarning { id: downloadingArchivesBanner Layout.fillWidth: true - active: communitiesPortalLayoutContainer.communitiesStore.downloadingCommunityHistoryArchives + active: appMain.communitiesStore.downloadingCommunityHistoryArchives type: ModuleWarning.Danger text: qsTr("Downloading message history archives, DO NOT CLOSE THE APP until this banner disappears.") closeBtnVisible: false @@ -881,7 +887,7 @@ Item { StatusBaseText { text: qsTr("Loading sections...") } - LoadingAnimation {} + LoadingAnimation { anchors.verticalCenter: parent.verticalCenter } } } } @@ -919,7 +925,7 @@ Item { chatCommunitySectionModule: appMain.rootStore.mainModuleInst.getChatSectionModule() networkConnectionStore: appMain.networkConnectionStore } - emojiPopup: statusEmojiPopup + emojiPopup: statusEmojiPopup.item stickersPopup: statusStickersPopupLoader.item onProfileButtonClicked: { @@ -929,23 +935,21 @@ Item { onOpenAppSearch: { appSearch.openSearchPopup() } - - onImportCommunityClicked: { - popups.openPopup(communitiesPortalLayoutContainer.importCommunitiesPopup); - } - - onCreateCommunityClicked: { - popups.openPopup(communitiesPortalLayoutContainer.createCommunitiesPopup); - } } } } - CommunitiesPortalLayout { - id: communitiesPortalLayoutContainer - - assetsModel: rootChatStore.assetsModel - collectiblesModel: rootChatStore.collectiblesModel + Loader { + active: appView.currentIndex === Constants.appViewStackIndex.communitiesPortal + asynchronous: true + CommunitiesPortalLayout { + anchors.fill: parent + communitiesStore: appMain.communitiesStore + assetsModel: appMain.rootChatStore.assetsModel + collectiblesModel: appMain.rootChatStore.collectiblesModel + notificationCount: appMain.activityCenterStore.unreadNotificationsCount + hasUnseenNotifications: activityCenterStore.hasUnseenNotifications + } } Loader { @@ -954,7 +958,7 @@ Item { sourceComponent: WalletLayout { store: appMain.rootStore contactsStore: appMain.rootStore.profileSectionStore.contactsStore - emojiPopup: statusEmojiPopup + emojiPopup: statusEmojiPopup.item sendModalPopup: sendModal networkConnectionStore: appMain.networkConnectionStore } @@ -987,7 +991,7 @@ Item { store: appMain.rootStore.profileSectionStore globalStore: appMain.rootStore systemPalette: appMain.sysPalette - emojiPopup: statusEmojiPopup + emojiPopup: statusEmojiPopup.item networkConnectionStore: appMain.networkConnectionStore } } @@ -1039,7 +1043,7 @@ Item { restoreMode: Binding.RestoreBindingOrValue } - emojiPopup: statusEmojiPopup + emojiPopup: statusEmojiPopup.item stickersPopup: statusStickersPopupLoader.item sectionItemModel: model @@ -1090,7 +1094,7 @@ Item { openCreateChat: createChatView.opened chatCommunitySectionModule: appMain.rootStore.mainModuleInst.getChatSectionModule() } - emojiPopup: statusEmojiPopup + emojiPopup: statusEmojiPopup.item stickersPopup: statusStickersPopupLoader.item } } @@ -1322,7 +1326,7 @@ Item { settings = {} } - // Set Status links as true. We intercept thoseURLs so it is privacy-safe + // Set Status links as true. We intercept those URLs so it is privacy-safe if (!settings[Constants.deepLinkPrefix] || !settings[Constants.joinStatusLink]) { settings[Constants.deepLinkPrefix] = true settings[Constants.joinStatusLink] = true diff --git a/ui/app/mainui/Popups.qml b/ui/app/mainui/Popups.qml index c47d3714f7..4f91e1615d 100644 --- a/ui/app/mainui/Popups.qml +++ b/ui/app/mainui/Popups.qml @@ -2,6 +2,7 @@ import QtQuick 2.15 import AppLayouts.Chat.popups 1.0 import AppLayouts.Profile.popups 1.0 +import AppLayouts.CommunitiesPortal.popups 1.0 import shared.popups 1.0 import shared.status 1.0 @@ -13,6 +14,7 @@ QtObject { required property var popupParent required property var rootStore + property var communitiesStore property var activePopupComponents: [] @@ -34,6 +36,8 @@ QtObject { Global.openEditDisplayNamePopup.connect(openEditDisplayNamePopup) Global.openPinnedMessagesPopupRequested.connect(openPinnedMessagesPopup) Global.openCommunityProfilePopupRequested.connect(openCommunityProfilePopup) + Global.createCommunityPopupRequested.connect(openCreateCommunityPopup) + Global.importCommunityPopupRequested.connect(openImportCommunityPopup) Global.openPopupRequested.connect(openPopup) } @@ -182,6 +186,18 @@ QtObject { openPopup(communityProfilePopup, {store: store, community: community, chatCommunitySectionModule: chatCommunitySectionModule}) } + function openCreateCommunityPopup(isDiscordImport) { + openPopup(createCommunitiesPopupComponent, {isDiscordImport: isDiscordImport}) + } + + function openImportCommunityPopup() { + openPopup(importCommunitiesPopupComponent) + } + + function openDiscordImportProgressPopup() { + openPopup(discordImportProgressDialog) + } + readonly property list _components: [ Component { id: contactVerificationRequestPopupComponent @@ -390,6 +406,34 @@ QtObject { } onClosed: destroy() } + }, + + Component { + id: importCommunitiesPopupComponent + ImportCommunityPopup { + store: root.communitiesStore + onClosed: { + destroy() + } + } + }, + + Component { + id: createCommunitiesPopupComponent + CreateCommunityPopup { + anchors.centerIn: parent + store: root.communitiesStore + onClosed: { + destroy() + } + } + }, + + Component { + id: discordImportProgressDialog + DiscordImportProgressDialog { + store: root.communitiesStore + } } ] } diff --git a/ui/imports/utils/Global.qml b/ui/imports/utils/Global.qml index 344ac8e441..6555f0ae3e 100644 --- a/ui/imports/utils/Global.qml +++ b/ui/imports/utils/Global.qml @@ -50,6 +50,8 @@ QtObject { signal openSendModal(string address) signal switchToCommunity(string communityId) + signal createCommunityPopupRequested(bool isDiscordImport) + signal importCommunityPopupRequested() signal playSendMessageSound() signal playNotificationSound()