2022-11-29 14:29:39 +00:00
import QtQuick 2.14
import QtQuick . Controls 2.14
2022-06-08 14:43:46 +00:00
import QtQuick . Layouts 1.14
2021-10-01 15:58:36 +00:00
2021-09-28 15:04:06 +00:00
import utils 1.0
2020-12-11 20:38:10 +00:00
2021-10-18 12:32:48 +00:00
import StatusQ . Core 0.1
import StatusQ . Core . Theme 0.1
import StatusQ . Controls 0.1
2022-09-13 07:56:47 +00:00
import StatusQ . Components 0.1
2021-10-18 12:32:48 +00:00
2021-10-27 21:27:49 +00:00
import shared . panels 1.0
import shared . popups 1.0
2021-10-18 12:32:48 +00:00
2022-11-29 14:29:39 +00:00
Control {
2020-12-11 20:38:10 +00:00
id: root
2023-10-26 08:33:30 +00:00
implicitWidth: d . invitedCommunity || d . loading ? 270 /*by design*/ : 0
2022-11-29 14:29:39 +00:00
padding: 1
2022-09-13 07:56:47 +00:00
2021-10-21 00:41:54 +00:00
property var store
2022-09-13 07:56:47 +00:00
property string communityId
QtObject {
id: d
property var invitedCommunity
2023-10-26 08:33:30 +00:00
readonly property string communityName: ! ! d . invitedCommunity ? d.invitedCommunity.name : ""
readonly property string communityDescription: ! ! d . invitedCommunity ? d.invitedCommunity.description : ""
2023-02-27 17:27:37 +00:00
readonly property string communityImage: ! ! d . invitedCommunity ? d.invitedCommunity.image : ""
2023-10-26 08:33:30 +00:00
readonly property string communityColor: ! ! d . invitedCommunity ? d.invitedCommunity.color : ""
readonly property int communityNbMembers: ! ! d . invitedCommunity ? d.invitedCommunity.nbMembers : 0
2023-02-27 17:27:37 +00:00
readonly property bool communityVerified: false //!!d.invitedCommunity ? d.invitedCommunity.verified : false TODO: add this to the community object if we should support verified communities
readonly property bool communityJoined: ! ! d . invitedCommunity ? d.invitedCommunity.joined : false
readonly property bool communitySpectated: ! ! d . invitedCommunity ? d.invitedCommunity.spectated : false
2022-09-13 07:56:47 +00:00
readonly property int margin: 12
2023-06-15 09:09:42 +00:00
readonly property int radius: Style . current . padding
2022-09-13 07:56:47 +00:00
2023-10-26 08:33:30 +00:00
readonly property bool loading: ! d . invitedCommunity
2022-09-13 07:56:47 +00:00
function getCommunity ( ) {
try {
const communityJson = root . store . getSectionByIdJson ( communityId )
2021-10-21 00:41:54 +00:00
2022-09-13 07:56:47 +00:00
if ( ! communityJson ) {
2023-11-08 19:59:45 +00:00
// we don't have the shard info, so we will try to fetch it on waku
root . store . requestCommunityInfo ( communityId , - 1 , - 1 )
2022-09-13 07:56:47 +00:00
return null
}
2022-06-20 11:39:40 +00:00
2022-09-13 07:56:47 +00:00
return JSON . parse ( communityJson ) ;
} catch ( e ) {
console . error ( "Error parsing community" , e )
2022-02-11 21:41:34 +00:00
}
2021-07-22 15:22:02 +00:00
2022-09-13 07:56:47 +00:00
return null
2022-02-11 21:41:34 +00:00
}
2021-07-22 15:22:02 +00:00
2022-09-13 07:56:47 +00:00
function reevaluate ( ) {
invitedCommunity = getCommunity ( )
}
fix(communities): re-joining of left communities
Fixes: #2649.
Upon receipt of status-go signals which included communities that have been left (`joined: false`), those communities were being rejoined automatically when they should not have been.
fix(communities): Invitation bubble button state updates
The community state inside of the invitation bubble was not reactive to any community actions (such as joining, leaving, updating). In addition, requesting to join a community changed the button’s text to “Pending”, but upon approval, the button’s state was not updating.
The component was setting an observed community in the Component.onCompleted event, which was occurring for all invitation bubbles, but because the community wasn’t bound correctly to the bubble, once a bubble with a different community was encountered, the community in context of the bubble wasn’t updated and instead used a local copy. Once the community was bound correctly (to be reactive), the states started working correctly.
The invitation bubble has been simplied so that it has states instead of using lots of if/else statements inside of the property bindings. This simplified the component’s logic for things like onClick action and made it a lot easier to read and modify.
2021-06-24 07:21:45 +00:00
}
2020-12-11 20:38:10 +00:00
Component.onCompleted: {
2022-09-13 07:56:47 +00:00
d . reevaluate ( )
fix(communities): re-joining of left communities
Fixes: #2649.
Upon receipt of status-go signals which included communities that have been left (`joined: false`), those communities were being rejoined automatically when they should not have been.
fix(communities): Invitation bubble button state updates
The community state inside of the invitation bubble was not reactive to any community actions (such as joining, leaving, updating). In addition, requesting to join a community changed the button’s text to “Pending”, but upon approval, the button’s state was not updating.
The component was setting an observed community in the Component.onCompleted event, which was occurring for all invitation bubbles, but because the community wasn’t bound correctly to the bubble, once a bubble with a different community was encountered, the community in context of the bubble wasn’t updated and instead used a local copy. Once the community was bound correctly (to be reactive), the states started working correctly.
The invitation bubble has been simplied so that it has states instead of using lots of if/else statements inside of the property bindings. This simplified the component’s logic for things like onClick action and made it a lot easier to read and modify.
2021-06-24 07:21:45 +00:00
}
2020-12-11 20:38:10 +00:00
2022-06-20 11:39:40 +00:00
Connections {
target: root . store . communitiesModuleInst
2022-11-22 18:01:07 +00:00
function onCommunityChanged ( communityId ) {
2022-06-20 11:39:40 +00:00
if ( communityId === root . communityId ) {
2022-09-13 07:56:47 +00:00
d . reevaluate ( )
2022-06-20 11:39:40 +00:00
}
}
2022-11-22 18:01:07 +00:00
function onCommunityAdded ( communityId ) {
2022-06-20 11:39:40 +00:00
if ( communityId === root . communityId ) {
2022-09-13 07:56:47 +00:00
d . reevaluate ( )
2022-06-20 11:39:40 +00:00
}
}
}
2020-12-11 20:38:10 +00:00
2022-11-29 14:29:39 +00:00
background: Rectangle {
radius: d . radius
color: Style . current . background
border.color: Style . current . border
border.width: 1
}
2022-09-13 07:56:47 +00:00
2022-11-29 14:29:39 +00:00
contentItem: ColumnLayout {
spacing: 0
2022-09-13 07:56:47 +00:00
2022-11-29 14:29:39 +00:00
StatusBaseText {
id: title
2022-09-13 07:56:47 +00:00
2022-11-29 14:29:39 +00:00
Layout.fillWidth: true
Layout.leftMargin: d . margin
Layout.rightMargin: d . margin
Layout.topMargin: 8
Layout.bottomMargin: 8
2022-09-13 07:56:47 +00:00
2023-02-27 17:27:37 +00:00
text: d . communityVerified ? qsTr ( "Verified community invitation" ) : qsTr ( "Community invitation" )
color: d . communityVerified ? Theme.palette.primaryColor1 : Theme . palette . baseColor1
2022-11-29 14:29:39 +00:00
font.weight: Font . Medium
font.pixelSize: 13
}
Rectangle {
Layout.fillWidth: true
Layout.preferredHeight: 1
color: Style . current . separator
}
RowLayout {
id: communityDescriptionLayout
Layout.leftMargin: d . margin
Layout.rightMargin: d . margin
Layout.topMargin: 12
Layout.bottomMargin: 12
spacing: 12
StatusSmartIdenticon {
Layout.alignment: Qt . AlignTop
Layout.preferredWidth: 40
Layout.preferredHeight: 40
2023-02-27 17:27:37 +00:00
name: d . communityName
2022-11-29 14:29:39 +00:00
asset {
width: 40
height: 40
2023-02-27 17:27:37 +00:00
name: d . communityImage
color: d . communityColor
2022-11-29 14:29:39 +00:00
isImage: true
2022-09-13 07:56:47 +00:00
}
2023-05-24 12:06:43 +00:00
2023-07-27 11:21:25 +00:00
visible: d . communityColor && d . communityName
2022-11-29 14:29:39 +00:00
}
2020-12-11 20:38:10 +00:00
2022-11-29 14:29:39 +00:00
ColumnLayout {
spacing: 2
StatusBaseText {
2022-09-13 07:56:47 +00:00
Layout.fillWidth: true
2023-09-12 08:55:40 +00:00
objectName: "communityName"
2023-07-27 11:21:25 +00:00
text: d . communityName
2022-11-29 14:29:39 +00:00
font.weight: Font . Bold
wrapMode: Text . WrapAtWordBoundaryOrAnywhere
font.pixelSize: 17
color: Theme . palette . directColor1
2022-09-13 07:56:47 +00:00
}
2020-12-11 20:38:10 +00:00
2022-11-29 14:29:39 +00:00
StatusBaseText {
Layout.fillWidth: true
2023-09-12 08:55:40 +00:00
objectName: "communityDescription"
2023-07-27 11:21:25 +00:00
text: d . communityDescription
2022-11-29 14:29:39 +00:00
wrapMode: Text . WrapAtWordBoundaryOrAnywhere
color: Theme . palette . directColor1
2022-09-13 07:56:47 +00:00
}
2022-06-08 14:43:46 +00:00
2022-11-29 14:29:39 +00:00
StatusBaseText {
2022-09-13 07:56:47 +00:00
Layout.fillWidth: true
2023-09-12 08:55:40 +00:00
objectName: "communityMembers"
2023-07-27 11:21:25 +00:00
text: qsTr ( "%n member(s)" , "" , d . communityNbMembers )
2022-11-29 14:29:39 +00:00
font.pixelSize: 13
font.weight: Font . Medium
color: Theme . palette . baseColor1
2022-09-13 07:56:47 +00:00
}
2022-11-29 14:29:39 +00:00
}
}
2022-09-13 07:56:47 +00:00
2022-11-29 14:29:39 +00:00
Rectangle {
Layout.fillWidth: true
Layout.preferredHeight: 1
color: Style . current . separator
}
2022-09-22 07:13:03 +00:00
2023-06-15 09:09:42 +00:00
Item {
2022-11-29 14:29:39 +00:00
Layout.fillWidth: true
Layout.preferredHeight: 44
2023-06-15 09:09:42 +00:00
clip: true
StatusFlatButton {
id: joinBtn
width: parent . width
height: ( parent . height + d . radius )
anchors.top: parent . top
anchors.topMargin: - d . radius
2023-10-26 08:33:30 +00:00
loading: d . loading
2023-06-15 09:09:42 +00:00
radius: d . radius - 1 // We do -1, otherwise there's a gap between border and button
contentItem: Item {
StatusBaseText {
anchors.centerIn: parent
anchors.verticalCenterOffset: d . radius / 2
2023-07-27 11:21:25 +00:00
visible: ! joinBtn . loading
2023-06-15 09:09:42 +00:00
font: joinBtn . font
color: joinBtn . enabled ? joinBtn.textColor : joinBtn . disabledTextColor
text: qsTr ( "Go to Community" )
}
}
2022-11-29 14:29:39 +00:00
2023-06-15 09:09:42 +00:00
onClicked: {
if ( d . communityJoined || d . communitySpectated ) {
root . store . setActiveCommunity ( communityId )
} else {
root . store . spectateCommunity ( communityId , userProfile . name )
}
2020-12-11 20:38:10 +00:00
}
}
}
}
}