web/elements: trigger search select data update on connected callback

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer
2023-01-02 10:26:52 +01:00
parent 042cd0b2cb
commit 9564894eda
4 changed files with 89 additions and 39 deletions

View File

@ -78,18 +78,6 @@ export abstract class AKChart<T> extends AKElement {
constructor() {
super();
window.addEventListener("resize", () => {
if (this.chart) {
this.chart.resize();
}
});
window.addEventListener(EVENT_REFRESH, () => {
this.apiRequest().then((r: T) => {
if (!this.chart) return;
this.chart.data = this.getChartData(r);
this.chart.update();
});
});
const matcher = window.matchMedia("(prefers-color-scheme: light)");
const handler = (ev?: MediaQueryListEvent) => {
if (ev?.matches || matcher.matches) {
@ -103,6 +91,33 @@ export abstract class AKChart<T> extends AKElement {
handler();
}
connectedCallback(): void {
super.connectedCallback();
window.addEventListener("resize", this.resizeHandler);
this.addEventListener(EVENT_REFRESH, this.refreshHandler);
}
disconnectedCallback(): void {
super.disconnectedCallback();
window.removeEventListener("resize", this.resizeHandler);
this.removeEventListener(EVENT_REFRESH, this.refreshHandler);
}
refreshHandler(): void {
this.apiRequest().then((r: T) => {
if (!this.chart) return;
this.chart.data = this.getChartData(r);
this.chart.update();
});
}
resizeHandler(): void {
if (!this.chart) {
return;
}
this.chart.resize();
}
firstUpdated(): void {
this.apiRequest().then((r) => {
const canvas = this.shadowRoot?.querySelector<HTMLCanvasElement>("canvas");