mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 03:00:46 +03:00
Add a fancy loading spinner to the member list
This commit is contained in:
parent
e1acf5d324
commit
a76fc7d200
3 changed files with 23 additions and 3 deletions
|
@ -109,6 +109,13 @@ ApplicationWindow {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
footer: BusyIndicator {
|
||||
// This is not a wonderful solution, but it is the best way to calculate whether
|
||||
// all users are loaded while keeping canFetchMore() const
|
||||
running: members.numUsersLoaded < members.memberCount
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,10 @@ MemberList::MemberList(const QString &room_id, QWidget *parent)
|
|||
}
|
||||
|
||||
try {
|
||||
addUsers(cache::getMembers(room_id_.toStdString()));
|
||||
auto members = cache::getMembers(room_id_.toStdString());
|
||||
addUsers(members);
|
||||
numUsersLoaded_ = members.size();
|
||||
emit numUsersLoadedChanged();
|
||||
} catch (const lmdb::error &e) {
|
||||
nhlog::db()->critical("Failed to retrieve members from cache: {}", e.what());
|
||||
}
|
||||
|
@ -83,11 +86,17 @@ bool
|
|||
MemberList::canFetchMore(const QModelIndex &) const
|
||||
{
|
||||
const size_t numMembers = rowCount();
|
||||
return (numMembers > 1 && numMembers < info_.member_count);
|
||||
if (numMembers > 1 && numMembers < info_.member_count)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
MemberList::fetchMore(const QModelIndex &)
|
||||
{
|
||||
addUsers(cache::getMembers(room_id_.toStdString(), rowCount()));
|
||||
auto members = cache::getMembers(room_id_.toStdString(), rowCount());
|
||||
addUsers(members);
|
||||
numUsersLoaded_ = members.size();
|
||||
emit numUsersLoadedChanged();
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ class MemberList : public QAbstractListModel
|
|||
Q_PROPERTY(size_t memberCount READ memberCount NOTIFY memberCountChanged)
|
||||
Q_PROPERTY(QString avatarUrl READ avatarUrl NOTIFY avatarUrlChanged)
|
||||
Q_PROPERTY(QString roomId READ roomId NOTIFY roomIdChanged)
|
||||
Q_PROPERTY(int numUsersLoaded READ numUsersLoaded NOTIFY numUsersLoadedChanged)
|
||||
|
||||
public:
|
||||
enum Roles
|
||||
|
@ -37,12 +38,14 @@ public:
|
|||
size_t memberCount() const { return info_.member_count; }
|
||||
QString avatarUrl() const { return QString::fromStdString(info_.avatar_url); }
|
||||
QString roomId() const { return room_id_; }
|
||||
int numUsersLoaded() const { return numUsersLoaded_; }
|
||||
|
||||
signals:
|
||||
void roomNameChanged();
|
||||
void memberCountChanged();
|
||||
void avatarUrlChanged();
|
||||
void roomIdChanged();
|
||||
void numUsersLoadedChanged();
|
||||
|
||||
public slots:
|
||||
void addUsers(const std::vector<RoomMember> &users);
|
||||
|
@ -55,4 +58,5 @@ private:
|
|||
QVector<QPair<RoomMember, QString>> m_memberList;
|
||||
QString room_id_;
|
||||
RoomInfo info_;
|
||||
int numUsersLoaded_;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue