|
5 | 5 | (function() { |
6 | 6 | 'use strict'; |
7 | 7 |
|
8 | | - const STORAGE_KEY = 'pythondeadlines-favorites'; // Use existing storage key |
| 8 | + const STORAGE_KEY = 'pythondeadlines-favorites'; // Legacy storage key for backward compatibility |
9 | 9 | const SERIES_KEY = 'pythondeadlines-series-subscriptions'; |
10 | 10 | const SAVED_CONFERENCES_KEY = 'pythondeadlines-saved-conferences'; |
11 | 11 | let currentPopover = null; |
12 | 12 | let isMobile = window.innerWidth <= 768; |
13 | 13 |
|
14 | | - // Load saved preferences from existing system |
| 14 | + // Load saved preferences from ConferenceStateManager |
15 | 15 | function getPrefs() { |
16 | 16 | 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 |
18 | 36 | const favorites = store.get(STORAGE_KEY) || []; |
19 | 37 | const savedConferences = store.get(SAVED_CONFERENCES_KEY) || {}; |
20 | 38 | const series = store.get(SERIES_KEY) || {}; |
|
39 | 57 | } |
40 | 58 | } |
41 | 59 |
|
42 | | - // Save preferences using existing system |
| 60 | + // Save preferences using ConferenceStateManager |
43 | 61 | function savePrefs(prefs) { |
44 | 62 | 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 |
46 | 96 | const favorites = []; |
47 | 97 | const savedConferences = store.get(SAVED_CONFERENCES_KEY) || {}; |
48 | 98 |
|
@@ -535,6 +585,18 @@ END:VCALENDAR`; |
535 | 585 | initializeIndicators(); |
536 | 586 | } |
537 | 587 |
|
| 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 | + |
538 | 600 | // Export API for other components |
539 | 601 | window.minimalActionAPI = { |
540 | 602 | getPrefs: getPrefs, |
|
0 commit comments