Only run spinner while loading members

This commit is contained in:
Loren Burkholder 2021-07-19 14:49:57 -04:00
parent a7bdbc2af2
commit 21eb312f69
3 changed files with 11 additions and 1 deletions

View file

@ -116,7 +116,7 @@ ApplicationWindow {
}
footer: Spinner {
visible: members.numUsersLoaded < members.memberCount
visible: members.numUsersLoaded < members.memberCount && members.loadingMoreMembers
// use the default height if it's visible, otherwise no height at all
height: visible ? undefined : 0
anchors.centerIn: parent

View file

@ -98,8 +98,14 @@ MemberList::canFetchMore(const QModelIndex &) const
void
MemberList::fetchMore(const QModelIndex &)
{
loadingMoreMembers_ = true;
emit loadingMoreMembersChanged();
auto members = cache::getMembers(room_id_.toStdString(), rowCount());
addUsers(members);
numUsersLoaded_ += members.size();
emit numUsersLoadedChanged();
loadingMoreMembers_ = false;
emit loadingMoreMembersChanged();
}

View file

@ -16,6 +16,7 @@ class MemberList : public QAbstractListModel
Q_PROPERTY(QString avatarUrl READ avatarUrl NOTIFY avatarUrlChanged)
Q_PROPERTY(QString roomId READ roomId NOTIFY roomIdChanged)
Q_PROPERTY(int numUsersLoaded READ numUsersLoaded NOTIFY numUsersLoadedChanged)
Q_PROPERTY(bool loadingMoreMembers READ loadingMoreMembers NOTIFY loadingMoreMembersChanged)
public:
enum Roles
@ -39,6 +40,7 @@ public:
QString avatarUrl() const { return QString::fromStdString(info_.avatar_url); }
QString roomId() const { return room_id_; }
int numUsersLoaded() const { return numUsersLoaded_; }
bool loadingMoreMembers() const { return loadingMoreMembers_; }
signals:
void roomNameChanged();
@ -46,6 +48,7 @@ signals:
void avatarUrlChanged();
void roomIdChanged();
void numUsersLoadedChanged();
void loadingMoreMembersChanged();
public slots:
void addUsers(const std::vector<RoomMember> &users);
@ -59,4 +62,5 @@ private:
QString room_id_;
RoomInfo info_;
int numUsersLoaded_{0};
bool loadingMoreMembers_{false};
};