Skip to content

Commit 702f131

Browse files
authored
made the project editable (#174)
1 parent 66b96fd commit 702f131

7 files changed

Lines changed: 96 additions & 11 deletions

File tree

backend/controllers/edit_task.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func EditTaskHandler(w http.ResponseWriter, r *http.Request) {
4545
taskID := requestBody.TaskID
4646
description := requestBody.Description
4747
tags := requestBody.Tags
48+
project := requestBody.Project
4849

4950
if taskID == "" {
5051
http.Error(w, "taskID is required", http.StatusBadRequest)
@@ -61,7 +62,7 @@ func EditTaskHandler(w http.ResponseWriter, r *http.Request) {
6162
Name: "Edit Task",
6263
Execute: func() error {
6364
logStore.AddLog("INFO", fmt.Sprintf("Editing task ID: %s", taskID), uuid, "Edit Task")
64-
err := tw.EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID, tags)
65+
err := tw.EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID, tags, project)
6566
if err != nil {
6667
logStore.AddLog("ERROR", fmt.Sprintf("Failed to edit task ID %s: %v", taskID, err), uuid, "Edit Task")
6768
return err

backend/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.19
55
require (
66
github.com/gorilla/sessions v1.2.2
77
github.com/swaggo/http-swagger v1.3.4
8+
github.com/swaggo/swag v1.16.3
89
golang.org/x/oauth2 v0.20.0
910
)
1011

@@ -20,7 +21,6 @@ require (
2021
github.com/mailru/easyjson v0.7.6 // indirect
2122
github.com/pmezard/go-difflib v1.0.0 // indirect
2223
github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe // indirect
23-
github.com/swaggo/swag v1.16.3 // indirect
2424
golang.org/x/net v0.17.0 // indirect
2525
golang.org/x/sys v0.13.0 // indirect
2626
golang.org/x/tools v0.7.0 // indirect

backend/models/request_body.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type EditTaskRequestBody struct {
3030
TaskID string `json:"taskid"`
3131
Description string `json:"description"`
3232
Tags []string `json:"tags"`
33+
Project string `json:"project"`
3334
}
3435
type CompleteTaskRequestBody struct {
3536
Email string `json:"email"`

backend/utils/tw/edit_task.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"strings"
88
)
99

10-
func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID string, tags []string) error {
10+
func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID string, tags []string, project string) error {
1111
if err := utils.ExecCommand("rm", "-rf", "/root/.task"); err != nil {
1212
return fmt.Errorf("error deleting Taskwarrior data: %v", err)
1313
}
@@ -32,6 +32,13 @@ func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID st
3232
return fmt.Errorf("failed to edit task: %v", err)
3333
}
3434

35+
// Handle project
36+
if project != "" {
37+
if err := utils.ExecCommand("task", taskID, "modify", "project:"+project); err != nil {
38+
return fmt.Errorf("failed to set project %s: %v", project, err)
39+
}
40+
}
41+
3542
// Handle tags
3643
if len(tags) > 0 {
3744
for _, tag := range tags {

backend/utils/tw/taskwarrior_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestSyncTaskwarrior(t *testing.T) {
2323
}
2424

2525
func TestEditTaskInATaskwarrior(t *testing.T) {
26-
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", nil)
26+
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", nil, "project")
2727
if err != nil {
2828
t.Errorf("EditTaskInTaskwarrior() failed: %v", err)
2929
} else {
@@ -68,7 +68,7 @@ func TestAddTaskWithTags(t *testing.T) {
6868
}
6969

7070
func TestEditTaskWithTagAddition(t *testing.T) {
71-
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "+important"})
71+
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "+important"}, "project")
7272
if err != nil {
7373
t.Errorf("EditTaskInTaskwarrior with tag addition failed: %v", err)
7474
} else {
@@ -77,7 +77,7 @@ func TestEditTaskWithTagAddition(t *testing.T) {
7777
}
7878

7979
func TestEditTaskWithTagRemoval(t *testing.T) {
80-
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"-work", "-lowpriority"})
80+
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"-work", "-lowpriority"}, "project")
8181
if err != nil {
8282
t.Errorf("EditTaskInTaskwarrior with tag removal failed: %v", err)
8383
} else {
@@ -86,7 +86,7 @@ func TestEditTaskWithTagRemoval(t *testing.T) {
8686
}
8787

8888
func TestEditTaskWithMixedTagOperations(t *testing.T) {
89-
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "-work", "normal"})
89+
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "-work", "normal"}, "project")
9090
if err != nil {
9191
t.Errorf("EditTaskInTaskwarrior with mixed tag operations failed: %v", err)
9292
} else {

frontend/src/components/HomeComponents/Tasks/Tasks.tsx

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ export const Tasks = (
101101
_selectedTask?.tags || []
102102
);
103103
const [isEditingTags, setIsEditingTags] = useState(false);
104+
const [isEditingProject, setIsEditingProject] = useState(false);
105+
const [editedProject, setEditedProject] = useState(
106+
_selectedTask?.project || ''
107+
);
104108
const [searchTerm, setSearchTerm] = useState('');
105109
const [lastSyncTime, setLastSyncTime] = useState<number | null>(null);
106110

@@ -298,7 +302,8 @@ export const Tasks = (
298302
UUID: string,
299303
description: string,
300304
tags: string[],
301-
taskID: string
305+
taskID: string,
306+
project: string
302307
) {
303308
try {
304309
await editTaskOnBackend({
@@ -309,6 +314,7 @@ export const Tasks = (
309314
tags,
310315
taskID,
311316
backendURL: url.backendURL,
317+
project,
312318
});
313319

314320
console.log('Task edited successfully!');
@@ -350,11 +356,26 @@ export const Tasks = (
350356
props.UUID,
351357
task.description,
352358
task.tags,
353-
task.id.toString()
359+
task.id.toString(),
360+
task.project
354361
);
355362
setIsEditing(false);
356363
};
357364

365+
const handleProjectSaveClick = (task: Task) => {
366+
task.project = editedProject;
367+
handleEditTaskOnBackend(
368+
props.email,
369+
props.encryptionSecret,
370+
props.UUID,
371+
task.description,
372+
task.tags,
373+
task.id.toString(),
374+
task.project
375+
);
376+
setIsEditingProject(false);
377+
};
378+
358379
const handleCancelClick = () => {
359380
setIsEditing(false);
360381
};
@@ -433,7 +454,8 @@ export const Tasks = (
433454
props.UUID,
434455
task.description,
435456
finalTags,
436-
task.id.toString()
457+
task.id.toString(),
458+
task.project
437459
);
438460

439461
setIsEditingTags(false); // Exit editing mode
@@ -942,7 +964,58 @@ export const Tasks = (
942964
</TableRow>
943965
<TableRow>
944966
<TableCell>Project:</TableCell>
945-
<TableCell>{task.project}</TableCell>
967+
<TableCell>
968+
{isEditingProject ? (
969+
<>
970+
<div className="flex items-center">
971+
<Input
972+
id={`project-${task.id}`}
973+
name={`project-${task.id}`}
974+
type="text"
975+
value={editedProject}
976+
onChange={(e) =>
977+
setEditedProject(
978+
e.target.value
979+
)
980+
}
981+
className="flex-grow mr-2"
982+
/>
983+
<Button
984+
variant="ghost"
985+
size="icon"
986+
onClick={() =>
987+
handleProjectSaveClick(task)
988+
}
989+
>
990+
<CheckIcon className="h-4 w-4 text-green-500" />
991+
</Button>
992+
<Button
993+
variant="ghost"
994+
size="icon"
995+
onClick={() =>
996+
setIsEditingProject(false)
997+
}
998+
>
999+
<XIcon className="h-4 w-4 text-red-500" />
1000+
</Button>
1001+
</div>
1002+
</>
1003+
) : (
1004+
<>
1005+
<span>{task.project}</span>
1006+
<Button
1007+
variant="ghost"
1008+
size="icon"
1009+
onClick={() => {
1010+
setIsEditingProject(true);
1011+
setEditedProject(task.project);
1012+
}}
1013+
>
1014+
<PencilIcon className="h-4 w-4 text-gray-500" />
1015+
</Button>
1016+
</>
1017+
)}
1018+
</TableCell>
9461019
</TableRow>
9471020
<TableRow>
9481021
<TableCell>Status:</TableCell>

frontend/src/components/HomeComponents/Tasks/hooks.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export const editTaskOnBackend = async ({
8888
tags,
8989
taskID,
9090
backendURL,
91+
project,
9192
}: {
9293
email: string;
9394
encryptionSecret: string;
@@ -96,6 +97,7 @@ export const editTaskOnBackend = async ({
9697
tags: string[];
9798
taskID: string;
9899
backendURL: string;
100+
project: string;
99101
}) => {
100102
const response = await fetch(`${backendURL}edit-task`, {
101103
method: 'POST',
@@ -106,6 +108,7 @@ export const editTaskOnBackend = async ({
106108
taskID,
107109
description,
108110
tags,
111+
project,
109112
}),
110113
headers: {
111114
'Content-Type': 'application/json',

0 commit comments

Comments
 (0)