From 906241a74378a72caa071c2565a51771993d5438 Mon Sep 17 00:00:00 2001 From: Scarriffle Date: Thu, 18 Jun 2026 17:13:18 +0200 Subject: [PATCH] fix: agenda view scrolls to current date on render The agenda lists the whole cached range, so clicking Today only reset scroll to the top (earliest past event). Scroll the agenda to the current date (or the next day with events) after rendering, so Today/mini-cal clicks land correctly. Co-Authored-By: Claude Opus 4.8 --- frontend/js/views/agenda.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/frontend/js/views/agenda.js b/frontend/js/views/agenda.js index 45a33f4..330f4c1 100644 --- a/frontend/js/views/agenda.js +++ b/frontend/js/views/agenda.js @@ -51,7 +51,7 @@ export function renderAgenda(container, currentDate, events, onEventClick) { `; }).join(''); - return `
+ return `
${date.getDate()}
@@ -65,6 +65,19 @@ export function renderAgenda(container, currentDate, events, onEventClick) { container.innerHTML = `
${html}
`; + // The agenda lists the whole cached range (past + future). Scroll so the + // current date (e.g. "today" after the Today button) sits at the top — or + // the next day with events if the current date itself has none. + const scrollEl = container.querySelector('.agenda-view'); + if (scrollEl) { + const curKey = `${currentDate.getFullYear()}-${String(currentDate.getMonth()+1).padStart(2,'0')}-${String(currentDate.getDate()).padStart(2,'0')}`; + const days = [...scrollEl.querySelectorAll('.agenda-day')]; + const target = days.find(d => d.dataset.date >= curKey) || days[days.length - 1]; + if (target) { + scrollEl.scrollTop += target.getBoundingClientRect().top - scrollEl.getBoundingClientRect().top; + } + } + container.querySelectorAll('.agenda-event').forEach(el => { el.addEventListener('click', () => { const ev = events.find(ev => ev.id === el.dataset.id && ev.url === el.dataset.url);