using const instead of let

This commit is contained in:
2021-05-24 13:40:56 +02:00
parent eea681d435
commit 9987086bf0

View File

@ -14,7 +14,7 @@ export class App {
this.defaultLocation = '/welcome'; this.defaultLocation = '/welcome';
this.account = null; this.account = null;
} else { } else {
let session = JSON.parse(localStorage.session); const session = JSON.parse(localStorage.session);
this.defaultLocation = '/'; this.defaultLocation = '/';
this.account = session.account; this.account = session.account;
} }
@ -30,7 +30,7 @@ export class App {
} }
setHash(hash) { setHash(hash) {
let url = new URL(document.URL); const url = new URL(document.URL);
url.hash = hash; url.hash = hash;
location.href = url.toString(); location.href = url.toString();
} }
@ -42,7 +42,7 @@ export class App {
handleHash(hash) { handleHash(hash) {
if (hash[0] === '#') hash = hash.substr(1); if (hash[0] === '#') hash = hash.substr(1);
let defaultCase = () => { const defaultCase = () => {
history.replaceState(null, null, `#${this.defaultLocation}`); history.replaceState(null, null, `#${this.defaultLocation}`);
this.handleHash(this.defaultLocation); this.handleHash(this.defaultLocation);
} }
@ -92,11 +92,11 @@ export class App {
} }
} }
let session = new USIMP.Session(domain); const session = new USIMP.Session(domain);
let rtt = await session.chooseDomainServer(); const rtt = await session.chooseDomainServer();
console.log(rtt); console.log(rtt);
let response = await session.authenticate(accountName, password); const response = await session.authenticate(accountName, password);
if (response.status === "success") { if (response.status === "success") {
this.session = session; this.session = session;
this.defaultLocation = "/"; this.defaultLocation = "/";
@ -127,7 +127,7 @@ export class App {
} }
addWelcomeWindow() { addWelcomeWindow() {
let win = document.createElement("div"); const win = document.createElement("div");
win.classList.add("window-welcome"); win.classList.add("window-welcome");
win.innerHTML = ` win.innerHTML = `
@ -138,18 +138,18 @@ export class App {
} }
addMessage(message) { addMessage(message) {
let msg = document.createElement("div"); const msg = document.createElement("div");
msg.classList.add("message"); msg.classList.add("message");
msg.innerText = message; msg.innerText = message;
let chat = this.main.getElementsByClassName("chat-history")[0]; const chat = this.main.getElementsByClassName("chat-history")[0];
chat.appendChild(msg); chat.appendChild(msg);
chat.scrollTop = chat.scrollHeight; chat.scrollTop = chat.scrollHeight;
} }
addLoginWindow() { addLoginWindow() {
let win = document.createElement("div"); const win = document.createElement("div");
win.classList.add("window-login"); win.classList.add("window-login");
win.innerHTML = ` win.innerHTML = `
@ -161,17 +161,20 @@ export class App {
<button type="submit">Login</button> <button type="submit">Login</button>
</form>`; </form>`;
win.getElementsByTagName("form")[0].addEventListener("submit", async (evt) => { win.getElementsByTagName("form")[0].addEventListener("submit", async (event) => {
evt.preventDefault(); event.preventDefault();
let form = evt.target; const form = event.target;
for (let e of form) e.disabled = true; for (const e of form) {
e.disabled = true;
e.removeAttribute("invalid");
}
for (let d of form.getElementsByTagName("div")) { for (const d of form.getElementsByTagName("div")) {
form.removeChild(d); form.removeChild(d);
} }
function formError(msg) { function formError(msg) {
let div = document.createElement("div"); const div = document.createElement("div");
div.classList.add("error"); div.classList.add("error");
div.innerText = msg; div.innerText = msg;
form.appendChild(div); form.appendChild(div);
@ -186,9 +189,8 @@ export class App {
document.getElementsByName("domain")[0].setAttribute("invalid", "invalid"); document.getElementsByName("domain")[0].setAttribute("invalid", "invalid");
} }
formError(error.toString()); formError(error.toString());
console.error(error);
} finally { } finally {
for (let e of form) e.disabled = false; for (const e of form) e.disabled = false;
} }
}); });
@ -214,7 +216,7 @@ export class App {
</div> </div>
</div>`; </div>`;
let input = document.getElementsByName("message")[0]; const input = document.getElementsByName("message")[0];
input.addEventListener("keyup", (event) => { input.addEventListener("keyup", (event) => {
if (event.key === "Enter" && input.value.length > 0) { if (event.key === "Enter" && input.value.length > 0) {
this.session.sendEvent("60nc0XXDIYUh6QzX4p0rMpCdzDmxghZLZk8dLuQh628", { this.session.sendEvent("60nc0XXDIYUh6QzX4p0rMpCdzDmxghZLZk8dLuQh628", {