Merge pull request #1757 from thelounge/xpaw/detached-sign-in
Do not keep sign-in and loader references in memory
This commit is contained in:
commit
c9da29f2fc
@ -6,8 +6,6 @@ const storage = require("../localStorage");
|
||||
const utils = require("../utils");
|
||||
const templates = require("../../views");
|
||||
|
||||
const login = $("#sign-in").html(templates.windows.sign_in());
|
||||
|
||||
socket.on("auth", function(data) {
|
||||
// If we reconnected and serverHash differs, that means the server restarted
|
||||
// And we will reload the page to grab the latest version
|
||||
@ -18,30 +16,36 @@ socket.on("auth", function(data) {
|
||||
return;
|
||||
}
|
||||
|
||||
utils.serverHash = data.serverHash;
|
||||
const login = $("#sign-in");
|
||||
|
||||
if (data.serverHash > -1) {
|
||||
utils.serverHash = data.serverHash;
|
||||
|
||||
login.html(templates.windows.sign_in());
|
||||
|
||||
login.find("form").on("submit", function() {
|
||||
const form = $(this);
|
||||
|
||||
form.find(".btn").attr("disabled", true);
|
||||
|
||||
const values = {};
|
||||
$.each(form.serializeArray(), function(i, obj) {
|
||||
values[obj.name] = obj.value;
|
||||
});
|
||||
|
||||
storage.set("user", values.user);
|
||||
|
||||
socket.emit("auth", values);
|
||||
|
||||
return false;
|
||||
});
|
||||
} else {
|
||||
login.find(".btn").prop("disabled", false);
|
||||
}
|
||||
|
||||
let token;
|
||||
const user = storage.get("user");
|
||||
|
||||
login.find(".btn").prop("disabled", false);
|
||||
|
||||
login.find("form").on("submit", function() {
|
||||
const form = $(this);
|
||||
|
||||
form.find(".btn").attr("disabled", true);
|
||||
|
||||
const values = {};
|
||||
$.each(form.serializeArray(), function(i, obj) {
|
||||
values[obj.name] = obj.value;
|
||||
});
|
||||
|
||||
storage.set("user", values.user);
|
||||
|
||||
socket.emit("auth", values);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (!data.success) {
|
||||
if (login.length === 0) {
|
||||
socket.disconnect();
|
||||
|
@ -4,7 +4,6 @@ const $ = require("jquery");
|
||||
const io = require("socket.io-client");
|
||||
const utils = require("./utils");
|
||||
const path = window.location.pathname + "socket.io/";
|
||||
const status = $("#loading-page-message, #connection-error");
|
||||
|
||||
const socket = io({
|
||||
transports: $(document.body).data("transports"),
|
||||
@ -18,11 +17,11 @@ socket.on("connect_error", handleDisconnect);
|
||||
socket.on("error", handleDisconnect);
|
||||
|
||||
socket.on("reconnecting", function(attempt) {
|
||||
status.text(`Reconnecting… (attempt ${attempt})`);
|
||||
$("#loading-page-message, #connection-error").text(`Reconnecting… (attempt ${attempt})`);
|
||||
});
|
||||
|
||||
socket.on("connecting", function() {
|
||||
status.text("Connecting…");
|
||||
$("#loading-page-message, #connection-error").text("Connecting…");
|
||||
});
|
||||
|
||||
socket.on("connect", function() {
|
||||
@ -31,17 +30,17 @@ socket.on("connect", function() {
|
||||
// nothing is sent to the server that might have happened.
|
||||
socket.sendBuffer = [];
|
||||
|
||||
status.text("Finalizing connection…");
|
||||
$("#loading-page-message, #connection-error").text("Finalizing connection…");
|
||||
});
|
||||
|
||||
socket.on("authorized", function() {
|
||||
status.text("Loading messages…");
|
||||
$("#loading-page-message, #connection-error").text("Loading messages…");
|
||||
});
|
||||
|
||||
function handleDisconnect(data) {
|
||||
const message = data.message || data;
|
||||
|
||||
status.text(`Waiting to reconnect… (${message})`).addClass("shown");
|
||||
$("#loading-page-message, #connection-error").text(`Waiting to reconnect… (${message})`).addClass("shown");
|
||||
$(".show-more-button, #input").prop("disabled", true);
|
||||
$("#submit").hide();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user