mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-03-28 17:42:45 +01:00
fix: Resolve channel selector dropdown not populating correctly
Fix issue where channel selector would show empty or missing channels after auto-refresh. The populateChannelSelector() function was clearing all options but not rebuilding them from API data correctly. Changes: - Rebuild entire dropdown from API response (including Public channel) - Use currentChannelIdx from global state for selection - Fallback to Public (index 0) if saved channel no longer exists - Remove unused variable (IDE warning fix) Bug: Channel selector showing empty after first auto-refresh Root cause: API returns ALL channels including Public at index 0, but the function was clearing all options and not adding them back. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -663,10 +663,12 @@ async function loadChannels() {
|
||||
function populateChannelSelector(channels) {
|
||||
const selector = document.getElementById('channelSelector');
|
||||
|
||||
// Clear current options
|
||||
selector.innerHTML = '';
|
||||
// Remove all options - we'll rebuild everything from API data
|
||||
while (selector.options.length > 0) {
|
||||
selector.remove(0);
|
||||
}
|
||||
|
||||
// Add channels
|
||||
// Add all channels from API (including Public at index 0)
|
||||
channels.forEach(channel => {
|
||||
const option = document.createElement('option');
|
||||
option.value = channel.index;
|
||||
@@ -674,10 +676,17 @@ function populateChannelSelector(channels) {
|
||||
selector.appendChild(option);
|
||||
});
|
||||
|
||||
// Set current selection
|
||||
// Restore selection (use currentChannelIdx from global state)
|
||||
selector.value = currentChannelIdx;
|
||||
|
||||
console.log(`Loaded ${channels.length} channels`);
|
||||
// If the saved channel doesn't exist, fall back to Public (0)
|
||||
if (selector.value !== currentChannelIdx.toString()) {
|
||||
currentChannelIdx = 0;
|
||||
selector.value = 0;
|
||||
localStorage.setItem('mc_active_channel', '0');
|
||||
}
|
||||
|
||||
console.log(`Loaded ${channels.length} channels, active: ${currentChannelIdx}`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user