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 @@ -47,6 +47,7 @@ func EditTaskHandler(w http.ResponseWriter, r *http.Request) {
tags := requestBody.Tags
project := requestBody.Project
start := requestBody.Start
entry := requestBody.Entry

if taskID == "" {
http.Error(w, "taskID is required", http.StatusBadRequest)
Expand All @@ -58,7 +59,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)
err := tw.EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID, tags, project, start, entry)
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 @@ -32,6 +32,7 @@ type EditTaskRequestBody struct {
Tags []string `json:"tags"`
Project string `json:"project"`
Start string `json:"start"`
Entry string `json:"entry"`
}
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, start string) error {
func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID string, tags []string, project string, start string, entry 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 @@ -70,6 +70,13 @@ func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID st
}
}

// Handle entry date
if entry != "" {
if err := utils.ExecCommand("task", taskID, "modify", "entry:"+entry); err != nil {
return fmt.Errorf("failed to set entry date %s: %v", entry, 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", "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")
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")
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "+important"}, "project", "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")
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"-work", "-lowpriority"}, "project", "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")
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "-work", "normal"}, "project", "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
132 changes: 127 additions & 5 deletions frontend/src/components/HomeComponents/Tasks/Tasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export const Tasks = (
);
const [isEditingStartDate, setIsEditingStartDate] = useState(false);
const [editedStartDate, setEditedStartDate] = useState('');
const [isEditingEntryDate, setIsEditingEntryDate] = useState(false);
const [editedEntryDate, setEditedEntryDate] = useState('');
const [searchTerm, setSearchTerm] = useState('');
const [lastSyncTime, setLastSyncTime] = useState<number | null>(null);

Expand Down Expand Up @@ -321,7 +323,8 @@ export const Tasks = (
tags: string[],
taskID: string,
project: string,
start: string
start: string,
entry: string
) {
try {
await editTaskOnBackend({
Expand All @@ -334,6 +337,7 @@ export const Tasks = (
backendURL: url.backendURL,
project,
start,
entry,
});

console.log('Task edited successfully!');
Expand Down Expand Up @@ -377,7 +381,8 @@ export const Tasks = (
task.tags,
task.id.toString(),
task.project,
task.start
task.start,
task.entry || ''
);
setIsEditing(false);
};
Expand All @@ -392,7 +397,8 @@ export const Tasks = (
task.tags,
task.id.toString(),
task.project,
task.start
task.start,
task.entry || ''
);
setIsEditingProject(false);
};
Expand All @@ -408,12 +414,31 @@ export const Tasks = (
task.tags,
task.id.toString(),
task.project,
task.start
task.start,
task.entry || ''
);

setIsEditingStartDate(false);
};

const handleEntryDateSaveClick = (task: Task) => {
task.entry = editedEntryDate;

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

setIsEditingEntryDate(false);
};

const handleCancelClick = () => {
setIsEditing(false);
};
Expand All @@ -427,6 +452,10 @@ export const Tasks = (
setEditedTags([]);
setIsEditingPriority(false);
setEditedPriority('NONE');
setIsEditingStartDate(false);
setEditedStartDate('');
setIsEditingEntryDate(false);
setEditedEntryDate('');
} else {
setSelectedTask(task);
setEditedDescription(task?.description || '');
Expand Down Expand Up @@ -499,7 +528,8 @@ export const Tasks = (
finalTags,
task.id.toString(),
task.project,
task.start
task.start,
task.entry || ''
);

setIsEditingTags(false); // Exit editing mode
Expand Down Expand Up @@ -1336,6 +1366,98 @@ export const Tasks = (
)}
</TableCell>
</TableRow>
<TableRow>
<TableCell>Entry:</TableCell>
<TableCell>
{isEditingEntryDate ? (
<div className="flex items-center gap-2">
<DatePicker
date={
editedEntryDate &&
editedEntryDate !== ''
? (() => {
try {
// Handle YYYY-MM-DD format
const dateStr =
editedEntryDate.includes(
'T'
)
? editedEntryDate.split(
'T'
)[0]
: editedEntryDate;
const parsed =
new Date(
dateStr +
'T00:00:00'
);
return isNaN(
parsed.getTime()
)
? undefined
: parsed;
} catch {
return undefined;
}
})()
: undefined
}
onDateChange={(date) =>
setEditedEntryDate(
date
? format(
date,
'yyyy-MM-dd'
)
: ''
)
}
/>

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

<Button
variant="ghost"
size="icon"
onClick={() =>
setIsEditingEntryDate(false)
}
>
<XIcon className="h-4 w-4 text-red-500" />
</Button>
</div>
) : (
<>
<span>
{formattedDate(task.entry)}
</span>
<Button
variant="ghost"
size="icon"
onClick={() => {
setIsEditingEntryDate(true);
const entryDate = task.entry
? task.entry.includes('T')
? task.entry.split('T')[0]
: task.entry
: '';
setEditedEntryDate(entryDate);
}}
>
<PencilIcon className="h-4 w-4 text-gray-500" />
</Button>
</>
)}
</TableCell>
</TableRow>
<TableRow>
<TableCell>Urgency:</TableCell>
<TableCell>{task.urgency}</TableCell>
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 @@ -90,6 +90,7 @@ export const editTaskOnBackend = async ({
backendURL,
project,
start,
entry,
}: {
email: string;
encryptionSecret: string;
Expand All @@ -100,6 +101,7 @@ export const editTaskOnBackend = async ({
backendURL: string;
project: string;
start: string;
entry: string;
}) => {
const response = await fetch(`${backendURL}edit-task`, {
method: 'POST',
Expand All @@ -112,6 +114,7 @@ export const editTaskOnBackend = async ({
tags,
project,
start,
entry,
}),
headers: {
'Content-Type': 'application/json',
Expand Down
Loading