Skip to content

Commit

Permalink
Untracked: Fix bug with deleted tasks (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlang42 authored Feb 12, 2024
1 parent 4004fa0 commit 814f97c
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions app/Prerequisites.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ function processPrerequisiteState(boardId, state) {
// create lookups
var completedByName = {};
var unusedCompletedIdsByName = {};
var deletedTaskIds = [];
var duplicateNames = [];
for (const id in state.taskStateById) {
const taskState = state.taskStateById[id];
Expand Down Expand Up @@ -181,13 +182,16 @@ function processPrerequisiteState(boardId, state) {
}
state.nextDatePrerequisite = !nextDate ? null : formatDateTasks(nextDate);
if (!taskState.due) {
// setTaskDueWithMessage() calls a task read, therefore only call if it might actually be useful
// getTaskOrAddToList() calls a task read, therefore only call if it might actually be useful
if (duplicates.length > 0) {
processed.push(setTaskDueWithMessage(boardId, id, "Prerequisite tasks have duplicate names: " + duplicates.join(", ")));
var task = getTaskOrAddToList(boardId, id, deletedTaskIds);
if (task) processed.push(setTaskDueWithMessage(boardId, id, "Prerequisite tasks have duplicate names: " + duplicates.join(", "), task));
} else if (missing.length > 0) {
processed.push(setTaskDueWithMessage(boardId, id, "Could not find prerequisite tasks: " + missing.join(", ")));
var task = getTaskOrAddToList(boardId, id, deletedTaskIds);
if (task) processed.push(setTaskDueWithMessage(boardId, id, "Could not find prerequisite tasks: " + missing.join(", "), task));
} else if (ready) {
processed.push(setTaskDueWithMessage(boardId, id, "Prerequisite tasks complete: " + taskState.prerequisiteNames.join(", ")));
var task = getTaskOrAddToList(boardId, id, deletedTaskIds);
if (task) processed.push(setTaskDueWithMessage(boardId, id, "Prerequisite tasks complete: " + taskState.prerequisiteNames.join(", "), task));
}
}
}
Expand All @@ -196,11 +200,23 @@ function processPrerequisiteState(boardId, state) {
const id = unusedCompletedIdsByName[name];
delete state.taskStateById[id];
}
// remove deleted tasks
for (const id in deletedTaskIds) {
delete state.taskStateById[id];
}
return processed;
}

const MAX_NOTES_LENGTH = 8000;

function getTaskOrAddToList(boardId, taskId, listOfFailedTaskIds) {
try {
return Tasks.Tasks.get(boardId, taskId);
} catch (err) {
listOfFailedTaskIds.push(taskId);
}
}

function setTaskDueWithMessage(boardId, taskId, message, already_up_to_date_task) {
var t = already_up_to_date_task ?? Tasks.Tasks.get(boardId, taskId);
if (!t.due) {
Expand Down

0 comments on commit 814f97c

Please sign in to comment.