Compare commits

...

2 Commits

Author SHA1 Message Date
Yuyao Huang
5e827e7d99 fix: refresh side panel after loadTasks in non-landscape mode
After saveTask or setTaskStatus triggers loadTasks(), the side panel
now refreshes from the updated server data. If the selected task no
longer exists (deleted or goal changed), the side panel closes.
This ensures Edit Task always matches selectedTaskId.
2026-05-09 16:37:26 +08:00
Yuyao Huang
fcee783ee5 feat: clicking a task now scrolls to and highlights it
selectTask() now also sets in-focus class and calls scrollToTask(),
making click behavior consistent with scroll-to-focus behavior.
Removed selectedTaskId assignment in loadTasks since selectTask
already sets it.
2026-05-09 16:34:04 +08:00

View File

@ -52,7 +52,6 @@ async function loadTasks() {
if (savedTaskExists) {
focusTaskId = savedTaskId;
scrollToTask(savedTaskId);
selectedTaskId = savedTaskId;
if (isLandscapeMode()) {
selectTask(savedTaskId);
}
@ -69,8 +68,6 @@ async function loadTasks() {
}
}
// Wait one frame so the async scroll event from scrollToTask fires first,
// then set in-focus and bind handlers after it has been consumed.
requestAnimationFrame(() => {
if (focusTaskId) {
document.querySelectorAll(".task-item.in-focus").forEach(el => el.classList.remove("in-focus"));
@ -79,6 +76,22 @@ async function loadTasks() {
focusEl.classList.add("in-focus");
}
}
// Refresh side panel if a task was selected
if (selectedTaskId) {
const currentTask = tasks.find(t => t.id === selectedTaskId);
if (currentTask) {
document.getElementById("edit-task-title").value = currentTask.title;
document.getElementById("edit-task-desc").value = currentTask.desc || "";
document.querySelectorAll(".status-btn").forEach(btn => {
btn.classList.toggle("active", btn.dataset.status === currentTask.status);
});
updateSaveButton();
} else {
closeSidePanel();
}
}
initScrollFocus();
});
} catch (error) {
@ -232,6 +245,14 @@ function selectTask(taskId) {
if (!task) return;
document.querySelectorAll(".task-item.in-focus").forEach(el => el.classList.remove("in-focus"));
const taskEl = document.querySelector(`[data-task-id="${taskId}"]`);
if (taskEl) {
taskEl.classList.add("in-focus");
}
scrollToTask(taskId);
document.getElementById("edit-task-title").value = task.title;
document.getElementById("edit-task-desc").value = task.desc || "";
document.getElementById("side-panel-error").textContent = "";