Merge branch 'Chatte' into feat/accounts

This commit is contained in:
2023-11-29 18:36:08 +01:00
14 changed files with 62 additions and 5 deletions

View File

@ -12,6 +12,8 @@ import { Client } from "./api/client.js";
let client = new Client(location.protocol + "//" + location.host)
let lastView = undefined
const pathToRegex = path => new RegExp("^" + path.replace(/\//g, "\\/").replace(/:\w+/g, "(.+)") + "$");
const getParams = match => {
@ -57,7 +59,12 @@ const router = async (uri = "") => {
result: [uri]
};
}
if (lastView !== undefined)
await lastView.leavePage();
const view = new match.route.view(getParams(match));
lastView = view;
let content = await view.getHtml();
if (content == null)
@ -81,4 +88,4 @@ document.addEventListener("DOMContentLoaded", () => {
router(location.pathname);
});
export { client, navigateTo }
export { client, navigateTo }

View File

@ -6,6 +6,9 @@ export default class {
async postInit() {
}
async leavePage() {
}
setTitle(title) {
document.title = title;
}

View File

@ -14,8 +14,9 @@ export default class extends AbstractView {
if (data.type === 'chat') {
let messages = document.getElementById('messages')
let username = data.username === null || data.username.length <= 0 ? "NoName" : data.username;
messages.insertAdjacentHTML('beforeend', `
<div><p>${data.message}</p></div>
<div><p>${username}: ${data.message}</p></div>
`)
}
@ -32,6 +33,11 @@ export default class extends AbstractView {
}))
form.reset()
})
}
async leavePage() {
this.chatSocket.close();
}
async getHtml() {