static: dynamically add messages instead of replacing

This commit is contained in:
Jens Langhammer 2020-10-16 19:22:44 +02:00
parent c6eb015d18
commit 897f64600a
3 changed files with 12 additions and 9 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

@ -34,7 +34,13 @@ class Messages extends LitElement {
} }
firstUpdated() { firstUpdated() {
return fetch(this.url).then(r => r.json()).then(r => this.messages = r); return fetch(this.url).then(r => r.json()).then(r => this.messages = r).then((r) => {
const container = this.querySelector(".pf-c-alert-group");
r.forEach(message => {
const messageElement = this.renderMessage(message);
container.appendChild(messageElement);
});
});
} }
renderMessage(message) { renderMessage(message) {
@ -57,10 +63,7 @@ class Messages extends LitElement {
} }
render() { render() {
if (this.messages === undefined) { return html`<ul class="pf-c-alert-group pf-m-toast"></ul>`;
return html`<ul class="pf-c-alert-group pf-m-toast"></ul>`;
}
return html`<ul class="pf-c-alert-group pf-m-toast">${this.messages.map(item => this.renderMessage(item))}</ul>`;
} }
} }