From a81103e90d5763d97fd7e3e6685e99eb6916668a Mon Sep 17 00:00:00 2001 From: Nikolay Tatarinov Date: Sat, 21 Feb 2026 01:08:48 +0300 Subject: [PATCH] fix: correct duty list scrolling behavior and simplify current duty check - Removed unnecessary condition for determining if a duty is current, streamlining the logic. - Refactored the scrolling functionality to ensure the view correctly focuses on the current duty or today's block. - Improved code clarity by consolidating the scroll target logic into a reusable function. --- webapp/js/dutyList.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/webapp/js/dutyList.js b/webapp/js/dutyList.js index a4dd573..9c0a3cf 100644 --- a/webapp/js/dutyList.js +++ b/webapp/js/dutyList.js @@ -136,7 +136,7 @@ export function renderDutyList(duties) { dayDuties.forEach((d) => { const start = new Date(d.start_at); const end = new Date(d.end_at); - const isCurrent = isToday && start <= now && now < end; + const isCurrent = start <= now && now < end; dayHtml += '
' + dateCellHtml + @@ -160,18 +160,25 @@ export function renderDutyList(duties) { "
"; }); dutyListEl.innerHTML = fullHtml; - const scrollTarget = dutyListEl.querySelector(".duty-timeline-day--today"); - if (scrollTarget) { - const calendarSticky = document.getElementById("calendarSticky"); + const calendarSticky = document.getElementById("calendarSticky"); + const scrollToEl = (el) => { + if (!el) return; if (calendarSticky) { requestAnimationFrame(() => { const calendarHeight = calendarSticky.offsetHeight; - const todayTop = scrollTarget.getBoundingClientRect().top + window.scrollY; - const scrollTop = Math.max(0, todayTop - calendarHeight); + const top = el.getBoundingClientRect().top + window.scrollY; + const scrollTop = Math.max(0, top - calendarHeight); window.scrollTo({ top: scrollTop, behavior: "auto" }); }); } else { - scrollTarget.scrollIntoView({ behavior: "auto", block: "start" }); + el.scrollIntoView({ behavior: "auto", block: "start" }); } + }; + const currentDutyCard = dutyListEl.querySelector(".duty-item--current"); + const todayBlock = dutyListEl.querySelector(".duty-timeline-day--today"); + if (currentDutyCard) { + scrollToEl(currentDutyCard); + } else if (todayBlock) { + scrollToEl(todayBlock); } }