refactor(general): qml cleaning

- Selecting `currentIndex` based on the children placed in the `StackLayout`
component with id `appView` is sorted out since we were referring to the wrong
indexes there in case of walletv2, node and community sections.
- Places which call `Utils.getAppSectionIndex` are updated since we don't have
that method any more.
- Some parts which are not refactored yet are commented.
This commit is contained in:
Sale Djenic 2021-11-10 13:48:22 +01:00
parent 4b6469c373
commit 3f50ab26b8
6 changed files with 71 additions and 74 deletions

View File

@ -25,7 +25,7 @@ StatusAppThreePanelLayout {
handle: SplitViewHandle { implicitWidth: 5 }
property var chatSectionModule // Everything here, within this component need to be set based on this property.
property var store
property var messageStore
@ -34,17 +34,18 @@ StatusAppThreePanelLayout {
signal profileButtonClicked()
signal openAppSearch()
Connections {
target: root.rootStore.chatsModelInst.stickers
onStickerPacksLoaded: {
stickersLoaded = true;
}
}
// Not Refactored
// Connections {
// target: root.rootStore.chatsModelInst.stickers
// onStickerPacksLoaded: {
// stickersLoaded = true;
// }
// }
property var onActivated: function () {
root.rootStore.chatsModelInst.channelView.restorePreviousActiveChannel();
chatColumn.onActivated();
}
// property var onActivated: function () {
// root.rootStore.chatsModelInst.channelView.restorePreviousActiveChannel();
// chatColumn.onActivated();
// }
// Not Refactored
property RootStore rootStore: RootStore {
messageStore: root.messageStore
@ -52,12 +53,12 @@ StatusAppThreePanelLayout {
leftPanel: Loader {
id: contactColumnLoader
sourceComponent: localAccountSensitiveSettings.communitiesEnabled && root.rootStore.chatsModelInst.communities.activeCommunity.active ? communtiyColumnComponent : contactsColumnComponent
sourceComponent: store.isCommunity()? communtiyColumnComponent : contactsColumnComponent
}
centerPanel: ChatColumnView {
id: chatColumn
rootStore: root.rootStore
//rootStore: root.rootStore
chatGroupsListViewCount: contactColumnLoader.item.chatGroupsListViewCount
onOpenAppSearch: {
@ -99,7 +100,7 @@ StatusAppThreePanelLayout {
id: contactsColumnComponent
ContactsColumnView {
// Not Refactored
store: root.rootStore
//store: root.rootStore
onOpenProfileClicked: {
root.profileButtonClicked();
}
@ -113,7 +114,7 @@ StatusAppThreePanelLayout {
Component {
id: communtiyColumnComponent
CommunityColumnView {
store: root.rootStore
store: root.store
pinnedMessagesPopupComponent: chatColumn.pinnedMessagesPopupComponent
}
}
@ -122,7 +123,7 @@ StatusAppThreePanelLayout {
id: groupInfoPopupComponent
GroupInfoPopup {
// Not Refactored
store: root.rootStore
//store: root.rootStore
pinnedMessagesPopupComponent: chatColumn.pinnedMessagesPopupComponent
}
}
@ -143,10 +144,10 @@ StatusAppThreePanelLayout {
//% "Are you sure you want to remove this contact?"
confirmationText: qsTrId("are-you-sure-you-want-to-remove-this-contact-")
onConfirmButtonClicked: {
if (root.rootStore.contactsModuleInst.model.isAdded(chatColumn.contactToRemove)) {
root.rootStore.contactsModuleInst.model.removeContact(chatColumn.contactToRemove)
}
// Not Refactored
// if (root.rootStore.profileModelInst.contacts.isAdded(chatColumn.contactToRemove)) {
// root.rootStore.profileModelInst.contacts.removeContact(chatColumn.contactToRemove)
// }
removeContactConfirmationDialog.parentPopup.close();
removeContactConfirmationDialog.close();
}
@ -155,7 +156,7 @@ StatusAppThreePanelLayout {
MessageContextMenuView {
id: quickActionMessageOptionsMenu
// Not Refactored
store: root.rootStore
// store: root.rootStore
// reactionModel: root.rootStore.emojiReactionsModel
}
}

View File

@ -42,10 +42,10 @@ Item {
property var idMap: ({})
property Timer timer: Timer { }
property var userList
property var onActivated: function () {
if(stackLayoutChatMessages.currentIndex >= 0 && stackLayoutChatMessages.currentIndex < stackLayoutChatMessages.children.length)
stackLayoutChatMessages.children[stackLayoutChatMessages.currentIndex].chatInput.textInput.forceActiveFocus(Qt.MouseFocusReason)
}
// property var onActivated: function () {
// if(stackLayoutChatMessages.currentIndex >= 0 && stackLayoutChatMessages.currentIndex < stackLayoutChatMessages.children.length)
// stackLayoutChatMessages.children[stackLayoutChatMessages.currentIndex].chatInput.textInput.forceActiveFocus(Qt.MouseFocusReason)
// }
signal openAppSearch()

View File

@ -353,16 +353,7 @@ Item {
anchors.fill: parent
currentIndex: {
if(mainModule.activeSection.sectionType === Constants.appSection.chat) {
/*************************************/
// This will be refactored later
if (chatsModel.communities.activeCommunity.active) {
chatLayoutContainer.chatColumn.hideChatInputExtendedArea();
chatsModel.communities.activeCommunity.active = false
}
/*************************************/
return 0
return Constants.appViewStackIndex.chat
}
else if(mainModule.activeSection.sectionType === Constants.appSection.community) {
@ -371,34 +362,32 @@ Item {
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 i
}
}
return 0
// Should never be here, correct index must be returned from the for loop above
console.error("Wrong section type: ", mainModule.activeSection.sectionType,
" or section id: ", mainModule.activeSection.id)
return Constants.appViewStackIndex.community
}
else if(mainModule.activeSection.sectionType === Constants.appSection.wallet) {
return 1
return Constants.appViewStackIndex.wallet
}
else if(mainModule.activeSection.sectionType === Constants.appSection.walletv2) {
return 7
return Constants.appViewStackIndex.walletv2
}
else if(mainModule.activeSection.sectionType === Constants.appSection.browser) {
return 2
return Constants.appViewStackIndex.browser
}
else if(mainModule.activeSection.sectionType === Constants.appSection.timeline) {
return 3
return Constants.appViewStackIndex.timeline
}
else if(mainModule.activeSection.sectionType === Constants.appSection.profile) {
return 4
return Constants.appViewStackIndex.profile
}
else if(mainModule.activeSection.sectionType === Constants.appSection.node) {
return 7
return Constants.appViewStackIndex.node
}
// We should never end up here
@ -429,12 +418,15 @@ Item {
}
}
// NOTE:
// If we ever change stack layout component order we need to updade
// Constants.appViewStackIndex accordingly
ChatLayout {
id: chatLayoutContainer
Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillHeight: true
messageStore: appMain.rootStore.messageStore
onProfileButtonClicked: {
appMain.changeAppSectionBySectionType(Constants.appSection.profile);
}
@ -444,7 +436,7 @@ Item {
}
Component.onCompleted: {
chatSectionModule = mainModule.getChatSectionModule()
store = mainModule.getChatSectionModule()
}
}
@ -507,12 +499,6 @@ Item {
Layout.fillHeight: true
}
UIComponents {
Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillHeight: true
}
WalletV2Layout {
id: walletV2LayoutContainer
Layout.fillWidth: true
@ -546,7 +532,7 @@ Item {
// we cannot return QVariant if we pass another parameter in a function call
// that's why we're using it this way
mainModule.prepareCommunitySectionModuleForCommunityId(model.id)
chatSectionModule = mainModule.getCommunitySectionModule()
store = mainModule.getCommunitySectionModule()
}
}
}
@ -561,19 +547,20 @@ Item {
switch(notificationType){
case Constants.osNotificationType.newContactRequest:
appView.currentIndex = Utils.getAppSectionIndex(Constants.chat)
appView.currentIndex = Constants.appViewStackIndex.chat
appMain.openContactsPopup()
break
case Constants.osNotificationType.acceptedContactRequest:
appView.currentIndex = Utils.getAppSectionIndex(Constants.chat)
appView.currentIndex = Constants.appViewStackIndex.chat
break
case Constants.osNotificationType.joinCommunityRequest:
case Constants.osNotificationType.acceptedIntoCommunity:
case Constants.osNotificationType.rejectedByCommunity:
appView.currentIndex = Utils.getAppSectionIndex(Constants.community)
// Not Refactored - Need to check what community exactly we need to switch to.
// appView.currentIndex = Utils.getAppSectionIndex(Constants.community)
break
case Constants.osNotificationType.newMessage:
appView.currentIndex = Utils.getAppSectionIndex(Constants.chat)
appView.currentIndex = Constants.appViewStackIndex.chat
break
}
}
@ -672,7 +659,8 @@ Item {
CreateChannelPopup {
anchors.centerIn: parent
isEdit: true
pinnedMessagesPopupComponent: chatLayoutContainer.chatColumn.pinnedMessagesPopupComponent
// Not Refactored
// pinnedMessagesPopupComponent: chatLayoutContainer.chatColumn.pinnedMessagesPopupComponent
onClosed: {
destroy()
}

View File

@ -20,6 +20,17 @@ QtObject {
readonly property int node: 7
}
readonly property QtObject appViewStackIndex: QtObject {
readonly property int chat: 0
readonly property int community: 7 // any stack layout children with the index 7 or higher is community
readonly property int wallet: 1
readonly property int walletv2: 6
readonly property int browser: 2
readonly property int timeline: 3
readonly property int profile: 4
readonly property int node: 5
}
readonly property QtObject osNotificationType: QtObject{
readonly property int newContactRequest: 1
readonly property int acceptedContactRequest: 2

View File

@ -80,7 +80,7 @@ StatusWindow {
Action {
shortcut: "Ctrl+W"
enabled: loader.item ? loader.item.currentView !== Utils.getAppSectionIndex(Constants.browser)
enabled: loader.item && !!loader.item.appLayout? loader.item.appLayout.appView.currentIndex === Constants.appViewStackIndex.browser
: true
onTriggered: {
applicationWindow.visible = false;
@ -192,15 +192,14 @@ StatusWindow {
Component.onCompleted: {
Style.changeTheme(localAppSettings.theme, systemPalette.isCurrentSystemThemeDark())
if (!localAppSettings.appSizeInitialized) {
width = Math.min(Screen.desktopAvailableWidth - 125, 1400)
height = Math.min(Screen.desktopAvailableHeight - 125, 840)
localAppSettings.appSizeInitialized = true
}
setX(Qt.application.screens[0].width / 2 - width / 2);
setY(Qt.application.screens[0].height / 2 - height / 2);
if (!localAppSettings.appSizeInitialized) {
width = Screen.desktopAvailableWidth - 125
height = Screen.desktopAvailableHeight - 125
localAppSettings.appSizeInitialized = true
}
applicationWindow.updatePosition();
}
@ -421,11 +420,10 @@ StatusWindow {
signal droppedOnValidScreen(var drop)
property alias droppedUrls: rptDraggedPreviews.model
readonly property int chatView: Utils.getAppSectionIndex(Constants.chat)
property bool enabled: !drag.source && !!loader.item && !!loader.item.appLayout &&
(
// in chat view
(loader.item.appLayout.appView.currentIndex === chatView &&
(loader.item.appLayout.appView.currentIndex === Constants.appViewStackIndex.chat &&
(
// in a one-to-one chat
chatsModel.channelView.activeChannel.chatType === Constants.chatTypeOneToOne ||
@ -433,8 +431,10 @@ StatusWindow {
chatsModel.channelView.activeChannel.chatType === Constants.chatTypePrivateGroupChat
)
) ||
// in timeline view
loader.item.appLayout.appView.currentIndex === Constants.appViewStackIndex.timeline ||
// In community section
loader.item.appLayout.appView.currentIndex === chatsModel.communities.activeCommunity.active
chatsModel.communities.activeCommunity.active
)
width: applicationWindow.width

View File

@ -18,7 +18,6 @@ TabButton {
property int iconRotation: 0
property string iconSource
property string section
property int sectionIndex: Utils.getAppSectionIndex(section)
property bool doNotHandleClick: false
property bool borderOnChecked: false
property bool useLetterIdenticon: false
@ -33,8 +32,6 @@ TabButton {
appMain.changeAppSectionBySectionType(section)
}
checked: sLayout.currentIndex === sectionIndex
icon.height: 24
icon.width: 24
icon.color: {