refactor(static): split schedule and weather to modules

This commit is contained in:
2026-09-07 18:09:49 +03:00
parent d44c8076b4
commit 5db61da32b
7 changed files with 124 additions and 117 deletions
+83
View File
@@ -0,0 +1,83 @@
import { Channel } from "./model";
export class ScheduleChannelElement extends HTMLElement {
static observedAttributes = ["channel", "removable"];
channel: Channel | null = null;
constructor() {
super();
this.handleClick = this.handleClick.bind(this);
this.handleRemoveClick = this.handleRemoveClick.bind(this);
}
connectedCallback() {
this.channel = JSON.parse(this.getAttribute("channel") || "{}");
this.innerHTML = `
<a href="${this.channel?.provider}/${this.channel?.id}"
class="d-flex justify-content-between align-items-start text-decoration-none">
<span>
<span class="badge me-1 text-bg-secondary">${this.channel?.provider}</span>
<span class="text-primary">${this.channel?.name}</span>
</span>
<span>
<span class="text-danger ms-2" data-remove>
&#x2715;
</span>
</span>
</a>`;
this.classList = "list-group-item list-group-item-action";
this.addEventListener("click", this.handleClick);
if (this.hasAttribute("removable")) {
this.querySelector<HTMLElement>("[data-remove]")?.addEventListener("click", this.handleRemoveClick);
} else {
this.querySelector("[data-remove]")?.remove();
}
}
disconnectedCallback() {
this.removeEventListener("click", this.handleClick);
this.querySelector<HTMLElement>("[data-remove]")?.removeEventListener("click", this.handleRemoveClick);
}
handleClick(event: MouseEvent) {
if (this.channel) {
window.scheduleChannelStorage.add(this.channel);
}
}
handleRemoveClick(event: MouseEvent) {
event.preventDefault();
event.stopPropagation();
if (this.channel) {
window.scheduleChannelStorage.remove(this.channel.id);
}
this.remove();
}
}
export class ScheduleChannelGroupElement extends HTMLElement {
static observedAttributes = ["channels"];
channels: Channel[] | null = null;
constructor() {
super();
}
connectedCallback() {
this.channels = JSON.parse(this.getAttribute("channels") || "[]");
const ids = this.channels?.map((item) => `${item.provider}:${item.id}`).join("+");
this.innerHTML = `
<a href="group?ids=${ids}"
class="d-flex justify-content-between align-items-start text-decoration-none">
<span>
<span class="text-primary">Open All</span>
</span>
</a>`;
this.classList = "list-group-item list-group-item-action";
}
}
customElements.define("schedule-channel", ScheduleChannelElement);
customElements.define("schedule-channel-group", ScheduleChannelGroupElement);