Skip to content

Commit c80cfd8

Browse files
committed
fix: sync favorites between countdown and dashboard pages
Previously, favorites added on the countdown page (via action-bar.js) were stored in 'pythondeadlines-favorites' while the dashboard read from 'pydeadlines_savedEvents' via ConferenceStateManager, causing favorites to not sync between pages. Changes: - Modified action-bar.js to use ConferenceStateManager for all save/load operations - Added event listeners for conferenceStateUpdate to sync UI state - Maintained backward compatibility with fallback to legacy storage - Ensured single source of truth through ConferenceStateManager This fixes the bug where favorites added on countdown page didn't appear on dashboard. All existing tests pass without regression.
1 parent 434fcea commit c80cfd8

File tree

1 file changed

+67
-5
lines changed

1 file changed

+67
-5
lines changed

static/js/action-bar.js

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,34 @@
55
(function() {
66
'use strict';
77

8-
const STORAGE_KEY = 'pythondeadlines-favorites'; // Use existing storage key
8+
const STORAGE_KEY = 'pythondeadlines-favorites'; // Legacy storage key for backward compatibility
99
const SERIES_KEY = 'pythondeadlines-series-subscriptions';
1010
const SAVED_CONFERENCES_KEY = 'pythondeadlines-saved-conferences';
1111
let currentPopover = null;
1212
let isMobile = window.innerWidth <= 768;
1313

14-
// Load saved preferences from existing system
14+
// Load saved preferences from ConferenceStateManager
1515
function getPrefs() {
1616
try {
17-
// Get favorites from existing FavoritesManager format
17+
// Use ConferenceStateManager if available
18+
if (window.confManager) {
19+
const savedEvents = window.confManager.getSavedEvents();
20+
const prefs = {};
21+
22+
savedEvents.forEach(conf => {
23+
const confId = conf.id;
24+
prefs[confId] = { saved: true };
25+
26+
// Check if series is followed
27+
if (window.confManager.isSeriesFollowed(conf.conference)) {
28+
prefs[confId].series = true;
29+
}
30+
});
31+
32+
return prefs;
33+
}
34+
35+
// Fallback to legacy storage if ConferenceStateManager not available yet
1836
const favorites = store.get(STORAGE_KEY) || [];
1937
const savedConferences = store.get(SAVED_CONFERENCES_KEY) || {};
2038
const series = store.get(SERIES_KEY) || {};
@@ -39,10 +57,42 @@
3957
}
4058
}
4159

42-
// Save preferences using existing system
60+
// Save preferences using ConferenceStateManager
4361
function savePrefs(prefs) {
4462
try {
45-
// Convert our format to FavoritesManager format
63+
// Use ConferenceStateManager if available
64+
if (window.confManager) {
65+
// Get current saved events for comparison
66+
const currentSaved = new Set(window.confManager.getSavedEvents().map(c => c.id));
67+
68+
Object.keys(prefs).forEach(confId => {
69+
const isSaved = prefs[confId].saved;
70+
const wasSaved = currentSaved.has(confId);
71+
72+
// Handle save/unsave through ConferenceStateManager
73+
if (isSaved && !wasSaved) {
74+
window.confManager.saveEvent(confId);
75+
} else if (!isSaved && wasSaved) {
76+
window.confManager.removeSavedEvent(confId);
77+
}
78+
79+
// Handle series following
80+
const conf = window.confManager.getConference(confId);
81+
if (conf) {
82+
const isSeriesFollowed = window.confManager.isSeriesFollowed(conf.conference);
83+
if (prefs[confId].series && !isSeriesFollowed) {
84+
window.confManager.followSeries(conf.conference);
85+
} else if (!prefs[confId].series && isSeriesFollowed) {
86+
window.confManager.unfollowSeries(conf.conference);
87+
}
88+
}
89+
});
90+
91+
// ConferenceStateManager will fire its own events
92+
return;
93+
}
94+
95+
// Fallback to legacy storage if ConferenceStateManager not available
4696
const favorites = [];
4797
const savedConferences = store.get(SAVED_CONFERENCES_KEY) || {};
4898

@@ -535,6 +585,18 @@ END:VCALENDAR`;
535585
initializeIndicators();
536586
}
537587

588+
// Listen for ConferenceStateManager updates
589+
window.addEventListener('conferenceStateUpdate', function(e) {
590+
// Re-initialize indicators when state changes
591+
initializeIndicators();
592+
});
593+
594+
// Also listen for ConferenceStateManager to become ready
595+
window.addEventListener('conferenceManagerReady', function(e) {
596+
// Re-initialize with ConferenceStateManager data
597+
initializeIndicators();
598+
});
599+
538600
// Export API for other components
539601
window.minimalActionAPI = {
540602
getPrefs: getPrefs,

0 commit comments

Comments
 (0)