diff --git a/backend/controllers/edit_task.go b/backend/controllers/edit_task.go index 6402bbe2..30cdb266 100644 --- a/backend/controllers/edit_task.go +++ b/backend/controllers/edit_task.go @@ -46,23 +46,19 @@ func EditTaskHandler(w http.ResponseWriter, r *http.Request) { description := requestBody.Description tags := requestBody.Tags project := requestBody.Project + start := requestBody.Start if taskID == "" { http.Error(w, "taskID is required", http.StatusBadRequest) return } - // if err := tw.EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID); err != nil { - // http.Error(w, err.Error(), http.StatusInternalServerError) - // return - // } - logStore := models.GetLogStore() job := Job{ Name: "Edit Task", Execute: func() error { logStore.AddLog("INFO", fmt.Sprintf("Editing task ID: %s", taskID), uuid, "Edit Task") - err := tw.EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID, tags, project) + err := tw.EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID, tags, project, start) if err != nil { logStore.AddLog("ERROR", fmt.Sprintf("Failed to edit task ID %s: %v", taskID, err), uuid, "Edit Task") return err diff --git a/backend/models/request_body.go b/backend/models/request_body.go index 725a6075..e2d87a0c 100644 --- a/backend/models/request_body.go +++ b/backend/models/request_body.go @@ -31,6 +31,7 @@ type EditTaskRequestBody struct { Description string `json:"description"` Tags []string `json:"tags"` Project string `json:"project"` + Start string `json:"start"` } type CompleteTaskRequestBody struct { Email string `json:"email"` diff --git a/backend/utils/tw/edit_task.go b/backend/utils/tw/edit_task.go index a9b8faf4..4d467e88 100644 --- a/backend/utils/tw/edit_task.go +++ b/backend/utils/tw/edit_task.go @@ -7,7 +7,7 @@ import ( "strings" ) -func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID string, tags []string, project string) error { +func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID string, tags []string, project string, start string) error { if err := utils.ExecCommand("rm", "-rf", "/root/.task"); err != nil { return fmt.Errorf("error deleting Taskwarrior data: %v", err) } @@ -63,6 +63,13 @@ func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID st } } + // Handle start date + if start != "" { + if err := utils.ExecCommand("task", taskID, "modify", "start:"+start); err != nil { + return fmt.Errorf("failed to set start date %s: %v", start, err) + } + } + // Sync Taskwarrior again if err := SyncTaskwarrior(tempDir); err != nil { return err diff --git a/backend/utils/tw/taskwarrior_test.go b/backend/utils/tw/taskwarrior_test.go index 04ab28ad..e858f9cf 100644 --- a/backend/utils/tw/taskwarrior_test.go +++ b/backend/utils/tw/taskwarrior_test.go @@ -23,7 +23,7 @@ func TestSyncTaskwarrior(t *testing.T) { } func TestEditTaskInATaskwarrior(t *testing.T) { - err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", nil, "project") + err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", nil, "project", "2025-11-29T18:30:00.000Z") if err != nil { t.Errorf("EditTaskInTaskwarrior() failed: %v", err) } else { @@ -68,7 +68,7 @@ func TestAddTaskWithTags(t *testing.T) { } func TestEditTaskWithTagAddition(t *testing.T) { - err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "+important"}, "project") + err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "+important"}, "project", "2025-11-29T18:30:00.000Z") if err != nil { t.Errorf("EditTaskInTaskwarrior with tag addition failed: %v", err) } else { @@ -77,7 +77,7 @@ func TestEditTaskWithTagAddition(t *testing.T) { } func TestEditTaskWithTagRemoval(t *testing.T) { - err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"-work", "-lowpriority"}, "project") + err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"-work", "-lowpriority"}, "project", "2025-11-29T18:30:00.000Z") if err != nil { t.Errorf("EditTaskInTaskwarrior with tag removal failed: %v", err) } else { @@ -86,7 +86,7 @@ func TestEditTaskWithTagRemoval(t *testing.T) { } func TestEditTaskWithMixedTagOperations(t *testing.T) { - err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "-work", "normal"}, "project") + err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "-work", "normal"}, "project", "2025-11-29T18:30:00.000Z") if err != nil { t.Errorf("EditTaskInTaskwarrior with mixed tag operations failed: %v", err) } else { diff --git a/frontend/src/components/HomeComponents/Tasks/Tasks.tsx b/frontend/src/components/HomeComponents/Tasks/Tasks.tsx index 140288db..737d6fc0 100644 --- a/frontend/src/components/HomeComponents/Tasks/Tasks.tsx +++ b/frontend/src/components/HomeComponents/Tasks/Tasks.tsx @@ -118,6 +118,8 @@ export const Tasks = ( const [editedProject, setEditedProject] = useState( _selectedTask?.project || '' ); + const [isEditingStartDate, setIsEditingStartDate] = useState(false); + const [editedStartDate, setEditedStartDate] = useState(''); const [searchTerm, setSearchTerm] = useState(''); const [lastSyncTime, setLastSyncTime] = useState(null); @@ -318,7 +320,8 @@ export const Tasks = ( description: string, tags: string[], taskID: string, - project: string + project: string, + start: string ) { try { await editTaskOnBackend({ @@ -330,6 +333,7 @@ export const Tasks = ( taskID, backendURL: url.backendURL, project, + start, }); console.log('Task edited successfully!'); @@ -372,7 +376,8 @@ export const Tasks = ( task.description, task.tags, task.id.toString(), - task.project + task.project, + task.start ); setIsEditing(false); }; @@ -386,11 +391,29 @@ export const Tasks = ( task.description, task.tags, task.id.toString(), - task.project + task.project, + task.start ); setIsEditingProject(false); }; + const handleStartDateSaveClick = (task: Task) => { + task.start = editedStartDate; + + handleEditTaskOnBackend( + props.email, + props.encryptionSecret, + props.UUID, + task.description, + task.tags, + task.id.toString(), + task.project, + task.start + ); + + setIsEditingStartDate(false); + }; + const handleCancelClick = () => { setIsEditing(false); }; @@ -475,7 +498,8 @@ export const Tasks = ( task.description, finalTags, task.id.toString(), - task.project + task.project, + task.start ); setIsEditingTags(false); // Exit editing mode @@ -483,9 +507,8 @@ export const Tasks = ( const handleCancelTags = () => { setIsEditingTags(false); - setEditedTags([]); // Reset tags + setEditedTags([]); }; - const handleEditPriorityClick = (task: Task) => { // Convert empty priority to "NONE" for the select component setEditedPriority(task.priority || 'NONE'); @@ -522,7 +545,6 @@ export const Tasks = ( const handleCancelPriority = () => { setIsEditingPriority(false); - // Reset to the task's original priority if (_selectedTask) { setEditedPriority(_selectedTask.priority || 'NONE'); } @@ -1003,7 +1025,94 @@ export const Tasks = ( Start: - {formattedDate(task.start)} + {isEditingStartDate ? ( +
+ { + try { + // Handle YYYY-MM-DD format + const dateStr = + editedStartDate.includes( + 'T' + ) + ? editedStartDate.split( + 'T' + )[0] + : editedStartDate; + const parsed = + new Date( + dateStr + + 'T00:00:00' + ); + return isNaN( + parsed.getTime() + ) + ? undefined + : parsed; + } catch { + return undefined; + } + })() + : undefined + } + onDateChange={(date) => + setEditedStartDate( + date + ? format( + date, + 'yyyy-MM-dd' + ) + : '' + ) + } + /> + + + + +
+ ) : ( + <> + + {formattedDate(task.start)} + + + + )}
diff --git a/frontend/src/components/HomeComponents/Tasks/hooks.ts b/frontend/src/components/HomeComponents/Tasks/hooks.ts index e5299932..f905fdbb 100644 --- a/frontend/src/components/HomeComponents/Tasks/hooks.ts +++ b/frontend/src/components/HomeComponents/Tasks/hooks.ts @@ -89,6 +89,7 @@ export const editTaskOnBackend = async ({ taskID, backendURL, project, + start, }: { email: string; encryptionSecret: string; @@ -98,6 +99,7 @@ export const editTaskOnBackend = async ({ taskID: string; backendURL: string; project: string; + start: string; }) => { const response = await fetch(`${backendURL}edit-task`, { method: 'POST', @@ -109,6 +111,7 @@ export const editTaskOnBackend = async ({ description, tags, project, + start, }), headers: { 'Content-Type': 'application/json',