fixed architecture to dispatch events when routes and token changes

This commit is contained in:
Fran Jurmanović
2021-05-31 12:00:07 +02:00
parent 48df6fc7cf
commit e1ab0e51d6
10 changed files with 131 additions and 29 deletions

View File

@@ -11,10 +11,16 @@ class HomePageElement extends HTMLElement {
constructor() {
super();
}
@update
connectedCallback() {
this.pingService = new PingService(this.appMain?.appService);
if (this.appMain.isAuth) this.getPong();
this.update();
window.addEventListener("tokenchange", this.update);
}
disconnectedCallback(): void {
window.removeEventListener("tokenchange", this.update);
}
getPong = async () => {
@@ -31,13 +37,21 @@ class HomePageElement extends HTMLElement {
render() {
return html`
<app-link data-to="/home" data-title="Home"></app-link> |
<app-link data-to="/" data-title="Main"></app-link> |
<app-link data-to="/login" data-title="Login"></app-link>
${this.appMain.isAuth
? html`<app-link data-to="/home" data-title="Home"></app-link>
|<app-link
data-to="/logout"
data-title="Logout"
></app-link>`
: html`<app-link
data-to="/login"
data-title="Login"
></app-link>`}
`;
}
update() {
update = () => {
render(this.render(), this);
}
};
}