Only invite if there is something/someone to invite

This commit is contained in:
Loren Burkholder 2021-07-19 12:31:20 -04:00
parent 74d493ff16
commit 4384554587
3 changed files with 9 additions and 77 deletions

View file

@ -18,13 +18,11 @@ ApplicationWindow {
if (inviteeEntry.text.match("@.+?:.{3,}")) { if (inviteeEntry.text.match("@.+?:.{3,}")) {
invitees.addUser(inviteeEntry.text); invitees.addUser(inviteeEntry.text);
inviteeEntry.clear(); inviteeEntry.clear();
} else {
warningLabel.show();
} }
} }
function cleanUpAndClose() { function cleanUpAndClose() {
if (inviteeEntry.text !== "") if (inviteeEntry.text.match("@.+?:.{3,}"))
addInvite(); addInvite();
invitees.accept(); invitees.accept();
close(); close();
@ -79,80 +77,8 @@ ApplicationWindow {
Button { Button {
text: qsTr("Add") text: qsTr("Add")
onClicked: { enabled: inviteeEntry.text.match("@.+?:.{3,}")
if (inviteeEntry.text !== "") { onClicked: addInvite()
addInvite();
}
}
}
}
Label {
id: warningLabel
function show() {
state = "shown";
warningLabelTimer.start();
}
text: qsTr("Please enter a valid username (e.g. @joe:matrix.org).")
color: "red"
visible: false
opacity: 0
state: "hidden"
states: [
State {
name: "shown"
PropertyChanges {
target: warningLabel
opacity: 1
visible: true
}
},
State {
name: "hidden"
PropertyChanges {
target: warningLabel
opacity: 0
visible: false
}
}
]
transitions: [
Transition {
from: "shown"
to: "hidden"
reversible: true
SequentialAnimation {
NumberAnimation {
target: warningLabel
property: "opacity"
duration: 500
}
PropertyAction {
target: warningLabel
property: "visible"
}
}
}
]
Timer {
id: warningLabelTimer
interval: 2000
repeat: false
running: false
onTriggered: warningLabel.state = "hidden"
} }
} }
@ -210,6 +136,7 @@ ApplicationWindow {
Button { Button {
text: qsTr("Invite") text: qsTr("Invite")
DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
enabled: invitees.count > 0
onClicked: cleanUpAndClose() onClicked: cleanUpAndClose()
} }

View file

@ -22,6 +22,8 @@ InviteesModel::addUser(QString mxid)
connect(invitee, &Invitee::userInfoLoaded, this, [this]() { endInsertRows(); }); connect(invitee, &Invitee::userInfoLoaded, this, [this]() { endInsertRows(); });
invitees_.push_back(invitee); invitees_.push_back(invitee);
emit countChanged();
} }
QHash<int, QByteArray> QHash<int, QByteArray>

View file

@ -30,6 +30,8 @@ class InviteesModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
public: public:
enum Roles enum Roles
{ {
@ -52,6 +54,7 @@ public:
signals: signals:
void accept(); void accept();
void countChanged();
private: private:
QVector<Invitee *> invitees_; QVector<Invitee *> invitees_;