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.tsx55
1 files changed, 44 insertions, 11 deletions
diff --git a/src/client/views/nodes/TaskBox.tsx b/src/client/views/nodes/TaskBox.tsx
index 168e1455e..37f6124a1 100644
--- a/src/client/views/nodes/TaskBox.tsx
+++ b/src/client/views/nodes/TaskBox.tsx
@@ -23,6 +23,7 @@ export class TaskBox extends ViewBoxBaseComponent<FieldViewProps>() {
public static LayoutString(fieldStr: string) {
return FieldView.LayoutString(TaskBox, fieldStr);
}
+
// contains the last synced task information
private _lastSyncedTask: {
title: string;
@@ -36,8 +37,23 @@ export class TaskBox extends ViewBoxBaseComponent<FieldViewProps>() {
completed: false,
};
+ // Whether the task needs to be synced with Google Tasks
@observable _needsSync = false;
+ // Getter for needsSync
+ get needsSync() {
+ return this._needsSync;
+ }
+
+ /**
+ * Constructor for the task box
+ * @param props - props containing the document reference
+ */
+ constructor(props: FieldViewProps) {
+ super(props);
+ makeObservable(this);
+ }
+
/**
* Method to update the task description
* @param e - event of changing the description box input
@@ -155,16 +171,6 @@ export class TaskBox extends ViewBoxBaseComponent<FieldViewProps>() {
this.Document.$task_completed = e.target.checked;
};
- /**
- * Constructor for the task box
- * @param props - props containing the document reference
- */
-
- constructor(props: TaskBoxProps) {
- super(props);
- makeObservable(this);
- }
-
_googleTaskCreateDisposer?: IReactionDisposer;
_heightDisposer?: IReactionDisposer;
_widthDisposer?: IReactionDisposer;
@@ -241,6 +247,33 @@ export class TaskBox extends ViewBoxBaseComponent<FieldViewProps>() {
}
);
+ runInAction(() => {
+ const completed = BoolCast(doc.$task_completed);
+ const $task_allDay = BoolCast(doc.$task_allDay);
+ const endTime = DateCast(doc.$task_endTime);
+ const startTime = DateCast(doc.$task_startTime);
+ const datePart = StrCast(doc.$task_dateRange)?.split('|')[0];
+
+ const due = (() => {
+ if ($task_allDay && datePart && !isNaN(new Date(datePart).getTime())) {
+ return new Date(datePart).toISOString();
+ } else if (endTime && !isNaN(+endTime.date)) {
+ return endTime.date.toISOString();
+ } else if (startTime && !isNaN(+startTime.date)) {
+ return startTime.date.toISOString();
+ }
+ return undefined;
+ })();
+
+ this._lastSyncedTask = {
+ title: StrCast(doc.title),
+ text: StrCast(doc[this.fieldKey]),
+ due,
+ completed,
+ };
+ this._needsSync = false;
+ });
+
this._googleTaskCreateDisposer = reaction(
() => {
const completed = BoolCast(doc.$task_completed);
@@ -442,7 +475,7 @@ export class TaskBox extends ViewBoxBaseComponent<FieldViewProps>() {
<button
className="task-manager-google"
- disabled={!this._needsSync}
+ disabled={!this.needsSync}
onClick={event => {
event.preventDefault();
handleGoogleTaskSync();