Fixed issue with favorites list not snycing in some circumstances
This commit is contained in:
@@ -636,6 +636,11 @@ class ChannelList {
|
||||
} else {
|
||||
await API.favorites.add(sourceId, channelId, 'channel');
|
||||
}
|
||||
|
||||
// Sync to EPG Guide
|
||||
if (window.app?.epgGuide) {
|
||||
window.app.epgGuide.syncFavorite(sourceId, channelId, !wasFavorite);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error toggling favorite:', err);
|
||||
// Revert on error
|
||||
|
||||
@@ -555,6 +555,11 @@ class EpgGuide {
|
||||
} else {
|
||||
await API.favorites.add(sourceId, channelId, 'channel');
|
||||
}
|
||||
|
||||
// 4. Re-render if viewing Favorites group (so new favorites appear immediately)
|
||||
if (this.selectedGroup === 'Favorites') {
|
||||
this.render();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error toggling favorite in EPG:', err);
|
||||
|
||||
@@ -587,6 +592,44 @@ class EpgGuide {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync favorite status from external source (e.g. ChannelList) without API call
|
||||
*/
|
||||
syncFavorite(sourceId, channelId, isFavorite) {
|
||||
// Ensure consistent string format for key
|
||||
const key = `${String(sourceId)}:${String(channelId)}`;
|
||||
const currentlyFav = this.favorites.has(key);
|
||||
|
||||
if (currentlyFav === isFavorite) return; // No change needed
|
||||
|
||||
// Update State
|
||||
if (isFavorite) {
|
||||
this.favorites.add(key);
|
||||
} else {
|
||||
this.favorites.delete(key);
|
||||
}
|
||||
|
||||
// Update DOM (All instances in EPG)
|
||||
const rows = this.container.querySelectorAll(`.epg-channel-row[data-channel-id="${channelId}"][data-source-id="${sourceId}"]`);
|
||||
rows.forEach(row => {
|
||||
const btn = row.querySelector('.favorite-btn');
|
||||
if (btn) {
|
||||
if (isFavorite) {
|
||||
btn.classList.add('active');
|
||||
btn.innerHTML = '❤️';
|
||||
btn.title = 'Remove from Favorites';
|
||||
} else {
|
||||
btn.classList.remove('active');
|
||||
btn.innerHTML = '♡';
|
||||
btn.title = 'Add to Favorites';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Note: We don't call render() here - the favorites Set is updated
|
||||
// and will be used when the user navigates to Guide or switches groups
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate time slots
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user