checking indeterminate child leaves parent checked

Hunter
Monday, August 5th, 2024 at 7:16 PM

index.html+19-18

index.html
413  
414  			function toggleTaskState(task) {
415  			if (task.state === 1) {
    -				// Only allow unchecking if not all direct children are checked
416 +				// if all direct children are checked, disallow unchecking
417  				if (task.subtasks.length === 0 || !task.subtasks.every(t => t.state === 1)) {
418  					task.state = 0;
419  					updateSubtasksState(task, 0);

448  				if (task.subtasks.length === 0) {
449  					return task.state; // If no subtasks, keep current state
450  				}
    -				const allChecked = task.subtasks.every(t => t.state === 1);
451  				const anyUnchecked = task.subtasks.some(t => t.state === 0);
    -				if (allChecked) {
452 +				const allCheckedOrIndeterminate = task.subtasks.every(t => t.state === 1 || t.state === 2);
453 +				
454 +				if (allCheckedOrIndeterminate) {
455  					return 1; // Checked
456  				} else if (anyUnchecked) {
457  					return 0; // Unchecked

476  				}
477  			}
478  
479 +			function updateSubtasksState(task, state) {
480 +				task.subtasks.forEach(subtask => {
481 +					if (subtask.state !== 1) {  // Only update if the subtask is not checked
482 +						if (state === 1) {
483 +							subtask.state = subtask.state === 0 ? 2 : subtask.state;
484 +						} else if (state === 0) {
485 +							subtask.state = 0;
486 +						}
487 +						if (subtask.subtasks.length > 0) {
488 +							updateSubtasksState(subtask, state);
489 +						}
490 +					}
491 +				});
492 +			}
493 +
494  			function deleteSubtask(subtask) {
495  				const parentTask = taskPath[taskPath.length - 1];
496  				const index = parentTask.subtasks.findIndex(t => t.id === subtask.id);

519  				scheduleSave();
520  			}
521  
    -			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);
    -						}
    -					}
    -				});
    -			}
    -
522  			function findParentTask(task) {
523  				for (let i = taskPath.length - 1; i >= 0; i--) {
524  					const potentialParent = taskPath[i];