Fix duplicate indicator addition by preventing multiple event listeners

Added eventListenersSet flag to track if event delegation has been setup.
Only call setupEventListeners() once during initial render to prevent
adding multiple event listeners that cause 'addIndicator' to be called
multiple times when clicking a button once.

This fixes the bug where one click adds 8 identical indicators.
This commit is contained in:
DiTus
2026-02-25 22:58:52 +01:00
parent 5f6d71f616
commit 551953f564

View File

@ -6,6 +6,7 @@ let configuringId = null;
let searchQuery = ''; let searchQuery = '';
let selectedCategory = 'all'; let selectedCategory = 'all';
let nextInstanceId = 1; let nextInstanceId = 1;
let eventListenersSet = false;
// Chart pane management // Chart pane management
let indicatorPanes = new Map(); let indicatorPanes = new Map();
@ -153,7 +154,6 @@ export function renderIndicatorPanel() {
<div class="section-title">★ Favorites</div> <div class="section-title">★ Favorites</div>
${[...favoriteIds].map(id => { ${[...favoriteIds].map(id => {
const ind = available.find(a => { const ind = available.find(a => {
// Find matching indicator by type
return a.type === id || (activeIndicators.find(ai => ai.id === id)?.type === ''); return a.type === id || (activeIndicators.find(ai => ai.id === id)?.type === '');
}); });
if (!ind) return ''; if (!ind) return '';
@ -187,7 +187,12 @@ export function renderIndicatorPanel() {
</div> </div>
`; `;
// Only setup event listeners once
if (!eventListenersSet) {
setupEventListeners(); setupEventListeners();
eventListenersSet = true;
}
}
} }
function renderIndicatorItem(indicator, isFavorite) { function renderIndicatorItem(indicator, isFavorite) {