From 07d06253bac344ab7ef8c35c2cc9586372ab4493 Mon Sep 17 00:00:00 2001 From: starnakin Date: Wed, 29 Nov 2023 16:18:54 +0100 Subject: [PATCH] opti: do not execute postInit if getHtml is null --- frontend/static/js/index.js | 6 +++++- frontend/static/js/views/accounts/LoginView.js | 4 +--- frontend/static/js/views/accounts/RegisterView.js | 7 ++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/frontend/static/js/index.js b/frontend/static/js/index.js index 9e00432..a261a8c 100644 --- a/frontend/static/js/index.js +++ b/frontend/static/js/index.js @@ -59,7 +59,11 @@ const router = async () => { } const view = new match.route.view(getParams(match)); - document.querySelector("#app").innerHTML = await view.getHtml(); + let content = await view.getHtml(); + if (content == null) + return; + + document.querySelector("#app").innerHTML = content await view.postInit(); }; diff --git a/frontend/static/js/views/accounts/LoginView.js b/frontend/static/js/views/accounts/LoginView.js index b751328..ff39a0a 100644 --- a/frontend/static/js/views/accounts/LoginView.js +++ b/frontend/static/js/views/accounts/LoginView.js @@ -35,9 +35,7 @@ export default class extends AbstractView { async postInit() { - let login_button = document.getElementById("button") - if (login_button != null) - login_button.onclick = login; + document.getElementById("button").onclick = login; } async getHtml() { diff --git a/frontend/static/js/views/accounts/RegisterView.js b/frontend/static/js/views/accounts/RegisterView.js index 7fe2cef..a4b8287 100644 --- a/frontend/static/js/views/accounts/RegisterView.js +++ b/frontend/static/js/views/accounts/RegisterView.js @@ -30,14 +30,11 @@ export default class extends AbstractView { async postInit() { - let register_button = document.getElementById("button") - if (register_button != null) - register_button.onclick = register; - + document.getElementById("button").onclick = register; } async getHtml() { - if (client.isAuthentificate()) + if (await client.isAuthentificate()) { navigateTo("/home") return;