diff --git a/static/index.html b/static/index.html
index 73e71b3..5dcc382 100644
--- a/static/index.html
+++ b/static/index.html
@@ -1023,6 +1023,9 @@
constructor() {
super();
this.currentSort = 'recent';
+ // Bind methods to ensure proper reference for event removal
+ this.handleSortChange = this.handleSortChange.bind(this);
+ this.handleRefreshView = this.handleRefreshView.bind(this);
}
async connectedCallback() {
@@ -1031,15 +1034,15 @@
`;
- eventBus.on('sort-changed', (sort) => this.handleSortChange(sort));
- eventBus.on('refresh-view', () => this.loadFeed());
+ eventBus.on('sort-changed', this.handleSortChange);
+ eventBus.on('refresh-view', this.handleRefreshView);
await this.loadFeed();
}
disconnectedCallback() {
eventBus.off('sort-changed', this.handleSortChange);
- eventBus.off('refresh-view', this.loadFeed);
+ eventBus.off('refresh-view', this.handleRefreshView);
}
handleSortChange(sort) {
@@ -1047,6 +1050,10 @@
this.loadFeed();
}
+ handleRefreshView() {
+ this.loadFeed();
+ }
+
async loadFeed() {
const params = new URLSearchParams({
sort: this.currentSort,
@@ -1070,9 +1077,6 @@
});
this.appendChild(container);
-
- // Re-add event listener after re-render
- eventBus.on('sort-changed', (sort) => this.handleSortChange(sort));
}
}
}