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.
This commit is contained in:
Yuyao Huang
2026-05-09 16:37:26 +08:00
parent fcee783ee5
commit 5e827e7d99
+16
View File
@@ -76,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) {