From 1f4efcd7b381d90b160df6a64a66dfd03e4ae3da Mon Sep 17 00:00:00 2001 From: Yuyao Huang Date: Sat, 9 May 2026 14:16:15 +0800 Subject: [PATCH] Add debug logging for scroll position restoration --- static/js/tasks.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/static/js/tasks.js b/static/js/tasks.js index 576df7b..ab50973 100644 --- a/static/js/tasks.js +++ b/static/js/tasks.js @@ -41,20 +41,26 @@ async function loadTasks() { isInitializing = true; try { tasks = await get(`/api/tasks?goal_id=${selectedGoalId}`); + console.log("loadTasks: got", tasks.length, "tasks"); + console.log("Task order:", tasks.map(t => ({id: t.id, title: t.title, status: t.status}))); renderTasks(); initSortable(); const currentGoal = goals.find(g => g.id === selectedGoalId); const savedTaskId = currentGoal ? currentGoal.selected_task_id : null; + console.log("loadTasks: savedTaskId from goal =", savedTaskId); const savedTaskExists = savedTaskId && tasks.some(t => t.id === savedTaskId); + console.log("loadTasks: savedTaskExists =", savedTaskExists); if (savedTaskExists) { + console.log("loadTasks: using savedTaskId path"); scrollToTask(savedTaskId); if (isLandscapeMode()) { selectTask(savedTaskId); } } else { + console.log("loadTasks: using fallback path"); const doingTask = tasks.find(t => t.status === "doing"); if (doingTask) { scrollToTask(doingTask.id); @@ -144,13 +150,19 @@ function initSortable() { } function scrollToTask(taskId) { + console.log("scrollToTask called:", taskId); const taskElement = document.querySelector(`[data-task-id="${taskId}"]`); if (taskElement) { const scrollView = document.getElementById("scroll-view"); const taskTop = taskElement.offsetTop; const scrollViewHeight = scrollView.clientHeight; const taskHeight = taskElement.offsetHeight; - scrollView.scrollTop = taskTop - (scrollViewHeight / 2) + (taskHeight / 2); + const targetScrollTop = taskTop - (scrollViewHeight / 2) + (taskHeight / 2); + console.log("Scrolling to:", targetScrollTop, "element offsetTop:", taskTop); + scrollView.scrollTop = targetScrollTop; + console.log("scrollTop after set:", scrollView.scrollTop); + } else { + console.log("Task element not found for id:", taskId); } }