From 18d416011ac4537ceff88da0926ffb0b62f82278 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Fri, 18 Aug 2023 21:48:46 -0400 Subject: [PATCH] Make news page loading more obvious, and show if there's no news If there's no news available (e.g. the server is down, or no internet connection) make it look a little bit nicer. --- launcher/include/headline.h | 4 ++++ launcher/src/launchercore.cpp | 3 +++ launcher/ui/Pages/NewsPage.qml | 17 +++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/launcher/include/headline.h b/launcher/include/headline.h index 7464ef1..9af7ff1 100644 --- a/launcher/include/headline.h +++ b/launcher/include/headline.h @@ -45,6 +45,7 @@ class Headline : public QObject Q_PROPERTY(QList news MEMBER news CONSTANT) Q_PROPERTY(QList pinned MEMBER pinned CONSTANT) Q_PROPERTY(QList topics MEMBER topics CONSTANT) + Q_PROPERTY(bool failedToLoad MEMBER failedToLoad CONSTANT) public: explicit Headline(QObject *parent = nullptr) @@ -56,4 +57,7 @@ public: QList news; QList pinned; QList topics; + + // FIXME: wtf is this? + bool failedToLoad = false; }; \ No newline at end of file diff --git a/launcher/src/launchercore.cpp b/launcher/src/launchercore.cpp index a95dc28..b2fa9fd 100755 --- a/launcher/src/launchercore.cpp +++ b/launcher/src/launchercore.cpp @@ -540,6 +540,9 @@ void LauncherCore::refreshNews() auto document = QJsonDocument::fromJson(reply->readAll()); auto headline = new Headline(this); + if (document.isEmpty()) { + headline->failedToLoad = true; + } const auto parseNews = [](QJsonObject object) -> News { News news; diff --git a/launcher/ui/Pages/NewsPage.qml b/launcher/ui/Pages/NewsPage.qml index ffb8bab..b57b6b9 100644 --- a/launcher/ui/Pages/NewsPage.qml +++ b/launcher/ui/Pages/NewsPage.qml @@ -86,6 +86,7 @@ Controls.Control { Layout.alignment: Qt.AlignHCenter | Qt.AlignTop maximumWidth: layout.maximumWidth + visible: LauncherCore.headline !== null contentItem: ColumnLayout { spacing: 0 @@ -104,6 +105,11 @@ Controls.Control { onClicked: applicationWindow().openUrl(modelData.url) } } + + MobileForm.FormTextDelegate { + description: i18n("No news.") + visible: LauncherCore.headline !== null ? LauncherCore.headline.failedToLoad : false + } } } @@ -113,6 +119,7 @@ Controls.Control { Layout.alignment: Qt.AlignHCenter | Qt.AlignTop maximumWidth: layout.maximumWidth + visible: LauncherCore.headline !== null contentItem: ColumnLayout { spacing: 0 @@ -131,6 +138,11 @@ Controls.Control { onClicked: applicationWindow().openUrl(modelData.url) } } + + MobileForm.FormTextDelegate { + description: i18n("No topics.") + visible: LauncherCore.headline !== null ? LauncherCore.headline.failedToLoad : false + } } } @@ -138,4 +150,9 @@ Controls.Control { Layout.fillHeight: true } } + + Kirigami.LoadingPlaceholder { + anchors.centerIn: parent + visible: LauncherCore.headline === null + } } \ No newline at end of file