static: fetch messages which were created when the user arrives/leaves the page

This commit is contained in:
Jens Langhammer 2020-11-26 18:16:50 +01:00
parent a91d0ddc6c
commit 14ab9bbd05
3 changed files with 24 additions and 2 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -38,6 +38,10 @@ export class Messages extends LitElement {
this.connect();
}
firstUpdated() {
this.fetchMessages();
}
connect() {
const wsUrl = `${window.location.protocol.replace("http", "ws")}//${
window.location.host
@ -64,6 +68,24 @@ export class Messages extends LitElement {
});
}
/* Fetch messages which were stored in the session.
* This mostly gets messages which were created when the user arrives/leaves the site
* and especially the login flow */
fetchMessages() {
return fetch(this.url)
.then((r) => r.json())
.then((r) => (this.messages = r))
.then((r) => {
const container = <HTMLElement>(
this.querySelector(".pf-c-alert-group")!
);
r.forEach((message: Message) => {
const messageElement = this.renderMessage(message);
container.appendChild(messageElement);
});
});
}
renderMessage(message: Message): ChildNode {
const id = ID("pb-message");
const el = document.createElement("template");