chore(Community Settings): OverviewSettingsPanel refactored

- fixed changing position of header when editing community
- simpler integration with SettingsDirtyToastMessage
This commit is contained in:
Michał Cieślak 2023-06-29 11:35:37 +02:00 committed by Michał
parent c3a86184ca
commit 7d02444318
1 changed files with 95 additions and 54 deletions

View File

@ -10,6 +10,8 @@ import StatusQ.Components 0.1
import AppLayouts.Communities.layouts 1.0 import AppLayouts.Communities.layouts 1.0
import AppLayouts.Communities.panels 1.0 import AppLayouts.Communities.panels 1.0
import shared.popups 1.0
import utils 1.0 import utils 1.0
StackLayout { StackLayout {
@ -35,11 +37,10 @@ StackLayout {
property bool owned: false property bool owned: false
function navigateBack() { function navigateBack() {
if (editCommunityPage.dirty) { if (editSettingsPanelLoader.item.dirty)
editCommunityPage.notifyDirty(); settingsDirtyToastMessage.notifyDirty()
} else { else
root.currentIndex = 0; root.currentIndex = 0
}
} }
signal edited(Item item) // item containing edited fields (name, description, logoImagePath, color, options, etc..) signal edited(Item item) // item containing edited fields (name, description, logoImagePath, color, options, etc..)
@ -50,10 +51,13 @@ StackLayout {
clip: true clip: true
SettingsPageLayout { SettingsPage {
title: qsTr("Overview") pageTitle: qsTr("Overview")
content: ColumnLayout { rightPadding: 64
bottomPadding: 64
contentItem: ColumnLayout {
spacing: 16 spacing: 16
RowLayout { RowLayout {
@ -171,61 +175,98 @@ StackLayout {
} }
} }
SettingsPageLayout { SettingsPage {
id: editCommunityPage id: editCommunityPage
title: qsTr("Edit Community") pageTitle: qsTr("Edit Community")
editable: true
content: EditSettingsPanel { contentItem: Loader {
name: root.name id: editSettingsPanelLoader
anchors.fill: parent
description: root.description function reloadContent() {
introMessage: root.introMessage active = false
outroMessage: root.outroMessage active = true
tags: root.tags
selectedTags: root.selectedTags
color: root.color
logoImageData: root.logoImageData
bannerImageData: root.bannerImageData
options {
archiveSupportEnabled: root.archiveSupportEnabled
requestToJoinEnabled: root.requestToJoinEnabled
pinMessagesEnabled: root.pinMessagesEnabled
} }
bottomReservedSpace: editCommunityPage.settingsDirtyToastMessageImplicitSize sourceComponent: EditSettingsPanel {
bottomReservedSpaceActive: editCommunityPage.dirty id: editSettingsPanel
Component.onCompleted: { function isValidRect(r /*rect*/) {
editCommunityPage.dirty = return r.width !== 0 && r.height !== 0
Qt.binding(() => { }
return root.name != name ||
root.description != description || readonly property bool dirty:
root.introMessage != introMessage || root.name != name ||
root.outroMessage != outroMessage || root.description != description ||
root.archiveSupportEnabled != options.archiveSupportEnabled || root.introMessage != introMessage ||
root.requestToJoinEnabled != options.requestToJoinEnabled || root.outroMessage != outroMessage ||
root.pinMessagesEnabled != options.pinMessagesEnabled || root.archiveSupportEnabled != options.archiveSupportEnabled ||
root.color != color || root.requestToJoinEnabled != options.requestToJoinEnabled ||
root.selectedTags != selectedTags || root.pinMessagesEnabled != options.pinMessagesEnabled ||
root.logoImageData != logoImageData || root.color != color ||
logoImagePath.length > 0 || root.selectedTags != selectedTags ||
isValidRect(logoCropRect) || root.logoImageData != logoImageData ||
root.bannerImageData != bannerImageData || logoImagePath.length > 0 ||
bannerPath.length > 0 || isValidRect(logoCropRect) ||
isValidRect(bannerCropRect) root.bannerImageData != bannerImageData ||
}) bannerPath.length > 0 ||
function isValidRect(r /*rect*/) { return r.width !== 0 && r.height !== 0 } isValidRect(bannerCropRect)
name: root.name
description: root.description
introMessage: root.introMessage
outroMessage: root.outroMessage
tags: root.tags
selectedTags: root.selectedTags
color: root.color
logoImageData: root.logoImageData
bannerImageData: root.bannerImageData
options {
archiveSupportEnabled: root.archiveSupportEnabled
requestToJoinEnabled: root.requestToJoinEnabled
pinMessagesEnabled: root.pinMessagesEnabled
}
bottomReservedSpace:
Qt.size(settingsDirtyToastMessage.implicitWidth,
settingsDirtyToastMessage.implicitHeight +
settingsDirtyToastMessage.anchors.bottomMargin)
bottomReservedSpaceActive: dirty
Binding {
target: editSettingsPanel.flickable
property: "bottomMargin"
value: 24
}
} }
} }
onSaveChangesClicked: { SettingsDirtyToastMessage {
root.currentIndex = 0 id: settingsDirtyToastMessage
root.edited(contentItem)
reloadContent()
}
onResetChangesClicked: reloadContent() z: 1
anchors {
bottom: parent.bottom
horizontalCenter: parent.horizontalCenter
bottomMargin: 16
}
active: !!editSettingsPanelLoader.item &&
editSettingsPanelLoader.item.dirty
saveChangesButtonEnabled:
!!editSettingsPanelLoader.item &&
editSettingsPanelLoader.item.saveChangesButtonEnabled
onResetChangesClicked: editSettingsPanelLoader.reloadContent()
onSaveChangesClicked: {
root.currentIndex = 0
root.edited(editSettingsPanelLoader.item)
editSettingsPanelLoader.reloadContent()
}
}
} }
} }