From 36d388b57f2fe0e4d67617de6336b4f057f08114 Mon Sep 17 00:00:00 2001 From: Mark VanLandingham Date: Fri, 28 Apr 2023 06:59:10 -0500 Subject: [PATCH] Revert "FEATURE: Reimplement offline indicator (#21285)" (#21296) This reverts commit de1066abcd8021ee60939bafff60b6285491cfcf. --- .../app/components/offline-indicator.hbs | 10 ------- .../app/components/offline-indicator.js | 16 ----------- .../discourse/app/initializers/message-bus.js | 22 +++++++++------ .../app/services/message-bus-connectivity.js | 16 ----------- .../discourse/app/templates/application.hbs | 1 - .../stylesheets/common/components/_index.scss | 1 - .../common/components/offline-indicator.scss | 10 ------- config/locales/client.en.yml | 4 --- spec/system/network_disconnected_spec.rb | 27 ------------------- 9 files changed, 14 insertions(+), 93 deletions(-) delete mode 100644 app/assets/javascripts/discourse/app/components/offline-indicator.hbs delete mode 100644 app/assets/javascripts/discourse/app/components/offline-indicator.js delete mode 100644 app/assets/javascripts/discourse/app/services/message-bus-connectivity.js delete mode 100644 app/assets/stylesheets/common/components/offline-indicator.scss delete mode 100644 spec/system/network_disconnected_spec.rb diff --git a/app/assets/javascripts/discourse/app/components/offline-indicator.hbs b/app/assets/javascripts/discourse/app/components/offline-indicator.hbs deleted file mode 100644 index ee53efd7aeb..00000000000 --- a/app/assets/javascripts/discourse/app/components/offline-indicator.hbs +++ /dev/null @@ -1,10 +0,0 @@ -{{#if this.showing}} -
- {{i18n "offline_indicator.no_internet"}} - -
-{{/if}} \ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/components/offline-indicator.js b/app/assets/javascripts/discourse/app/components/offline-indicator.js deleted file mode 100644 index 3a6edebe7a3..00000000000 --- a/app/assets/javascripts/discourse/app/components/offline-indicator.js +++ /dev/null @@ -1,16 +0,0 @@ -import Component from "@glimmer/component"; -import { action } from "@ember/object"; -import { inject as service } from "@ember/service"; - -export default class OfflineIndicator extends Component { - @service messageBusConnectivity; - - get showing() { - return !this.messageBusConnectivity.connected; - } - - @action - refresh() { - window.location.reload(true); - } -} diff --git a/app/assets/javascripts/discourse/app/initializers/message-bus.js b/app/assets/javascripts/discourse/app/initializers/message-bus.js index c83d409cb9f..8eb790749df 100644 --- a/app/assets/javascripts/discourse/app/initializers/message-bus.js +++ b/app/assets/javascripts/discourse/app/initializers/message-bus.js @@ -5,14 +5,23 @@ import { handleLogoff } from "discourse/lib/ajax"; import userPresent, { onPresenceChange } from "discourse/lib/user-presence"; const LONG_POLL_AFTER_UNSEEN_TIME = 1200000; // 20 minutes +const CONNECTIVITY_ERROR_CLASS = "message-bus-offline"; -function ajax(opts, messageBusConnectivity) { +function updateConnectivityIndicator(stat) { + if (stat === "error") { + document.documentElement.classList.add(CONNECTIVITY_ERROR_CLASS); + } else { + document.documentElement.classList.remove(CONNECTIVITY_ERROR_CLASS); + } +} + +function ajax(opts) { if (opts.complete) { const oldComplete = opts.complete; opts.complete = function (xhr, stat) { handleLogoff(xhr); oldComplete(xhr, stat); - messageBusConnectivity.setConnectivity(xhr.readyState === 4); + updateConnectivityIndicator(stat); }; } else { opts.complete = handleLogoff; @@ -33,10 +42,7 @@ export default { const messageBus = container.lookup("service:message-bus"), user = container.lookup("service:current-user"), - siteSettings = container.lookup("service:site-settings"), - messageBusConnectivity = container.lookup( - "service:message-bus-connectivity" - ); + siteSettings = container.lookup("service:site-settings"); messageBus.alwaysLongPoll = !isProduction(); messageBus.shouldLongPollCallback = () => @@ -91,7 +97,7 @@ export default { if (userPresent()) { opts.headers["Discourse-Present"] = "true"; } - return ajax(opts, messageBusConnectivity); + return ajax(opts); }; } else { messageBus.ajax = function (opts) { @@ -99,7 +105,7 @@ export default { if (userPresent()) { opts.headers["Discourse-Present"] = "true"; } - return ajax(opts, messageBusConnectivity); + return ajax(opts); }; messageBus.baseUrl = getURL("/"); diff --git a/app/assets/javascripts/discourse/app/services/message-bus-connectivity.js b/app/assets/javascripts/discourse/app/services/message-bus-connectivity.js deleted file mode 100644 index 876ecb34e99..00000000000 --- a/app/assets/javascripts/discourse/app/services/message-bus-connectivity.js +++ /dev/null @@ -1,16 +0,0 @@ -import Service from "@ember/service"; -import { tracked } from "@glimmer/tracking"; - -const CONNECTIVITY_ERROR_CLASS = "message-bus-offline"; - -export default class MessageBusConnectivity extends Service { - @tracked connected = true; - - setConnectivity(connected) { - this.connected = connected; - document.documentElement.classList.toggle( - CONNECTIVITY_ERROR_CLASS, - !connected - ); - } -} diff --git a/app/assets/javascripts/discourse/app/templates/application.hbs b/app/assets/javascripts/discourse/app/templates/application.hbs index 623f253f224..2c6d11c0e4a 100644 --- a/app/assets/javascripts/discourse/app/templates/application.hbs +++ b/app/assets/javascripts/discourse/app/templates/application.hbs @@ -24,7 +24,6 @@ {{/if}} -