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
2022-11-29 14:29:39 +00:00
implicitWidth: 270 // by design
implicitHeight: ! d . invitedCommunity ? 0 : Math . max ( implicitBackgroundHeight + topInset + bottomInset ,
implicitContentHeight + verticalPadding )
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-02-27 17:27:37 +00:00
readonly property string communityName: ! ! d . invitedCommunity ? d.invitedCommunity.name : ""
readonly property string communityDescription: ! ! d . invitedCommunity ? d.invitedCommunity.description : ""
readonly property string communityImage: ! ! d . invitedCommunity ? d.invitedCommunity.image : ""
readonly property string communityColor: ! ! d . invitedCommunity ? d.invitedCommunity.color : ""
readonly property int communityNbMembers: ! ! d . invitedCommunity ? d.invitedCommunity.nbMembers : 0
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
2022-10-07 12:15:08 +00:00
readonly property int radius: 16
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 ) {
root . store . requestCommunityInfo ( communityId )
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
}
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
2022-11-29 14:29:39 +00:00
2023-02-27 17:27:37 +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-02-27 17:27:37 +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
2022-11-29 14:29:39 +00:00
2023-02-27 17:27:37 +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
2022-11-29 14:29:39 +00:00
StatusFlatButton {
id: joinBtn
Layout.fillWidth: true
Layout.preferredHeight: 44
text: qsTr ( "Go to Community" )
radius: d . radius - 1 // We do -1, otherwise there's a gap between border and button
onClicked: {
2023-02-27 17:27:37 +00:00
if ( d . communityJoined || d . communitySpectated ) {
2022-11-29 14:29:39 +00:00
root . store . setActiveCommunity ( communityId )
} else {
root . store . spectateCommunity ( communityId , userProfile . name )
2020-12-11 20:38:10 +00:00
}
}
}
}
}