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