FEATURE: Add a CSS class to the HTML element on background connection error (#10991)

This is a way to detect that Discourse isn't able to receive online updates from
the server, and will be used to trigger an UI warning to the user that the session
is working on offline mode.

Meta request https://meta.discourse.org/t/offline-indicator/123000?u=falco
This commit is contained in:
Rafael dos Santos Silva 2020-10-29 21:59:02 -03:00 committed by GitHub
parent 8b24e0f0b7
commit ec35b353a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -5,6 +5,15 @@ import { handleLogoff } from "discourse/lib/ajax";
import { isProduction, isTesting } from "discourse-common/config/environment";
const LONG_POLL_AFTER_UNSEEN_TIME = 1200000; // 20 minutes
const CONNECTIVITY_ERROR_CLASS = "message-bus-offline";
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) {
@ -12,6 +21,7 @@ function ajax(opts) {
opts.complete = function (xhr, stat) {
handleLogoff(xhr);
oldComplete(xhr, stat);
updateConnectivityIndicator(stat);
};
} else {
opts.complete = handleLogoff;