aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/views/nodes/TaskBox.tsx55
-rw-r--r--src/server/ApiManagers/GeneralGoogleManager.ts44
2 files changed, 65 insertions, 34 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();
diff --git a/src/server/ApiManagers/GeneralGoogleManager.ts b/src/server/ApiManagers/GeneralGoogleManager.ts
index 79ca55444..7a1969bf4 100644
--- a/src/server/ApiManagers/GeneralGoogleManager.ts
+++ b/src/server/ApiManagers/GeneralGoogleManager.ts
@@ -96,7 +96,7 @@ export default class GeneralGoogleManager extends ApiManager {
// Task Update
register({
method: Method.PATCH,
- subscription: new RouteSubscriber('googleTasks').add('taskId'),
+ subscription: new RouteSubscriber('googleTasks').add('taskId'),
// any way to add static params? like /update (this is not very descriptive)
secureHandler: async ({ req, res, user }) => {
try {
@@ -130,30 +130,28 @@ export default class GeneralGoogleManager extends ApiManager {
method: Method.DELETE,
subscription: new RouteSubscriber('googleTasks').add('taskId'),
secureHandler: async ({ req, res, user }) => {
- try {
- const auth = await GoogleApiServerUtils.retrieveOAuthClient(user.id);
-
- if (!auth) {
- return res.status(401).send('Google credentials missing or invalid.');
+ try {
+ const auth = await GoogleApiServerUtils.retrieveOAuthClient(user.id);
+
+ if (!auth) {
+ return res.status(401).send('Google credentials missing or invalid.');
+ }
+
+ const tasks = google.tasks({ version: 'v1', auth });
+ const { taskId } = req.params;
+
+ await tasks.tasks.delete({
+ tasklist: '@default',
+ task: taskId,
+ });
+
+ res.status(200).send({ success: true });
+ } catch (err) {
+ console.error('Google Tasks delete error:', err);
+ res.status(500).send('Failed to delete task.');
}
-
- const tasks = google.tasks({ version: 'v1', auth });
- const { taskId } = req.params;
-
- await tasks.tasks.delete({
- tasklist: '@default',
- task: taskId,
- });
-
- res.status(200).send({ success: true });
- } catch (err) {
- console.error('Google Tasks delete error:', err);
- res.status(500).send('Failed to delete task.');
- }
},
- });
-
-
+ });
register({
method: Method.GET,