aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/TaskBox.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/TaskBox.tsx')
-rw-r--r--src/client/views/nodes/TaskBox.tsx52
1 files changed, 39 insertions, 13 deletions
diff --git a/src/client/views/nodes/TaskBox.tsx b/src/client/views/nodes/TaskBox.tsx
index 5a54e8049..f415f8b52 100644
--- a/src/client/views/nodes/TaskBox.tsx
+++ b/src/client/views/nodes/TaskBox.tsx
@@ -31,11 +31,13 @@ export class TaskBox extends ViewBoxBaseComponent<FieldViewProps>() {
text: string;
due?: string;
completed: boolean;
+ deleted?: boolean;
} = {
title: '',
text: '',
due: '',
completed: false,
+ deleted: false,
};
/**
@@ -215,20 +217,28 @@ export class TaskBox extends ViewBoxBaseComponent<FieldViewProps>() {
* @returns - an object containing the task details
*/
- private buildGoogleTaskBody(): Record<string, string | undefined> {
+ private buildGoogleTaskBody(): Record<string, string | boolean | undefined> {
const doc = this.Document;
const title = StrCast(doc.title, 'Untitled Task');
const notes = StrCast(doc[this.fieldKey]);
const due = this.computeDueDate();
const completed = !!doc.$task_completed;
- return {
+ const body: Record<string, string | boolean | undefined> = {
title,
notes,
due,
status: completed ? 'completed' : 'needsAction',
completed: completed ? new Date().toISOString() : undefined,
};
+
+ if (doc.$dashDeleted === true) {
+ body.deleted = true;
+ } else if (doc.$dashDeleted === false) {
+ body.deleted = false;
+ }
+
+ return body;
}
/**
@@ -307,7 +317,11 @@ export class TaskBox extends ViewBoxBaseComponent<FieldViewProps>() {
const dashUpdated = new Date(StrCast(doc.$task_lastSyncedAt));
const dashChanged =
- StrCast(doc.title) !== this._lastSyncedTask.title || StrCast(doc[this.fieldKey]) !== this._lastSyncedTask.text || this.computeDueDate() !== this._lastSyncedTask.due || !!doc.$task_completed !== this._lastSyncedTask.completed;
+ StrCast(doc.title) !== this._lastSyncedTask.title ||
+ StrCast(doc[this.fieldKey]) !== this._lastSyncedTask.text ||
+ this.computeDueDate() !== this._lastSyncedTask.due ||
+ !!doc.$task_completed !== this._lastSyncedTask.completed ||
+ !!doc.$dashDeleted !== this._lastSyncedTask.deleted;
if (googleUpdated > dashUpdated && !dashChanged) {
// Google version is newer — update Dash
@@ -328,6 +342,7 @@ export class TaskBox extends ViewBoxBaseComponent<FieldViewProps>() {
text: StrCast(doc[this.fieldKey]),
due: this.computeDueDate(),
completed: !!doc.$task_completed,
+ deleted: !!doc.$dashDeleted,
};
this._needsSync = false;
});
@@ -358,6 +373,7 @@ export class TaskBox extends ViewBoxBaseComponent<FieldViewProps>() {
text: StrCast(doc[this.fieldKey]),
due: this.computeDueDate(),
completed: !!doc.$task_completed,
+ deleted: !!doc.$dashDeleted,
};
this._needsSync = false;
console.log('Pushed newer version to Google');
@@ -446,23 +462,27 @@ export class TaskBox extends ViewBoxBaseComponent<FieldViewProps>() {
text: StrCast(doc[this.fieldKey]),
due,
completed,
+ deleted: !!doc.$dashDeleted,
};
this._needsSync = false;
});
+ if (this.Document.$dashDeleted) {
+ runInAction(() => {
+ this.Document.$dashDeleted = false;
+ });
+ }
+
this._googleTaskCreateDisposer = reaction(
() => {
const completed = BoolCast(doc.$task_completed);
const due = this.computeDueDate();
+ const dashDeleted = !!doc.$dashDeleted;
- return { title: StrCast(doc.title), text: StrCast(doc[this.fieldKey]), completed, due };
+ return { title: StrCast(doc.title), text: StrCast(doc[this.fieldKey]), completed, due, dashDeleted };
},
- ({ title, text, completed, due }) => {
- this._needsSync =
- title !== this._lastSyncedTask.title || //
- text !== this._lastSyncedTask.text ||
- due !== this._lastSyncedTask.due ||
- completed !== this._lastSyncedTask.completed;
+ ({ title, text, completed, due, dashDeleted }) => {
+ this._needsSync = title !== this._lastSyncedTask.title || text !== this._lastSyncedTask.text || due !== this._lastSyncedTask.due || completed !== this._lastSyncedTask.completed || dashDeleted !== this._lastSyncedTask.deleted;
},
{ fireImmediately: true }
);
@@ -478,10 +498,18 @@ export class TaskBox extends ViewBoxBaseComponent<FieldViewProps>() {
this._widthDisposer?.();
}
+
+ /**
+ * Method to handle task deletion
+ * @returns - a promise that resolves when the task is deleted
+ */
handleDeleteTask = async () => {
const doc = this.Document;
if (!doc.$googleTaskId) return;
- if (!window.confirm('Are you sure you want to permanently delete this task? This action is undoable.')) return;
+ if (!window.confirm('Are you sure you want to delete this task?')) return;
+
+ doc.$dashDeleted = true;
+ this._needsSync = true;
try {
const token = await GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken();
@@ -602,8 +630,6 @@ export class TaskBox extends ViewBoxBaseComponent<FieldViewProps>() {
<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="12" height="12" viewBox="0 0 24 24" style={{ fill: 'white', marginRight: '6px', verticalAlign: 'middle', marginTop: '-2px' }}>
<path d="M 10 2 L 9 3 L 5 3 C 4.4 3 4 3.4 4 4 C 4 4.6 4.4 5 5 5 L 7 5 L 17 5 L 19 5 C 19.6 5 20 4.6 20 4 C 20 3.4 19.6 3 19 3 L 15 3 L 14 2 L 10 2 z M 5 7 L 5 20 C 5 21.1 5.9 22 7 22 L 17 22 C 18.1 22 19 21.1 19 20 L 19 7 L 5 7 z M 9 9 C 9.6 9 10 9.4 10 10 L 10 19 C 10 19.6 9.6 20 9 20 C 8.4 20 8 19.6 8 19 L 8 10 C 8 9.4 8.4 9 9 9 z M 15 9 C 15.6 9 16 9.4 16 10 L 16 19 C 16 19.6 15.6 20 15 20 C 14.4 20 14 19.6 14 19 L 14 10 C 14 9.4 14.4 9 15 9 z"></path>
</svg>
-
-
Delete
</button>
</div>