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
3 changes: 2 additions & 1 deletion backend/controllers/edit_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func EditTaskHandler(w http.ResponseWriter, r *http.Request) {
project := requestBody.Project
start := requestBody.Start
entry := requestBody.Entry
wait := requestBody.Wait

if taskID == "" {
http.Error(w, "taskID is required", http.StatusBadRequest)
Expand All @@ -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, wait)
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 @@ -33,6 +33,7 @@ type EditTaskRequestBody struct {
Project string `json:"project"`
Start string `json:"start"`
Entry string `json:"entry"`
Wait string `json:"wait"`
}
type CompleteTaskRequestBody struct {
Email string `json:"email"`
Expand Down
12 changes: 11 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, start string, entry string) error {
func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID string, tags []string, project string, start string, entry string, wait string) error {
if err := utils.ExecCommand("rm", "-rf", "/root/.task"); err != nil {
return fmt.Errorf("error deleting Taskwarrior data: %v", err)
}
Expand Down Expand Up @@ -39,6 +39,16 @@ func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID st
}
}

// Handle wait date
if wait != "" {
// Convert `2025-11-29` -> `2025-11-29T00:00:00`
formattedWait := wait + "T00:00:00"

if err := utils.ExecCommand("task", taskID, "modify", "wait:"+formattedWait); err != nil {
return fmt.Errorf("failed to set wait date %s: %v", formattedWait, err)
}
}

// Handle tags
if len(tags) > 0 {
for _, tag := range tags {
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", "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-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", "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-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", "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-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", "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-29T18:30:00.000Z")
if err != nil {
t.Errorf("EditTaskInTaskwarrior with mixed tag operations failed: %v", err)
} else {
Expand Down
100 changes: 93 additions & 7 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 [isEditingWaitDate, setIsEditingWaitDate] = useState(false);
const [editedWaitDate, setEditedWaitDate] = useState('');
const [isEditingStartDate, setIsEditingStartDate] = useState(false);
const [editedStartDate, setEditedStartDate] = useState('');
const [isEditingEntryDate, setIsEditingEntryDate] = useState(false);
Expand Down Expand Up @@ -324,7 +326,8 @@ export const Tasks = (
taskID: string,
project: string,
start: string,
entry: string
entry: string,
wait: string
) {
try {
await editTaskOnBackend({
Expand All @@ -338,6 +341,7 @@ export const Tasks = (
project,
start,
entry,
wait,
});

console.log('Task edited successfully!');
Expand Down Expand Up @@ -382,7 +386,8 @@ export const Tasks = (
task.id.toString(),
task.project,
task.start,
task.entry || ''
task.entry || '',
task.wait
);
setIsEditing(false);
};
Expand All @@ -398,11 +403,31 @@ export const Tasks = (
task.id.toString(),
task.project,
task.start,
task.entry || ''
task.entry || '',
task.wait
);
setIsEditingProject(false);
};

const handleWaitDateSaveClick = (task: Task) => {
task.wait = editedWaitDate;

handleEditTaskOnBackend(
props.email,
props.encryptionSecret,
props.UUID,
task.description,
task.tags,
task.id.toString(),
task.project,
task.start,
task.entry || '',
task.wait
);

setIsEditingWaitDate(false);
};

const handleStartDateSaveClick = (task: Task) => {
task.start = editedStartDate;

Expand All @@ -415,7 +440,8 @@ export const Tasks = (
task.id.toString(),
task.project,
task.start,
task.entry || ''
task.entry || '',
task.wait
);

setIsEditingStartDate(false);
Expand All @@ -433,7 +459,8 @@ export const Tasks = (
task.id.toString(),
task.project,
task.start,
task.entry
task.entry,
task.wait
);

setIsEditingEntryDate(false);
Expand Down Expand Up @@ -529,7 +556,8 @@ export const Tasks = (
task.id.toString(),
task.project,
task.start,
task.entry || ''
task.entry || '',
task.wait
);

setIsEditingTags(false); // Exit editing mode
Expand Down Expand Up @@ -1154,7 +1182,65 @@ export const Tasks = (
<TableRow>
<TableCell>Wait:</TableCell>
<TableCell>
{formattedDate(task.wait)}
{isEditingWaitDate ? (
<div className="flex items-center gap-2">
<DatePicker
date={
editedWaitDate
? new Date(editedWaitDate)
: undefined
}
onDateChange={(date) =>
setEditedWaitDate(
date
? format(
date,
'yyyy-MM-dd'
)
: ''
)
}
/>

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

<Button
variant="ghost"
size="icon"
onClick={() =>
setIsEditingWaitDate(false)
}
>
<XIcon className="h-4 w-4 text-red-500" />
</Button>
</div>
) : (
<>
<span>
{formattedDate(task.wait)}
</span>
<Button
variant="ghost"
size="icon"
onClick={() => {
setIsEditingWaitDate(true);
setEditedWaitDate(
task?.wait ?? ''
);
}}
>
<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 @@ -91,6 +91,7 @@ export const editTaskOnBackend = async ({
project,
start,
entry,
wait,
}: {
email: string;
encryptionSecret: string;
Expand All @@ -102,6 +103,7 @@ export const editTaskOnBackend = async ({
project: string;
start: string;
entry: string;
wait: string;
}) => {
const response = await fetch(`${backendURL}edit-task`, {
method: 'POST',
Expand All @@ -115,6 +117,7 @@ export const editTaskOnBackend = async ({
project,
start,
entry,
wait,
}),
headers: {
'Content-Type': 'application/json',
Expand Down
Loading