diff --git a/static/js/tasks.js b/static/js/tasks.js index 7fdb25c..ffea065 100644 --- a/static/js/tasks.js +++ b/static/js/tasks.js @@ -83,6 +83,7 @@ async function persistSelectedTask(taskId) { if (goal) { goal.selected_task_id = taskId; } + console.log("Saved selected task:", taskId); } catch (error) { console.error("Failed to persist selected task:", error); } @@ -149,7 +150,9 @@ function scrollToTask(taskId) { if (taskElement) { const scrollView = document.getElementById("scroll-view"); const taskTop = taskElement.offsetTop; - scrollView.scrollTop = taskTop; + const scrollViewHeight = scrollView.clientHeight; + const taskHeight = taskElement.offsetHeight; + scrollView.scrollTop = taskTop - (scrollViewHeight / 2) + (taskHeight / 2); } } @@ -171,13 +174,16 @@ function handleScrollFocus() { const scrollView = document.getElementById("scroll-view"); const taskItems = document.querySelectorAll(".task-item"); - const scrollTop = scrollView.scrollTop; + const scrollViewRect = scrollView.getBoundingClientRect(); + const focusCenter = scrollViewRect.top + scrollViewRect.height / 2; let closestItem = null; let closestDistance = Infinity; taskItems.forEach(item => { - const distance = Math.abs(item.offsetTop - scrollTop); + const itemRect = item.getBoundingClientRect(); + const itemCenter = itemRect.top + itemRect.height / 2; + const distance = Math.abs(itemCenter - focusCenter); item.classList.remove("in-focus"); @@ -201,7 +207,9 @@ function handleScrollFocus() { } function handleScrollSave() { + // Save the task that has in-focus class (determined by handleScrollFocus) const inFocusTask = document.querySelector(".task-item.in-focus"); + console.log("handleScrollSave: inFocusTask=", inFocusTask?.dataset.taskId, "isInitializing=", isInitializing); if (inFocusTask && !isInitializing) { const taskId = parseInt(inFocusTask.dataset.taskId);