2023-02-01 17:26:59 +00:00
import QtQuick 2.14
import QtQuick . Controls 2.14
import QtQuick . Layouts 1.14
2024-03-27 12:36:00 +00:00
import StatusQ 0.1
2023-02-01 17:26:59 +00:00
import StatusQ . Core 0.1
import StatusQ . Core . Theme 0.1
import StatusQ . Components 0.1
import StatusQ . Controls 0.1
2023-06-23 06:17:04 +00:00
import AppLayouts . Communities . helpers 1.0
import AppLayouts . Communities . controls 1.0
2023-02-01 17:26:59 +00:00
import SortFilterProxyModel 0.2
2023-03-30 09:42:28 +00:00
import utils 1.0
2023-02-01 17:26:59 +00:00
Control {
id: root
property bool joinCommunity: true // Otherwise it means join channel action
2024-03-27 12:36:00 +00:00
property bool allChannelsAreHiddenBecauseNotPermitted: false
2023-02-01 17:26:59 +00:00
property bool requirementsMet: false
2023-08-04 13:14:06 +00:00
property bool requirementsCheckPending: false
2023-02-01 17:26:59 +00:00
property bool requiresRequest: false
property bool isInvitationPending: false
property bool isJoinRequestRejected: false
property string communityName
2023-02-14 16:33:23 +00:00
property var communityHoldingsModel
2023-02-01 17:26:59 +00:00
property string channelName
2023-02-14 16:33:23 +00:00
property var viewOnlyHoldingsModel
property var viewAndPostHoldingsModel
property var moderateHoldingsModel
property bool showOnlyPanels: false
2023-02-01 17:26:59 +00:00
2023-02-13 10:40:13 +00:00
property var assetsModel
property var collectiblesModel
2024-03-27 07:37:28 +00:00
signal requestToJoinClicked
2023-02-01 17:26:59 +00:00
signal invitationPendingClicked
QtObject {
id: d
readonly property string communityRequirementsNotMetText: qsTr ( "Membership requirements not met" )
2024-03-27 07:37:28 +00:00
readonly property string communityRequestToJoinText: qsTr ( "Request to join Community" )
2023-02-01 17:26:59 +00:00
readonly property string communityMembershipRequestPendingText: qsTr ( "Membership Request Pending..." )
readonly property string channelRequirementsNotMetText: qsTr ( "Channel requirements not met" )
readonly property string channelMembershipRequestPendingText: qsTr ( "Channel Membership Request Pending..." )
readonly property string memberchipRequestRejectedText: qsTr ( "Membership Request Rejected" )
2024-03-27 12:36:00 +00:00
readonly property string allChannelsAreHiddenBecauseNotPermittedText: qsTr ( "Sorry, you don't hodl the necessary tokens to view or post in any of <b>%1</b> channels" ) . arg ( root . communityName )
2023-02-01 17:26:59 +00:00
2024-03-27 12:36:00 +00:00
readonly property bool onlyPrivateNotMetPermissions: ( d . visiblePermissionsModel . count === 0 ) && root . communityHoldingsModel . count > 0
2023-06-08 11:01:01 +00:00
2024-03-27 12:36:00 +00:00
readonly property var visiblePermissionsModel: SortFilterProxyModel {
2023-06-08 11:01:01 +00:00
sourceModel: root . communityHoldingsModel
2024-03-27 12:36:00 +00:00
2023-06-08 11:01:01 +00:00
filters: [
2024-03-27 12:36:00 +00:00
// The only permissions to be discarded are if they are private and NOT met
FastExpressionFilter {
2024-03-28 12:37:25 +00:00
expression: d . filterPermissions ( model )
2024-03-27 12:36:00 +00:00
expectedRoles: [ "tokenCriteriaMet" , "isPrivate" ]
2023-06-08 11:01:01 +00:00
}
]
}
readonly property var viewOnlyPermissionsModel: SortFilterProxyModel {
sourceModel: root . viewOnlyHoldingsModel
filters: [
ExpressionFilter {
expression: d . filterPermissions ( model )
}
]
}
readonly property var viewAndPostPermissionsModel: SortFilterProxyModel {
sourceModel: root . viewAndPostHoldingsModel
filters: [
ExpressionFilter {
expression: d . filterPermissions ( model )
}
]
}
2023-07-04 15:11:41 +00:00
readonly property var moderatePermissionsModel: SortFilterProxyModel {
sourceModel: root . moderateHoldingsModel
filters: [
ExpressionFilter {
expression: d . filterPermissions ( model )
}
]
}
2024-03-28 12:37:25 +00:00
function filterPermissions ( model ) {
return ! ! model && ( model . tokenCriteriaMet || ! model . isPrivate )
}
2023-02-01 17:26:59 +00:00
}
padding: 35 // default by design
spacing: 32 // default by design
2023-07-04 15:11:41 +00:00
2023-02-01 17:26:59 +00:00
contentItem: ColumnLayout {
id: column
2023-02-13 10:40:13 +00:00
2023-02-01 17:26:59 +00:00
spacing: root . spacing
2023-02-13 10:40:13 +00:00
component CustomHoldingsListPanel: HoldingsListPanel {
2023-02-01 17:26:59 +00:00
Layout.fillWidth: true
2023-02-13 10:40:13 +00:00
assetsModel: root . assetsModel
collectiblesModel: root . collectiblesModel
2023-02-01 17:26:59 +00:00
spacing: root . spacing
2023-02-13 10:40:13 +00:00
}
CustomHoldingsListPanel {
2023-06-08 11:01:01 +00:00
id: communityRequirements
visible: root . joinCommunity
2024-03-27 12:36:00 +00:00
introText: ! d . onlyPrivateNotMetPermissions ?
2023-06-08 11:01:01 +00:00
qsTr ( "To join <b>%1</b> you need to prove that you hold" ) . arg ( root . communityName ) :
qsTr ( "Sorry, you can't join <b>%1</b> because it's a private, closed community" ) . arg ( root . communityName )
2024-03-27 12:36:00 +00:00
model: d . visiblePermissionsModel
2023-02-01 17:26:59 +00:00
}
2024-03-28 12:37:25 +00:00
StatusBaseText {
Layout.fillWidth: true
visible: root . allChannelsAreHiddenBecauseNotPermitted
horizontalAlignment: Text . AlignHCenter
wrapMode: Text . WordWrap
text: d . allChannelsAreHiddenBecauseNotPermittedText
textFormat: Text . StyledText
}
2023-02-13 10:40:13 +00:00
CustomHoldingsListPanel {
2024-03-28 12:37:25 +00:00
visible: ( ! root . joinCommunity && d . viewOnlyPermissionsModel . count > 0 ) && ! root . allChannelsAreHiddenBecauseNotPermitted
2023-06-08 11:01:01 +00:00
introText: root . requiresRequest ?
2023-07-04 15:11:41 +00:00
qsTr ( "To view the <b>#%1</b> channel you need to join <b>%2</b> and prove that you hold" ) . arg ( root . channelName ) . arg ( root . communityName ) :
qsTr ( "To view the <b>#%1</b> channel you need to hold" ) . arg ( root . channelName )
2023-06-08 11:01:01 +00:00
model: d . viewOnlyPermissionsModel
2023-02-01 17:26:59 +00:00
}
2023-02-13 10:40:13 +00:00
CustomHoldingsListPanel {
2024-03-28 12:37:25 +00:00
visible: ( ! root . joinCommunity && d . viewAndPostPermissionsModel . count > 0 ) && ! root . allChannelsAreHiddenBecauseNotPermitted
introText: root . requiresRequest ? qsTr ( "To view and post in the <b>#%1</b> channel you need to join <b>%2</b> and prove that you hold" ) . arg ( root . channelName ) . arg ( root . communityName ) :
qsTr ( "To view and post in the <b>#%1</b> channel you need to hold" ) . arg ( root . channelName )
2023-06-08 11:01:01 +00:00
model: d . viewAndPostPermissionsModel
2023-02-01 17:26:59 +00:00
}
2023-07-04 15:11:41 +00:00
CustomHoldingsListPanel {
visible: ! root . joinCommunity && d . moderatePermissionsModel . count > 0
introText: qsTr ( "To moderate in the <b>#%1</b> channel you need to hold" ) . arg ( root . channelName )
model: d . moderatePermissionsModel
2023-02-01 17:26:59 +00:00
}
StatusButton {
Layout.alignment: Qt . AlignHCenter
2024-03-27 12:36:00 +00:00
visible: ! root . showOnlyPanels
&& ! root . isJoinRequestRejected
&& root . requiresRequest
&& ! d . onlyPrivateNotMetPermissions
&& ! root . allChannelsAreHiddenBecauseNotPermitted
text: root . isInvitationPending ? ( root . joinCommunity ? d.communityMembershipRequestPendingText : d . channelMembershipRequestPendingText )
: d . communityRequestToJoinText
font.pixelSize: 13
enabled: root . requirementsMet || ( root . joinCommunity && d . visiblePermissionsModel . count === 0 )
onClicked: root . isInvitationPending ? root . invitationPendingClicked ( ) : root . requestToJoinClicked ( )
2023-02-01 17:26:59 +00:00
}
StatusBaseText {
Layout.alignment: Qt . AlignHCenter
2024-03-27 12:36:00 +00:00
visible: ! root . showOnlyPanels
&& ! root . requirementsCheckPending
&& ( root . isJoinRequestRejected || ! root . requirementsMet )
&& ! d . onlyPrivateNotMetPermissions
&& ! root . allChannelsAreHiddenBecauseNotPermitted
2023-02-01 17:26:59 +00:00
text: root . isJoinRequestRejected ? d.memberchipRequestRejectedText :
( root . joinCommunity ? d.communityRequirementsNotMetText : d . channelRequirementsNotMetText )
color: Theme . palette . dangerColor1
}
2023-08-04 13:14:06 +00:00
2023-08-22 18:04:58 +00:00
RequirementsCheckPendingLoader {
2023-08-04 13:14:06 +00:00
visible: root . requirementsCheckPending
2023-08-22 18:04:58 +00:00
Layout.alignment: Qt . AlignHCenter
2023-08-04 13:14:06 +00:00
}
2023-02-01 17:26:59 +00:00
}
}