From afddfd5bb13d147941da8c13d8a40a04d4606edc Mon Sep 17 00:00:00 2001 From: Ludwig Mey Date: Tue, 28 Jul 2026 21:27:40 +1200 Subject: [PATCH] Fetch photo list fresh on each slideshow start MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously fetched once at page load — if photos were added after the service started they wouldn't appear until a restart. Now fetches on every slideshow activation so new photos show up immediately. Co-Authored-By: Claude Sonnet 4.6 --- static/js/app.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/static/js/app.js b/static/js/app.js index ee176c0..70e91a9 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -234,19 +234,10 @@ function showAddToast() { // ---------- Slideshow screensaver ---------- -async function initSlideshow() { - try { - const res = await fetch('/api/photos'); - photos = await res.json(); - } catch (e) { - console.error('Could not load photos:', e); - } - - // Any interaction resets the inactivity timer (or dismisses the slideshow) +function initSlideshow() { ['touchstart', 'click', 'mousemove', 'keydown'].forEach(evt => { document.addEventListener(evt, handleUserActivity, { passive: true }); }); - resetInactivityTimer(); } @@ -260,21 +251,30 @@ function handleUserActivity() { function resetInactivityTimer() { clearTimeout(inactivityTimer); - if (photos.length > 0) { - inactivityTimer = setTimeout(showSlideshow, INACTIVITY_TIMEOUT); - } + inactivityTimer = setTimeout(showSlideshow, INACTIVITY_TIMEOUT); } -function showSlideshow() { +async function showSlideshow() { + // Fetch fresh each time so newly added photos appear without a restart + try { + const res = await fetch('/api/photos'); + photos = await res.json(); + } catch (e) { + console.error('Could not load photos:', e); + } + + if (!photos.length) { + resetInactivityTimer(); + return; + } + slideshowActive = true; const overlay = document.getElementById('slideshow-overlay'); overlay.classList.remove('hidden'); - // Start from a random position in the shuffled list slideIndex = Math.floor(Math.random() * photos.length); activeSlot = 'a'; - // Show first photo immediately; preload second into the inactive slot loadSlide('a', photos[slideIndex]); if (photos.length > 1) { loadSlide('b', photos[(slideIndex + 1) % photos.length]);