From fcf25320cb3c02ad3991c22ad85e4ba7dbcff534 Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Sun, 28 Aug 2022 20:52:34 +0300 Subject: [PATCH] Don't render anything until gateway connection --- frontend/src/gateway.js | 1 + frontend/src/main.js | 38 +++++++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/frontend/src/gateway.js b/frontend/src/gateway.js index e7a6d61..9f70491 100644 --- a/frontend/src/gateway.js +++ b/frontend/src/gateway.js @@ -60,6 +60,7 @@ export default { init(token) { if (!token) { log("no auth token, skipping connection"); + this.dispatch(GatewayEventType.Close, GatewayErrors.BAD_AUTH); this.dispatch(GatewayEventType.BadAuth, 0); return false; } diff --git a/frontend/src/main.js b/frontend/src/main.js index 52ff208..446840a 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -3,21 +3,33 @@ import { getItem } from './storage'; import { authWithToken, useAuthHandlers } from './auth'; import { initResponsiveHandlers } from './responsive'; import { useDebuggingApi } from './debuggingapi'; +import gateway, { GatewayEventType } from './gateway'; -useDebuggingApi(); -initResponsiveHandlers(); -useAuthHandlers(); -authWithToken(getItem("auth:token")); +function handleGatewaySettlement() { + initResponsiveHandlers(); -// Remove loading screen -const loadingElement = document.getElementById("pre--loading-screen"); -if (loadingElement) { - loadingElement.parentElement.removeChild(loadingElement); + const loadingElement = document.getElementById("pre--loading-screen"); + if (loadingElement) { + loadingElement.parentElement.removeChild(loadingElement); + } + + const app = new Main({ + target: document.body + }); + window.__waffle.app = app; + + gateway.unsubscribe(GatewayEventType.Ready, handleGatewaySettlement); + gateway.unsubscribe(GatewayEventType.Close, handleGatewaySettlement); } -const app = new Main({ - target: document.body -}); -window.__waffle.app = app; +function main() { + useDebuggingApi(); + useAuthHandlers(); + + gateway.subscribe(GatewayEventType.Ready, handleGatewaySettlement); + gateway.subscribe(GatewayEventType.Close, handleGatewaySettlement); + + authWithToken(getItem("auth:token")); +} -export default app; \ No newline at end of file +main();