Do not keep sign-in and loader references in memory

This commit is contained in:
Pavel Djundik 2017-11-27 19:39:16 +02:00
parent ba002cca64
commit 5855099d5b
2 changed files with 31 additions and 28 deletions

View file

@ -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,12 +16,12 @@ socket.on("auth", function(data) {
return;
}
const login = $("#sign-in");
if (data.serverHash > -1) {
utils.serverHash = data.serverHash;
let token;
const user = storage.get("user");
login.find(".btn").prop("disabled", false);
login.html(templates.windows.sign_in());
login.find("form").on("submit", function() {
const form = $(this);
@ -41,6 +39,12 @@ socket.on("auth", function(data) {
return false;
});
} else {
login.find(".btn").prop("disabled", false);
}
let token;
const user = storage.get("user");
if (!data.success) {
if (login.length === 0) {

View file

@ -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();