commit f54025627491543f5d6ba2138f3d8e45a173a96c
parent 9a5d6e972d2d5fa79226bfa6e2b5c29a4fc70fc3
Author: Hunter
Date:   Mon,  5 Aug 2024 19:16:23 -0400

checking indeterminate child leaves parent checked

Diffstat:
Mindex.html | 37+++++++++++++++++++------------------
1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/index.html b/index.html @@ -413,7 +413,7 @@ function toggleTaskState(task) { if (task.state === 1) { - // Only allow unchecking if not all direct children are checked + // if all direct children are checked, disallow unchecking if (task.subtasks.length === 0 || !task.subtasks.every(t => t.state === 1)) { task.state = 0; updateSubtasksState(task, 0); @@ -448,9 +448,10 @@ if (task.subtasks.length === 0) { return task.state; // If no subtasks, keep current state } - const allChecked = task.subtasks.every(t => t.state === 1); const anyUnchecked = task.subtasks.some(t => t.state === 0); - if (allChecked) { + const allCheckedOrIndeterminate = task.subtasks.every(t => t.state === 1 || t.state === 2); + + if (allCheckedOrIndeterminate) { return 1; // Checked } else if (anyUnchecked) { return 0; // Unchecked @@ -475,6 +476,21 @@ } } + function updateSubtasksState(task, state) { + task.subtasks.forEach(subtask => { + if (subtask.state !== 1) { // Only update if the subtask is not checked + if (state === 1) { + subtask.state = subtask.state === 0 ? 2 : subtask.state; + } else if (state === 0) { + subtask.state = 0; + } + if (subtask.subtasks.length > 0) { + updateSubtasksState(subtask, state); + } + } + }); + } + function deleteSubtask(subtask) { const parentTask = taskPath[taskPath.length - 1]; const index = parentTask.subtasks.findIndex(t => t.id === subtask.id); @@ -503,21 +519,6 @@ scheduleSave(); } - function updateSubtasksState(task, state) { - task.subtasks.forEach(subtask => { - if (subtask.state !== 1) { // Only update if the subtask is not checked - if (state === 1) { - subtask.state = subtask.state === 0 ? 2 : subtask.state; - } else if (state === 0) { - subtask.state = 0; - } - if (subtask.subtasks.length > 0) { - updateSubtasksState(subtask, state); - } - } - }); - } - function findParentTask(task) { for (let i = taskPath.length - 1; i >= 0; i--) { const potentialParent = taskPath[i];