From 5a0f1c1f4e51b7a0fc67a2516247c8806064dd2c Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Mon, 11 Nov 2019 15:48:47 +0200 Subject: [PATCH] Replace getActiveWindowComponent with an event --- client/components/Windows/SignIn.vue | 10 ++++++++++ client/js/socket-events/auth.js | 11 +++++------ client/js/vue.js | 5 ----- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/client/components/Windows/SignIn.vue b/client/components/Windows/SignIn.vue index 92736aae..7ab702d9 100644 --- a/client/components/Windows/SignIn.vue +++ b/client/components/Windows/SignIn.vue @@ -71,7 +71,17 @@ export default { errorShown: false, }; }, + mounted() { + this.$root.$on("auth:failed", this.onAuthFailed); + }, + beforeDestroy() { + this.$root.$off("auth:failed", this.onAuthFailed); + }, methods: { + onAuthFailed() { + this.inFlight = false; + this.errorShown = true; + }, onSubmit(event) { event.preventDefault(); diff --git a/client/js/socket-events/auth.js b/client/js/socket-events/auth.js index d7b9d362..57a06ac1 100644 --- a/client/js/socket-events/auth.js +++ b/client/js/socket-events/auth.js @@ -2,7 +2,7 @@ const socket = require("../socket"); const storage = require("../localStorage"); -const {vueApp, getActiveWindowComponent} = require("../vue"); +const {vueApp} = require("../vue"); const store = require("../store").default; let lastServerHash = null; @@ -18,12 +18,9 @@ socket.on("auth:failed", function() { return reloadPage("Authentication failed, reloading…"); } - // TODO: This will most likely fail getActiveWindowComponent showSignIn(); - // TODO: getActiveWindowComponent is the SignIn component, find a better way to set this - getActiveWindowComponent().errorShown = true; - getActiveWindowComponent().inFlight = false; + vueApp.$emit("auth:failed"); }); socket.on("auth:start", function(serverHash) { @@ -78,7 +75,9 @@ function showSignIn() { window.g_TheLoungeRemoveLoading(); } - vueApp.$router.push("/sign-in"); + if (vueApp.$route.name !== "SignIn") { + vueApp.$router.push("/sign-in"); + } } function reloadPage(message) { diff --git a/client/js/vue.js b/client/js/vue.js index df7a7453..c5004b69 100644 --- a/client/js/vue.js +++ b/client/js/vue.js @@ -120,12 +120,7 @@ function initChannel(channel) { } } -function getActiveWindowComponent() { - return vueApp.$refs.app.$refs.window; -} - module.exports = { vueApp, initChannel, - getActiveWindowComponent, };