-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use toggleComplete from TaskCheckbox.ts
- Loading branch information
Showing
2 changed files
with
6 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,19 @@ | ||
<script lang="ts"> | ||
import { updateTask } from '@taskratchet/sdk'; | ||
import { toggleComplete } from './TaskCheckbox'; | ||
export let task: TaskType; | ||
export let disabled = false; | ||
let isConfirming = false; | ||
async function toggleComplete(event: Event) { | ||
if (!task.id) return; | ||
const checkbox = event.target as HTMLInputElement; | ||
const taskDue = new Date(task.due); | ||
const now = new Date(); | ||
const isPastDue = taskDue < now; | ||
if (isPastDue && task.complete && !isConfirming) { | ||
checkbox.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; | ||
task.status = task.complete ? 'complete' : 'pending'; | ||
isConfirming = false; | ||
async function handleChange(event: Event) { | ||
await toggleComplete({ event, task, isConfirming }); | ||
} | ||
</script> | ||
|
||
<input | ||
type="checkbox" | ||
checked={task.complete} | ||
{disabled} | ||
on:change={toggleComplete} | ||
on:change={handleChange} | ||
/> |