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 <noreply@anthropic.com>
This commit is contained in:
@@ -51,7 +51,7 @@ export function renderAgenda(container, currentDate, events, onEventClick) {
|
|||||||
</div>`;
|
</div>`;
|
||||||
}).join('');
|
}).join('');
|
||||||
|
|
||||||
return `<div class="agenda-day">
|
return `<div class="agenda-day" data-date="${key}">
|
||||||
<div class="agenda-date ${todayCls}">
|
<div class="agenda-date ${todayCls}">
|
||||||
<div class="agenda-date-num">${date.getDate()}</div>
|
<div class="agenda-date-num">${date.getDate()}</div>
|
||||||
<div class="agenda-date-label">
|
<div class="agenda-date-label">
|
||||||
@@ -65,6 +65,19 @@ export function renderAgenda(container, currentDate, events, onEventClick) {
|
|||||||
|
|
||||||
container.innerHTML = `<div class="agenda-view">${html}</div>`;
|
container.innerHTML = `<div class="agenda-view">${html}</div>`;
|
||||||
|
|
||||||
|
// 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 => {
|
container.querySelectorAll('.agenda-event').forEach(el => {
|
||||||
el.addEventListener('click', () => {
|
el.addEventListener('click', () => {
|
||||||
const ev = events.find(ev => ev.id === el.dataset.id && ev.url === el.dataset.url);
|
const ev = events.find(ev => ev.id === el.dataset.id && ev.url === el.dataset.url);
|
||||||
|
|||||||
Reference in New Issue
Block a user