Skip to content

Commit

Permalink
eagerly create tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
reykjalin committed Jul 20, 2024
1 parent 1a52199 commit 330e6e6
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions resources/js/src/entrypoints/Tasks.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,40 @@
.filter((t) => t)
.map((t) => t.substring(1));
await createTask(taskDescription.substring(0, index), newTags);
$tasks = await getTasks(selectedTag);
const description = taskDescription.substring(0, index);
const task: TaskType = {
id: -1, // ID doesn't exist yet, use -1 for temporary tasks.
description,
tags: newTags.map((t) => ({ id: 0, name: t })),
order: -1, // Order doesn't matter or exist yet.
};
$tasks = [task, ...$tasks];
// FIXME: fix flashing when the full task list is loaded.
try {
await createTask(description, newTags);
$tasks = await getTasks(selectedTag);
} catch (_) {
// Remove all temporary tasks.
$tasks = $tasks.filter((t) => t.id !== -1);
}
} else {
await createTask(taskDescription);
const task: TaskType = {
id: -1, // ID doesn't exist yet, use -1 for temporary tasks.
description: taskDescription,
tags: [],
order: -1, // Order doesn't matter or exist yet.
};
$tasks = [task, ...$tasks];
// FIXME: fix flashing when the full task list is loaded.
try {
await createTask(taskDescription);
} catch (_) {
// Remove all temporary tasks.
$tasks = $tasks.filter((t) => t.id !== -1);
}
}
$tasks = await getTasks(selectedTag);
Expand Down

0 comments on commit 330e6e6

Please sign in to comment.