From 12da559905ecb9fd9ddabdb28459ab8eb0054255 Mon Sep 17 00:00:00 2001 From: Rajat yadav Date: Mon, 17 Nov 2025 22:42:56 +0530 Subject: [PATCH] feat: add end date editing to task details Users can now modify task end dates using the date picker --- backend/controllers/edit_task.go | 3 +- backend/models/request_body.go | 1 + backend/utils/tw/edit_task.go | 9 +- backend/utils/tw/taskwarrior_test.go | 8 +- .../components/HomeComponents/Tasks/Tasks.tsx | 128 +++++++++++++++++- .../components/HomeComponents/Tasks/hooks.ts | 3 + 6 files changed, 139 insertions(+), 13 deletions(-) diff --git a/backend/controllers/edit_task.go b/backend/controllers/edit_task.go index 5ca9f181..e994bbaa 100644 --- a/backend/controllers/edit_task.go +++ b/backend/controllers/edit_task.go @@ -48,6 +48,7 @@ func EditTaskHandler(w http.ResponseWriter, r *http.Request) { project := requestBody.Project start := requestBody.Start entry := requestBody.Entry + end := requestBody.End if taskID == "" { http.Error(w, "taskID is required", http.StatusBadRequest) @@ -59,7 +60,7 @@ func EditTaskHandler(w http.ResponseWriter, r *http.Request) { 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, start, entry) + err := tw.EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID, tags, project, start, entry, end) 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 961fd2cf..42c2afc2 100644 --- a/backend/models/request_body.go +++ b/backend/models/request_body.go @@ -33,6 +33,7 @@ type EditTaskRequestBody struct { Project string `json:"project"` Start string `json:"start"` Entry string `json:"entry"` + End string `json:"end"` } type CompleteTaskRequestBody struct { Email string `json:"email"` diff --git a/backend/utils/tw/edit_task.go b/backend/utils/tw/edit_task.go index f77c8b27..14bd70dc 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, start string, entry string) error { +func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID string, tags []string, project string, start string, entry string, end string) error { if err := utils.ExecCommand("rm", "-rf", "/root/.task"); err != nil { return fmt.Errorf("error deleting Taskwarrior data: %v", err) } @@ -77,6 +77,13 @@ func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID st } } + // Handle end date + if end != "" { + if err := utils.ExecCommand("task", taskID, "modify", "end:"+end); err != nil { + return fmt.Errorf("failed to set end date %s: %v", end, 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 02b92485..8bf5012e 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", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z") + err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", nil, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-30T18: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", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z") + err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "+important"}, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-30T18: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", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z") + err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"-work", "-lowpriority"}, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-30T18: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", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z") + err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "-work", "normal"}, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-30T18: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 1a447aad..0c1a251a 100644 --- a/frontend/src/components/HomeComponents/Tasks/Tasks.tsx +++ b/frontend/src/components/HomeComponents/Tasks/Tasks.tsx @@ -122,6 +122,8 @@ export const Tasks = ( const [editedStartDate, setEditedStartDate] = useState(''); const [isEditingEntryDate, setIsEditingEntryDate] = useState(false); const [editedEntryDate, setEditedEntryDate] = useState(''); + const [isEditingEndDate, setIsEditingEndDate] = useState(false); + const [editedEndDate, setEditedEndDate] = useState(''); const [searchTerm, setSearchTerm] = useState(''); const [lastSyncTime, setLastSyncTime] = useState(null); @@ -324,7 +326,8 @@ export const Tasks = ( taskID: string, project: string, start: string, - entry: string + entry: string, + end: string ) { try { await editTaskOnBackend({ @@ -338,6 +341,7 @@ export const Tasks = ( project, start, entry, + end, }); console.log('Task edited successfully!'); @@ -382,7 +386,8 @@ export const Tasks = ( task.id.toString(), task.project, task.start, - task.entry || '' + task.entry || '', + task.end || '' ); setIsEditing(false); }; @@ -398,7 +403,8 @@ export const Tasks = ( task.id.toString(), task.project, task.start, - task.entry || '' + task.entry || '', + task.end || '' ); setIsEditingProject(false); }; @@ -415,7 +421,8 @@ export const Tasks = ( task.id.toString(), task.project, task.start, - task.entry || '' + task.entry || '', + task.end || '' ); setIsEditingStartDate(false); @@ -433,12 +440,32 @@ export const Tasks = ( task.id.toString(), task.project, task.start, - task.entry + task.entry, + task.end ); setIsEditingEntryDate(false); }; + const handleEndDateSaveClick = (task: Task) => { + task.end = editedEndDate; + + handleEditTaskOnBackend( + props.email, + props.encryptionSecret, + props.UUID, + task.description, + task.tags, + task.id.toString(), + task.project, + task.start, + task.entry, + task.end + ); + + setIsEditingEndDate(false); + }; + const handleCancelClick = () => { setIsEditing(false); }; @@ -456,6 +483,8 @@ export const Tasks = ( setEditedStartDate(''); setIsEditingEntryDate(false); setEditedEntryDate(''); + setIsEditingEndDate(false); + setEditedEndDate(''); } else { setSelectedTask(task); setEditedDescription(task?.description || ''); @@ -529,7 +558,8 @@ export const Tasks = ( task.id.toString(), task.project, task.start, - task.entry || '' + task.entry || '', + task.end || '' ); setIsEditingTags(false); // Exit editing mode @@ -1148,7 +1178,91 @@ export const Tasks = ( End: - {formattedDate(task.end)} + {isEditingEndDate ? ( +
+ { + try { + const dateStr = + editedEndDate.includes( + 'T' + ) + ? editedEndDate.split( + 'T' + )[0] + : editedEndDate; + const parsed = + new Date( + dateStr + + 'T00:00:00' + ); + return isNaN( + parsed.getTime() + ) + ? undefined + : parsed; + } catch { + return undefined; + } + })() + : undefined + } + onDateChange={(date) => + setEditedEndDate( + date + ? format( + date, + 'yyyy-MM-dd' + ) + : '' + ) + } + placeholder="Select end date" + /> + + +
+ ) : ( +
+ + {formattedDate(task.end)} + + +
+ )}
diff --git a/frontend/src/components/HomeComponents/Tasks/hooks.ts b/frontend/src/components/HomeComponents/Tasks/hooks.ts index 83be616d..4a6d07c8 100644 --- a/frontend/src/components/HomeComponents/Tasks/hooks.ts +++ b/frontend/src/components/HomeComponents/Tasks/hooks.ts @@ -91,6 +91,7 @@ export const editTaskOnBackend = async ({ project, start, entry, + end, }: { email: string; encryptionSecret: string; @@ -102,6 +103,7 @@ export const editTaskOnBackend = async ({ project: string; start: string; entry: string; + end: string; }) => { const response = await fetch(`${backendURL}edit-task`, { method: 'POST', @@ -115,6 +117,7 @@ export const editTaskOnBackend = async ({ project, start, entry, + end, }), headers: { 'Content-Type': 'application/json',