Skip to content

Commit

Permalink
work on confirmation step for marking past-due task incomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Nov 20, 2024
1 parent cd6da93 commit 469cfbe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions knowledge.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Use `pnpm verify` to check that code changes are valid.
- Complete: Can mark incomplete, copy
- Expired: Can copy
- Completing tasks requires careful handling:
- Marking tasks complete is a critical action
- Reversing completed tasks requires support intervention
- Marking past-due tasks incomplete is a critical action
- Reversing incompleted past-due tasks requires support intervention
- UI should prevent accidental completion

## Future Improvements
Expand Down
21 changes: 16 additions & 5 deletions src/components/task.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,34 @@
return date.toLocaleString();
}
async function toggleComplete() {
let isConfirming = false;
async function toggleComplete(event?: Event) {
if (!task.id) return;
const newComplete = event?.target ? (event.target as HTMLInputElement).checked : !task.complete;
const taskDue = new Date(task.due);
const now = new Date();
const isPastDue = taskDue < now;
if (isPastDue && task.complete) {
if (isPastDue && task.complete && !isConfirming) {
// Prevent checkbox from changing
if (event?.target) {
(event.target as HTMLInputElement).checked = true;
}
const confirmed = confirm(
'This task is past due. Marking it incomplete will require contacting support to undo. Continue?',
);
if (!confirmed) return;
isConfirming = true;
}
await updateTask(task.id, { complete: !task.complete });
task.complete = !task.complete;
await updateTask(task.id, { complete: newComplete });
task.complete = newComplete;
task.status = task.complete ? 'complete' : 'pending';
isConfirming = false;
}
</script>

Expand All @@ -62,7 +73,7 @@
type="checkbox"
checked={task.complete}
disabled={!task.id || task.status === 'expired'}
on:change={toggleComplete}
on:change={(e) => toggleComplete(e)}
/>
<div class="task-content">
<div class="task-text">{task.task}</div>
Expand Down

0 comments on commit 469cfbe

Please sign in to comment.