Fetch photo list fresh on each slideshow start
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
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]);
|
||||
|
||||
Reference in New Issue
Block a user