status-desktop/ui/app/AppLayouts/Chat/popups/community/CommunitiesPopup.qml

158 lines
5.1 KiB
QML
Raw Normal View History

2020-12-11 20:29:46 +00:00
import QtQuick 2.12
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
import StatusQ.Controls 0.1
import StatusQ.Components 0.1
import StatusQ.Popups 0.1
import utils 1.0
import shared 1.0
2020-12-11 20:29:46 +00:00
StatusModal {
2020-12-11 20:29:46 +00:00
id: popup
property var communitiesList
signal setActiveCommunity(string id)
signal setObservedCommunity(string id)
signal openCommunityDetail()
signal importCommunityClicked()
signal createCommunityClicked()
2020-12-11 20:29:46 +00:00
onOpened: {
contentItem.searchBox.input.text = "";
contentItem.searchBox.input.forceActiveFocus(Qt.MouseFocusReason)
2020-12-11 20:29:46 +00:00
}
header.title: qsTr("Communities")
headerActionButton: StatusFlatRoundButton {
type: StatusFlatRoundButton.Type.Secondary
width: 32
height: 32
icon.name: "more"
onClicked: contextMenu.popup(-contextMenu.width+width, height + 4)
StatusPopupMenu {
id: contextMenu
width: 230
StatusMenuItem {
icon.name: "download"
text: qsTr("Access existing community")
onTriggered: {
popup.importCommunityClicked();
}
}
2021-02-12 18:19:31 +00:00
}
}
2021-02-12 18:19:31 +00:00
contentItem: Item {
Column {
id: contentItem
anchors.horizontalCenter: parent.horizontalCenter
property alias searchBox: searchBox
Item {
height: 8
width: parent.width
}
2021-02-12 18:19:31 +00:00
StatusInput {
id: searchBox
anchors.horizontalCenter: parent.horizontalCenter
placeholderText: qsTr("Search for communities or topics")
input.asset.name: "search"
}
2020-12-11 20:29:46 +00:00
StatusModalDivider { topPadding: 8 }
2021-06-22 18:30:51 +00:00
StatusScrollView {
width: parent.width
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
topPadding: 8
bottomPadding: 8
height: 400
2020-12-11 20:29:46 +00:00
StatusListView {
anchors.fill: parent
model: communitiesDelegateModel
spacing: 4
id: communitiesList
section.property: "name"
section.criteria: ViewSection.FirstCharacter
section.delegate: Column {
StatusBaseText {
anchors.left: parent.left
anchors.leftMargin: 16
text: section.toUpperCase()
font.pixelSize: 15
font.weight: Font.Medium
color: Theme.palette.directColor1
}
StatusModalDivider {
bottomPadding: 8
}
}
}
DelegateModelGeneralized {
id: communitiesDelegateModel
lessThan: [
function(left, right) {
return left.name.toLowerCase() < right.name.toLowerCase()
}
]
model: popup.communitiesList
delegate: StatusListItem {
visible: {
if (!searchBox.input.text) {
return true
}
const lowerCaseSearchStr = searchBox.input.text.toLowerCase()
return model.name.toLowerCase().includes(lowerCaseSearchStr) || model.description.toLowerCase().includes(lowerCaseSearchStr)
}
height: visible ? implicitHeight : 0
anchors.horizontalCenter: parent.horizontalCenter
title: model.name
subTitle: model.description
tertiaryTitle: qsTr("%n member(s)", "", model.members.count)
statusListItemTitle.font.weight: Font.Bold
statusListItemTitle.font.pixelSize: 17
asset.name: model.image
asset.isImage: !!model.image
asset.isLetterIdenticon: !model.image
asset.bgColor: model.color || Theme.palette.primaryColor1
onClicked: {
if (model.joined && model.isMember) {
popup.setActiveCommunity(model.id);
} else {
popup.setObservedCommunity(model.id);
popup.openCommunityDetail();
}
popup.close()
2020-12-11 20:29:46 +00:00
}
}
}
}
}
}
2020-12-11 20:38:10 +00:00
rightButtons: [
StatusButton {
text: qsTr("Create a community")
onClicked: {
popup.createCommunityClicked();
popup.close()
}
2020-12-11 20:29:46 +00:00
}
]
2020-12-11 20:29:46 +00:00
}