Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions backend/controllers/edit_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions backend/models/request_body.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
9 changes: 8 additions & 1 deletion backend/utils/tw/edit_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shall be reverted. this file is also using ExecCommandsinDir instead of ExecCommands; which is also not really desired so please fix that

Copy link
Copy Markdown
Contributor Author

@Hell1213 Hell1213 Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add back the rm -rf /root/.task lines. For ExecCommandInDir vs ExecCommand - should I use ExecCommand to match main branch, or keep ExecCommandInDir since SetTaskwarriorConfig uses it with tempDir?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say just ExecCommand will work, as it is currently, in main

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I have pushed with accurate changes , it should be fine now !!

return fmt.Errorf("error deleting Taskwarrior data: %v", err)
}
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions backend/utils/tw/taskwarrior_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
125 changes: 117 additions & 8 deletions frontend/src/components/HomeComponents/Tasks/Tasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<number | null>(null);

Expand Down Expand Up @@ -318,7 +320,8 @@ export const Tasks = (
description: string,
tags: string[],
taskID: string,
project: string
project: string,
start: string
) {
try {
await editTaskOnBackend({
Expand All @@ -330,6 +333,7 @@ export const Tasks = (
taskID,
backendURL: url.backendURL,
project,
start,
});

console.log('Task edited successfully!');
Expand Down Expand Up @@ -372,7 +376,8 @@ export const Tasks = (
task.description,
task.tags,
task.id.toString(),
task.project
task.project,
task.start
);
setIsEditing(false);
};
Expand All @@ -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);
};
Expand Down Expand Up @@ -475,17 +498,17 @@ export const Tasks = (
task.description,
finalTags,
task.id.toString(),
task.project
task.project,
task.start
);

setIsEditingTags(false); // Exit editing mode
};

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');
Expand Down Expand Up @@ -522,7 +545,6 @@ export const Tasks = (

const handleCancelPriority = () => {
setIsEditingPriority(false);
// Reset to the task's original priority
if (_selectedTask) {
setEditedPriority(_selectedTask.priority || 'NONE');
}
Expand Down Expand Up @@ -1003,7 +1025,94 @@ export const Tasks = (
<TableRow>
<TableCell>Start:</TableCell>
<TableCell>
{formattedDate(task.start)}
{isEditingStartDate ? (
<div className="flex items-center gap-2">
<DatePicker
date={
editedStartDate &&
editedStartDate !== ''
? (() => {
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'
)
: ''
)
}
/>

<Button
variant="ghost"
size="icon"
onClick={() =>
handleStartDateSaveClick(task)
}
>
<CheckIcon className="h-4 w-4 text-green-500" />
</Button>

<Button
variant="ghost"
size="icon"
onClick={() =>
setIsEditingStartDate(false)
}
>
<XIcon className="h-4 w-4 text-red-500" />
</Button>
</div>
) : (
<>
<span>
{formattedDate(task.start)}
</span>
<Button
variant="ghost"
size="icon"
onClick={() => {
setIsEditingStartDate(true);
// Extract just the date part if it's in ISO format
const startDate = task.start
? task.start.includes('T')
? task.start.split('T')[0]
: task.start
: '';
setEditedStartDate(startDate);
}}
>
<PencilIcon className="h-4 w-4 text-gray-500" />
</Button>
</>
)}
</TableCell>
</TableRow>
<TableRow>
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/HomeComponents/Tasks/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const editTaskOnBackend = async ({
taskID,
backendURL,
project,
start,
}: {
email: string;
encryptionSecret: string;
Expand All @@ -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',
Expand All @@ -109,6 +111,7 @@ export const editTaskOnBackend = async ({
description,
tags,
project,
start,
}),
headers: {
'Content-Type': 'application/json',
Expand Down
Loading