From 0a1c48940195a226ffed7364abfc1916c31b19cc Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 17 Aug 2023 17:37:24 -0400 Subject: [PATCH] Make the explore page search loading process more obvious Adds progress bars, lots of them! Now it's easier to tell if NeoChat is trying it's best to load the public room list. --- src/models/publicroomlistmodel.cpp | 11 +++++++++++ src/models/publicroomlistmodel.h | 9 +++++++++ src/qml/Page/JoinRoomPage.qml | 22 +++++++++++++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/models/publicroomlistmodel.cpp b/src/models/publicroomlistmodel.cpp index 23953adfa..697f16244 100644 --- a/src/models/publicroomlistmodel.cpp +++ b/src/models/publicroomlistmodel.cpp @@ -41,6 +41,7 @@ void PublicRoomListModel::setConnection(Connection *conn) if (job) { job->abandon(); job = nullptr; + Q_EMIT loadingChanged(); } if (m_connection) { @@ -70,12 +71,14 @@ void PublicRoomListModel::setServer(const QString &value) nextBatch = ""; attempted = false; rooms.clear(); + Q_EMIT loadingChanged(); endResetModel(); if (job) { job->abandon(); job = nullptr; + Q_EMIT loadingChanged(); } if (m_connection) { @@ -110,6 +113,7 @@ void PublicRoomListModel::setKeyword(const QString &value) if (job) { job->abandon(); job = nullptr; + Q_EMIT loadingChanged(); } if (m_connection) { @@ -133,6 +137,7 @@ void PublicRoomListModel::next(int count) } job = m_connection->callApi(m_server, count, nextBatch, QueryPublicRoomsJob::Filter{m_keyword, {}}); + Q_EMIT loadingChanged(); connect(job, &BaseJob::finished, this, [this] { attempted = true; @@ -150,6 +155,7 @@ void PublicRoomListModel::next(int count) } this->job = nullptr; + Q_EMIT loadingChanged(); }); } @@ -253,4 +259,9 @@ bool PublicRoomListModel::hasMore() const return !(attempted && nextBatch.isEmpty()); } +bool PublicRoomListModel::loading() const +{ + return (job != nullptr) || isJobPending(job); +} + #include "moc_publicroomlistmodel.cpp" diff --git a/src/models/publicroomlistmodel.h b/src/models/publicroomlistmodel.h index 989f7be3c..7e412d48f 100644 --- a/src/models/publicroomlistmodel.h +++ b/src/models/publicroomlistmodel.h @@ -48,6 +48,11 @@ class PublicRoomListModel : public QAbstractListModel */ Q_PROPERTY(bool hasMore READ hasMore NOTIFY hasMoreChanged) + /** + * @biref Whether the model is still loading. + */ + Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged) + public: /** * @brief Defines the model roles. @@ -98,6 +103,8 @@ public: [[nodiscard]] bool hasMore() const; + [[nodiscard]] bool loading() const; + /** * @brief Load the next set of rooms. * @@ -111,6 +118,7 @@ private: QString m_keyword; bool attempted = false; + bool m_loading = false; QString nextBatch; QVector rooms; @@ -122,4 +130,5 @@ Q_SIGNALS: void serverChanged(); void keywordChanged(); void hasMoreChanged(); + void loadingChanged(); }; diff --git a/src/qml/Page/JoinRoomPage.qml b/src/qml/Page/JoinRoomPage.qml index 1e7574f01..f3a9a1075 100644 --- a/src/qml/Page/JoinRoomPage.qml +++ b/src/qml/Page/JoinRoomPage.qml @@ -7,7 +7,7 @@ import QtQuick.Controls 2.15 as QQC2 import QtQuick.Layouts 1.15 import Qt.labs.qmlmodels 1.0 -import org.kde.kirigami 2.15 as Kirigami +import org.kde.kirigami 2.19 as Kirigami import org.kde.kirigamiaddons.labs.components 1.0 as KirigamiComponents import org.kde.neochat 1.0 @@ -255,5 +255,25 @@ Kirigami.ScrollablePage { } } } + + footer: RowLayout { + width: parent.width + + QQC2.ProgressBar { + visible: publicRoomsListView.model.loading && publicRoomsListView.count !== 0 + indeterminate: true + padding: Kirigami.Units.largeSpacing * 2 + Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter + Layout.topMargin: Kirigami.Units.largeSpacing + Layout.bottomMargin: Kirigami.Units.largeSpacing + Layout.leftMargin: Kirigami.Units.largeSpacing + Layout.rightMargin: Kirigami.Units.largeSpacing + } + } + + Kirigami.LoadingPlaceholder { + anchors.centerIn: parent + visible: publicRoomsListView.model.loading && publicRoomsListView.count === 0 + } } }