From 551953f564d08c25250c41190a662d768cad79f6 Mon Sep 17 00:00:00 2001 From: DiTus Date: Wed, 25 Feb 2026 22:58:52 +0100 Subject: [PATCH] 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. --- src/api/dashboard/static/js/ui/indicators-panel-new.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/api/dashboard/static/js/ui/indicators-panel-new.js b/src/api/dashboard/static/js/ui/indicators-panel-new.js index 18f378d..90dcbf0 100644 --- a/src/api/dashboard/static/js/ui/indicators-panel-new.js +++ b/src/api/dashboard/static/js/ui/indicators-panel-new.js @@ -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() {
★ Favorites
${[...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() { `; - setupEventListeners(); + // Only setup event listeners once + if (!eventListenersSet) { + setupEventListeners(); + eventListenersSet = true; + } +} } function renderIndicatorItem(indicator, isFavorite) {