From a99c66ca8b9c2543e3ae4326f7f9d136d610de0f Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 3 Mar 2022 15:01:11 -0500 Subject: [PATCH] refactor(ChatColumnView): move duplicated code to function --- .../AppLayouts/Chat/views/ChatColumnView.qml | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/ui/app/AppLayouts/Chat/views/ChatColumnView.qml b/ui/app/AppLayouts/Chat/views/ChatColumnView.qml index 5690f2c7b0..e0393ca713 100644 --- a/ui/app/AppLayouts/Chat/views/ChatColumnView.qml +++ b/ui/app/AppLayouts/Chat/views/ChatColumnView.qml @@ -131,9 +131,21 @@ Item { // This is kind of a solution for applying backend refactored changes with the minimal qml changes. // The best would be if we made qml to follow the struct we have on the backend side. Repeater { + id: chatRepeater model: parentModule && parentModule.model delegate: delegateChooser + function isChatActive(chatContentModule, activeChatId, activeSubItemId, isSectionActive) { + if(!chatContentModule || !isSectionActive) + return false + + let myChatId = chatContentModule.getMyChatId() + if(myChatId === activeChatId || myChatId === activeSubItemId) + return true + + return false + } + DelegateChooser { id: delegateChooser role: "type" @@ -149,6 +161,8 @@ Item { delegate: ChatContentView { width: parent.width clip: true + // dynamically calculate the height of the view, if the active one is the current one + // then set the height to parent otherwise set it to 0 height: isActiveChannel ? parent.height : 0 rootStore: root.rootStore contactsStore: root.contactsStore @@ -157,18 +171,7 @@ Item { sendTransactionWithEnsModal: cmpSendTransactionWithEns stickersLoaded: root.stickersLoaded isBlocked: model.blocked - isActiveChannel: { - // dynamically calculate the height of the view, if the active one is the current one - // then set the height to parent otherwise set it to 0 - if(!chatContentModule || !isSectionActive) - return false - - let myChatId = chatContentModule.getMyChatId() - if(myChatId === root.activeChatId || myChatId === root.activeSubItemId) - return true - - return false - } + isActiveChannel: chatRepeater.isChatActive(chatContentModule, root.activeChatId, root.activeSubItemId, root.isSectionActive) Component.onCompleted: { parentModule.prepareChatContentModuleForChatId(model.itemId) chatContentModule = parentModule.getChatContentModule() @@ -188,18 +191,7 @@ Item { sendTransactionWithEnsModal: cmpSendTransactionWithEns stickersLoaded: root.stickersLoaded isBlocked: model.blocked - isActiveChannel: { - // dynamically calculate the height of the view, if the active one is the current one - // then set the height to parent otherwise set it to 0 - if(!chatContentModule || !isSectionActive) - return false - - let myChatId = chatContentModule.getMyChatId() - if(myChatId === root.activeChatId || myChatId === root.activeSubItemId) - return true - - return false - } + isActiveChannel: chatRepeater.isChatActive(chatContentModule, root.activeChatId, root.activeSubItemId, root.isSectionActive) Component.onCompleted: { parentModule.prepareChatContentModuleForChatId(itemId) chatContentModule = parentModule.getChatContentModule()