From 0d6bef5c41c47e1564f0b5ddbdaa8a29975866e5 Mon Sep 17 00:00:00 2001 From: cproudlock Date: Tue, 18 Nov 2025 09:13:56 -0500 Subject: [PATCH] Fix carousel reset on data refresh - preserve index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The carousel was resetting to index 0 every 10 seconds when the dashboard refreshed data from the API. This caused the carousel to show: - 0s: test 2 (index 0) - 5s: test again (index 1) - 10s: DATA REFRESH → reset to test 2 (index 0) ❌ Fixed by: - Preserving currentUpcomingIndex across renderEvents() calls - Only reset index if it's out of range for new data - Render the currently active event instead of always starting at 0 - Added logging to show index preservation Now the carousel cycles continuously through all 4 events without resetting when the page refreshes data every 10 seconds. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- shopfloor-dashboard/index.html | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/shopfloor-dashboard/index.html b/shopfloor-dashboard/index.html index e5eb38f..a4a0f59 100644 --- a/shopfloor-dashboard/index.html +++ b/shopfloor-dashboard/index.html @@ -867,18 +867,26 @@ // Store for carousel upcomingEvents = sortedUpcoming; + // Preserve current index if it's still valid, otherwise reset + if (currentUpcomingIndex >= sortedUpcoming.length) { + console.log(`Carousel: Index ${currentUpcomingIndex} out of range, resetting to 0`); + currentUpcomingIndex = 0; + } else { + console.log(`Carousel: Preserving index ${currentUpcomingIndex} across refresh`); + } + html += '
'; html += '
UPCOMING (Next 72 Hours)
'; html += ''; // Close section - - // Reset carousel index - currentUpcomingIndex = 0; } // No events message