chore(AirdropSettingsPanel) simplified, storybook page improved

- added "back" navigation in storybook
- no need to use states and StackViewStates component
This commit is contained in:
Michał Cieślak 2023-06-30 11:00:04 +02:00 committed by Michał
parent 6ccb832800
commit 7f3f425a36
3 changed files with 49 additions and 71 deletions

View File

@ -61,17 +61,25 @@ SplitView {
} }
} }
Button {
text: "Back"
onClicked: loader.item.navigateBack()
}
Rectangle { Rectangle {
SplitView.fillWidth: true SplitView.fillWidth: true
SplitView.fillHeight: true SplitView.fillHeight: true
color: Theme.palette.statusAppLayout.rightPanelBackgroundColor color: Theme.palette.statusAppLayout.rightPanelBackgroundColor
Loader { Loader {
id: loader
anchors.fill: parent anchors.fill: parent
active: globalUtilsReady && mainModuleReady active: globalUtilsReady && mainModuleReady
sourceComponent: AirdropsSettingsPanel { sourceComponent: AirdropsSettingsPanel {
id: airdropsSettingsPanel id: airdropsSettingsPanel
anchors.fill: parent anchors.fill: parent
anchors.topMargin: 50 anchors.topMargin: 50
assetsModel: AssetsModel {} assetsModel: AssetsModel {}

View File

@ -1,16 +1,14 @@
import QtQuick 2.14 import QtQuick 2.15
import QtQuick.Controls 2.14 import QtQuick.Controls 2.15
import QtQuick.Layouts 1.14
import StatusQ.Controls 0.1 import StatusQ.Controls 0.1
import StatusQ.Core.Utils 0.1
import AppLayouts.Communities.layouts 1.0 import AppLayouts.Communities.layouts 1.0
import AppLayouts.Communities.views 1.0 import AppLayouts.Communities.views 1.0
import utils 1.0 import utils 1.0
SettingsPageLayout { StackView {
id: root id: root
// id, name, image, color, owner properties expected // id, name, image, color, owner properties expected
@ -28,18 +26,21 @@ SettingsPageLayout {
property var airdropFees: null property var airdropFees: null
property int viewWidth: 560 // by design property int viewWidth: 560 // by design
property string previousPageName: depth > 1 ? qsTr("Airdrops") : ""
signal airdropClicked(var airdropTokens, var addresses, var membersPubKeys) signal airdropClicked(var airdropTokens, var addresses, var membersPubKeys)
signal airdropFeesRequested(var contractKeysAndAmounts, var addresses) signal airdropFeesRequested(var contractKeysAndAmounts, var addresses)
signal navigateToMintTokenSettings(bool isAssetType) signal navigateToMintTokenSettings(bool isAssetType)
function navigateBack() { function navigateBack() {
stackManager.pop(StackView.Immediate) pop(StackView.Immediate)
} }
function selectToken(key, amount, type) { function selectToken(key, amount, type) {
if (depth > 1)
pop(StackView.Immediate)
root.push(newAirdropView, StackView.Immediate)
d.selectToken(key, amount, type) d.selectToken(key, amount, type)
} }
@ -50,56 +51,21 @@ SettingsPageLayout {
QtObject { QtObject {
id: d id: d
readonly property string welcomeViewState: "WELCOME"
readonly property string newAirdropViewState: "NEW_AIRDROP"
readonly property string welcomePageTitle: qsTr("Airdrops")
readonly property string newAirdropViewPageTitle: qsTr("New airdrop")
signal selectToken(string key, int amount, int type) signal selectToken(string key, int amount, int type)
signal addAddresses(var addresses) signal addAddresses(var addresses)
} }
content: StackView { initialItem: SettingsPage {
anchors.fill: parent implicitWidth: 0
initialItem: welcomeView pageTitle: qsTr("Airdrops")
Component.onCompleted: stackManager.pushInitialState(d.welcomeViewState) buttons: StatusButton {
} text: qsTr("New Airdrop")
state: stackManager.currentState onClicked: root.push(newAirdropView, StackView.Immediate)
states: [
State {
name: d.welcomeViewState
PropertyChanges {target: root; title: d.welcomePageTitle}
PropertyChanges {target: root; previousPageName: ""}
PropertyChanges {target: root; primaryHeaderButton.visible: true}
PropertyChanges {target: root; primaryHeaderButton.text: qsTr("New Airdrop")}
},
State {
name: d.newAirdropViewState
PropertyChanges {target: root; title: d.newAirdropViewPageTitle}
PropertyChanges {target: root; previousPageName: d.welcomePageTitle}
PropertyChanges {target: root; primaryHeaderButton.visible: false}
} }
]
onPrimaryHeaderButtonClicked: { contentItem: WelcomeSettingsView {
if(root.state !== d.newAirdropViewState)
stackManager.push(d.newAirdropViewState, newAirdropView, null, StackView.Immediate)
}
StackViewStates {
id: stackManager
stackView: root.contentItem
}
// Mint tokens possible view contents:
Component {
id: welcomeView
WelcomeSettingsView {
viewWidth: root.viewWidth viewWidth: root.viewWidth
image: Style.png("community/airdrops8_1") image: Style.png("community/airdrops8_1")
title: qsTr("Airdrop community tokens") title: qsTr("Airdrop community tokens")
@ -115,28 +81,35 @@ SettingsPageLayout {
Component { Component {
id: newAirdropView id: newAirdropView
EditAirdropView { SettingsPage {
id: view pageTitle: qsTr("New airdrop")
communityDetails: root.communityDetails contentItem: EditAirdropView {
assetsModel: root.assetsModel id: view
collectiblesModel: root.collectiblesModel
membersModel: root.membersModel
Binding on airdropFees { padding: 0
value: root.airdropFees
}
onAirdropClicked: { communityDetails: root.communityDetails
root.airdropClicked(airdropTokens, addresses, membersPubKeys) assetsModel: root.assetsModel
stackManager.clear(d.welcomeViewState, StackView.Immediate) collectiblesModel: root.collectiblesModel
} membersModel: root.membersModel
onNavigateToMintTokenSettings: root.navigateToMintTokenSettings(isAssetType)
Component.onCompleted: { Binding on airdropFees {
d.selectToken.connect(view.selectToken) value: root.airdropFees
d.addAddresses.connect(view.addAddresses) }
airdropFeesRequested.connect(root.airdropFeesRequested)
onAirdropClicked: {
root.airdropClicked(airdropTokens, addresses, membersPubKeys)
root.pop(StackView.Immediate)
}
onNavigateToMintTokenSettings: root.navigateToMintTokenSettings(isAssetType)
Component.onCompleted: {
d.selectToken.connect(view.selectToken)
d.addAddresses.connect(view.addAddresses)
airdropFeesRequested.connect(root.airdropFeesRequested)
}
} }
} }
} }

View File

@ -563,9 +563,6 @@ StatusSectionLayout {
target: mintPanel target: mintPanel
function onAirdropToken(tokenKey, type, addresses) { function onAirdropToken(tokenKey, type, addresses) {
// Here it is forced a navigation to the new airdrop form, like if it was clicked the header button
airdropPanel.primaryHeaderButtonClicked()
// Force a token selection to be airdroped with default amount 1 // Force a token selection to be airdroped with default amount 1
airdropPanel.selectToken(tokenKey, 1, type) airdropPanel.selectToken(tokenKey, 1, type)