refactor(@desktop/general): qml `ChatLayout` component added for the `Chat` section and for each community

This commit is contained in:
Sale Djenic 2021-11-01 21:10:50 +01:00
parent eca74532ac
commit 0fa88be513
7 changed files with 93 additions and 8 deletions

View File

@ -130,10 +130,8 @@ method load*(self: Module) =
self.view.load() self.view.load()
if(self.controller.isCommunity()): if(self.controller.isCommunity()):
singletonInstance.engine.setRootContextProperty("communitySectionModule", self.viewVariant)
self.buildCommunityUI() self.buildCommunityUI()
else: else:
singletonInstance.engine.setRootContextProperty("chatSectionModule", self.viewVariant)
self.buildChatUI() self.buildChatUI()
self.inputAreaModule.load() self.inputAreaModule.load()
@ -189,4 +187,7 @@ method activeItemSubItemSet*(self: Module, itemId: string, subItemId: string) =
let subItem = item.subItems.getItemById(subItemId) let subItem = item.subItems.getItemById(subItemId)
self.view.model().setActiveItemSubItem(itemId, subItemId) self.view.model().setActiveItemSubItem(itemId, subItemId)
self.view.activeItemSubItemSet(item, subItem) self.view.activeItemSubItemSet(item, subItem)
method getChatSection*(self: Module): QVariant =
return self.viewVariant

View File

@ -1,3 +1,5 @@
import NimQml
method delete*(self: AccessInterface) {.base.} = method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
@ -6,3 +8,6 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method getChatSection*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -275,3 +275,13 @@ method disableSection*[T](self: Module[T], sectionType: SectionType) =
method setUserStatus*[T](self: Module[T], status: bool) = method setUserStatus*[T](self: Module[T], status: bool) =
self.controller.setUserStatus(status) self.controller.setUserStatus(status)
method getChatSection*[T](self: Module[T]): QVariant =
return self.chatSectionModule.getChatSection()
method getCommunitySection*[T](self: Module[T], communityId: string): QVariant =
if(not self.communitySectionsModule.contains(communityId)):
echo "main-module, unexisting community key: ", communityId
return
return self.communitySectionsModule[communityId].getChatSection()

View File

@ -1,3 +1,4 @@
import NimQml
import ../item import ../item
method viewDidLoad*(self: AccessInterface) {.base.} = method viewDidLoad*(self: AccessInterface) {.base.} =
@ -10,4 +11,10 @@ method setActiveSection*(self: AccessInterface, item: Item) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method setUserStatus*(self: AccessInterface, status: bool) {.base.} = method setUserStatus*(self: AccessInterface, status: bool) {.base.} =
raise newException(ValueError, "No implementation available")
method getChatSection*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")
method getCommunitySection*(self: AccessInterface, communityId: string): QVariant {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -10,6 +10,7 @@ QtObject:
modelVariant: QVariant modelVariant: QVariant
activeSection: ActiveSection activeSection: ActiveSection
activeSectionVariant: QVariant activeSectionVariant: QVariant
tmpCommunityId: string # shouldn't be used anywhere except in setCommunitySection/getCommunitySection procs
proc delete*(self: View) = proc delete*(self: View) =
self.model.delete self.model.delete
@ -99,3 +100,21 @@ QtObject:
proc setUserStatus*(self: View, status: bool) {.slot.} = proc setUserStatus*(self: View, status: bool) {.slot.} =
self.delegate.setUserStatus(status) self.delegate.setUserStatus(status)
# Since we cannot return QVariant from the proc which has arguments, so cannot have proc like this:
# getCommunitySection(self: View, communityId: string): QVariant {.slot.}
# we're using combinaiton of
# setCommunitySection/getCommunitySection procs
proc setCommunitySection*(self: View, communityId: string) {.slot.} =
self.tmpCommunityId = communityId
proc getCommunitySection*(self: View): QVariant {.slot.} =
var communityVariant = self.delegate.getCommunitySection(self.tmpCommunityId)
self.tmpCommunityId = ""
if(communityVariant.isNil):
return newQVariant()
return communityVariant
proc getChatSection*(self: View): QVariant {.slot.} =
return self.delegate.getChatSection()

View File

@ -25,6 +25,8 @@ StatusAppThreePanelLayout {
handle: SplitViewHandle { implicitWidth: 5 } handle: SplitViewHandle { implicitWidth: 5 }
property var chatSectionModule // Everything here, within this component need to be set based on this property.
property var messageStore property var messageStore
property alias chatColumn: chatColumn property alias chatColumn: chatColumn

View File

@ -2,6 +2,7 @@ import QtQuick 2.13
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 utils 1.0 import utils 1.0
import shared 1.0 import shared 1.0
@ -360,12 +361,21 @@ Item {
} }
else if(mainModule.activeSection.sectionType === Constants.appSection.community) { else if(mainModule.activeSection.sectionType === Constants.appSection.community) {
/*************************************/ for(let i = this.children.length - 1; i >=0; i--)
// This will be refactored later {
chatsModel.communities.setActiveCommunity(mainModule.activeSection.id) var obj = this.children[i];
/*************************************/ if(obj && obj.sectionId == mainModule.activeSection.id)
{
/*************************************/
// This will be refactored/removed later
chatsModel.communities.setActiveCommunity(mainModule.activeSection.id)
/*************************************/
return 99 //Don't know why, but that's how it was in Utils::getAppSectionIndex function. return i
}
}
return 0
} }
else if(mainModule.activeSection.sectionType === Constants.appSection.wallet) { else if(mainModule.activeSection.sectionType === Constants.appSection.wallet) {
return 1 return 1
@ -423,6 +433,10 @@ Item {
onProfileButtonClicked: { onProfileButtonClicked: {
appMain.changeAppSectionBySectionType(Constants.appSection.profile); appMain.changeAppSectionBySectionType(Constants.appSection.profile);
} }
Component.onCompleted: {
chatSectionModule = mainModule.getChatSection()
}
} }
WalletLayout { WalletLayout {
@ -496,6 +510,33 @@ Item {
Layout.alignment: Qt.AlignLeft | Qt.AlignTop Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillHeight: true Layout.fillHeight: true
} }
Repeater{
model: mainModule.sectionsModel
delegate: DelegateChooser {
id: delegateChooser
role: "sectionType"
DelegateChoice {
roleValue: Constants.appSection.community
delegate: ChatLayout {
property string sectionId: model.id
Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillHeight: true
onProfileButtonClicked: {
appMain.changeAppSectionBySectionType(Constants.appSection.profile);
}
Component.onCompleted: {
mainModule.setCommunitySection(model.id)
chatSectionModule = mainModule.getCommunitySection()
}
}
}
}
}
} }
Connections { Connections {