Skip to content

Commit df5356b

Browse files
authored
Merge pull request #40 from joshuaaaaa/claude/design-improvements-vcoSk
Fix auto-restore not showing stations in main card after cache clear
2 parents 68c9884 + db7e348 commit df5356b

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

radio-browser-card.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,12 @@ class RadioBrowserCard extends HTMLElement {
153153
if (!result || !result.value) return;
154154

155155
const data = result.value;
156-
const localFavs = localStorage.getItem('radio_favorites');
157-
const localCustom = localStorage.getItem('radio_custom_stations');
158-
const hasLocalData = (localFavs && JSON.parse(localFavs).length > 0) ||
159-
(localCustom && JSON.parse(localCustom).length > 0);
156+
const hasLocalFavs = this._favorites && this._favorites.length > 0;
157+
const hasLocalCustom = this._customStations && this._customStations.length > 0;
158+
const hasServerData = (data.favorites?.length > 0 || data.custom_stations?.length > 0);
160159

161-
// Only restore if localStorage is empty (cache was cleared) and server has data
162-
if (!hasLocalData && (data.favorites?.length > 0 || data.custom_stations?.length > 0)) {
160+
// Only restore if local data is empty (cache was cleared) and server has data
161+
if (!hasLocalFavs && !hasLocalCustom && hasServerData) {
163162
console.log('Cache cleared detected - restoring from HA server backup...');
164163
if (data.favorites?.length > 0) {
165164
this._favorites = data.favorites;
@@ -170,7 +169,14 @@ class RadioBrowserCard extends HTMLElement {
170169
localStorage.setItem('radio_custom_stations', JSON.stringify(data.custom_stations));
171170
}
172171
console.log(`Restored: ${data.favorites?.length || 0} favorites, ${data.custom_stations?.length || 0} custom stations`);
173-
this.updatePlaylist();
172+
173+
// Force re-render to show restored data (playlist DOM may already exist)
174+
if (this.shadowRoot.querySelector('.playlist-items')) {
175+
this.updatePlaylist();
176+
} else {
177+
// DOM not ready yet, re-render the whole card
178+
this.render();
179+
}
174180
}
175181
} catch (e) {
176182
console.log('Auto-restore from HA server not available:', e);

0 commit comments

Comments
 (0)