static: dynamically add messages instead of replacing
This commit is contained in:
parent
c6eb015d18
commit
897f64600a
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -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>`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue