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 @@ -52,6 +52,7 @@ func EditTaskHandler(w http.ResponseWriter, r *http.Request) {
end := requestBody.End
depends := requestBody.Depends
due := requestBody.Due
recur := requestBody.Recur

if taskID == "" {
http.Error(w, "taskID is required", http.StatusBadRequest)
Expand All @@ -63,7 +64,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, wait, end, depends, due)
err := tw.EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID, tags, project, start, entry, wait, end, depends, due, recur)
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 @@ -37,6 +37,7 @@ type EditTaskRequestBody struct {
End string `json:"end"`
Depends []string `json:"depends"`
Due string `json:"due"`
Recur string `json:"recur"`
}
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, entry string, wait string, end string, depends []string, due string) error {
func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID string, tags []string, project string, start string, entry string, wait string, end string, depends []string, due string, recur 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 @@ -112,6 +112,13 @@ func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID st
}
}

// Handle recur - this will automatically set rtype field
if recur != "" {
if err := utils.ExecCommand("task", taskID, "modify", "recur:"+recur); err != nil {
return fmt.Errorf("failed to set recur %s: %v", recur, 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", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18: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", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18:30:00.000Z", "weekly")
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", "2025-11-29T18:30:00.000Z", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18: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", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18:30:00.000Z", "daily")
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", "2025-11-29T18:30:00.000Z", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18: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", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18:30:00.000Z", "monthly")
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", "2025-11-29T18:30:00.000Z", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18: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", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18:30:00.000Z", "yearly")
if err != nil {
t.Errorf("EditTaskInTaskwarrior with mixed tag operations failed: %v", err)
} else {
Expand Down
181 changes: 163 additions & 18 deletions frontend/src/components/HomeComponents/Tasks/Tasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ export const Tasks = (
const [editedDepends, setEditedDepends] = useState<string[]>([]);
const [dependsDropdownOpen, setDependsDropdownOpen] = useState(false);
const [dependsSearchTerm, setDependsSearchTerm] = useState('');
const [isEditingRecur, setIsEditingRecur] = useState(false);
const [editedRecur, setEditedRecur] = useState('');
const [originalRecur, setOriginalRecur] = useState('');
const [searchTerm, setSearchTerm] = useState('');
const [debouncedTerm, setDebouncedTerm] = useState('');
const [lastSyncTime, setLastSyncTime] = useState<number | null>(null);
Expand Down Expand Up @@ -379,7 +382,8 @@ export const Tasks = (
wait: string,
end: string,
depends: string[],
due: string
due: string,
recur: string
) {
try {
await editTaskOnBackend({
Expand All @@ -397,6 +401,7 @@ export const Tasks = (
end,
depends,
due,
recur,
});

console.log('Task edited successfully!');
Expand Down Expand Up @@ -444,7 +449,8 @@ export const Tasks = (
task.wait || '',
task.end || '',
task.depends || [],
task.due || ''
task.due || '',
task.recur || ''
);
setIsEditing(false);
};
Expand All @@ -464,7 +470,8 @@ export const Tasks = (
task.wait || '',
task.end || '',
task.depends || [],
task.due || ''
task.due || '',
task.recur || ''
);
setIsEditingProject(false);
};
Expand All @@ -485,7 +492,8 @@ export const Tasks = (
task.wait,
task.end || '',
task.depends || [],
task.due || ''
task.due || '',
task.recur || ''
);

setIsEditingWaitDate(false);
Expand All @@ -507,7 +515,8 @@ export const Tasks = (
task.wait || '',
task.end || '',
task.depends || [],
task.due || ''
task.due || '',
task.recur || ''
);

setIsEditingStartDate(false);
Expand All @@ -529,7 +538,8 @@ export const Tasks = (
task.wait,
task.end,
task.depends || [],
task.due || ''
task.due || '',
task.recur || ''
);

setIsEditingEntryDate(false);
Expand All @@ -551,7 +561,8 @@ export const Tasks = (
task.wait,
task.end,
task.depends || [],
task.due || ''
task.due || '',
task.recur || ''
);

setIsEditingEndDate(false);
Expand All @@ -573,7 +584,8 @@ export const Tasks = (
task.wait,
task.end,
task.depends || [],
task.due
task.due,
task.recur || ''
);

setIsEditingDueDate(false);
Expand All @@ -595,13 +607,47 @@ export const Tasks = (
task.wait || '',
task.end || '',
task.depends,
task.due || ''
task.due || '',
task.recur || ''
);

setIsEditingDepends(false);
setDependsDropdownOpen(false);
};

const handleRecurSaveClick = (task: Task) => {
if (editedRecur === 'none') {
setIsEditingRecur(false);
return;
}

if (!editedRecur || editedRecur === '') {
setIsEditingRecur(false);
return;
}

task.recur = editedRecur;

handleEditTaskOnBackend(
props.email,
props.encryptionSecret,
props.UUID,
task.description,
task.tags,
task.id.toString(),
task.project,
task.start,
task.entry || '',
task.wait || '',
task.end || '',
task.depends || [],
task.due || '',
task.recur
);

setIsEditingRecur(false);
};

const handleAddDependency = (uuid: string) => {
if (!editedDepends.includes(uuid)) {
setEditedDepends([...editedDepends, uuid]);
Expand Down Expand Up @@ -637,6 +683,9 @@ export const Tasks = (
setEditedDepends([]);
setDependsDropdownOpen(false);
setDependsSearchTerm('');
setIsEditingRecur(false);
setEditedRecur('');
setOriginalRecur('');
} else {
setSelectedTask(task);
setEditedDescription(task?.description || '');
Expand Down Expand Up @@ -762,7 +811,8 @@ export const Tasks = (
task.wait || '',
task.end || '',
task.depends || [],
task.due || ''
task.due || '',
task.recur || ''
);

setIsEditingTags(false);
Expand Down Expand Up @@ -1937,14 +1987,6 @@ export const Tasks = (
)}
</TableCell>
</TableRow>
<TableRow>
<TableCell>Recur:</TableCell>
<TableCell>{task.recur}</TableCell>
</TableRow>
<TableRow>
<TableCell>RType:</TableCell>
<TableCell>{task.rtype}</TableCell>
</TableRow>
<TableRow>
<TableCell>Priority:</TableCell>
<TableCell>
Expand Down Expand Up @@ -2285,6 +2327,109 @@ export const Tasks = (
)}
</TableCell>
</TableRow>
<TableRow>
<TableCell>Recur:</TableCell>
<TableCell>
{isEditingRecur ? (
<div className="flex items-center gap-2">
<Select
value={editedRecur || 'none'}
onValueChange={(value) =>
setEditedRecur(value)
}
>
<SelectTrigger className="flex-grow">
<SelectValue placeholder="Select recurrence" />
</SelectTrigger>
<SelectContent>
{!originalRecur && (
<SelectItem
value="none"
className="cursor-pointer hover:bg-accent"
>
None
</SelectItem>
)}
<SelectItem
value="daily"
className="cursor-pointer hover:bg-accent"
>
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.

Shall also have a None field by default, and it should be selectable too... clicking that would remove any recurrence, as in this implementation one can 'SET' recursion but can not remove any (via the UI)

Daily
</SelectItem>
<SelectItem
value="weekly"
className="cursor-pointer hover:bg-accent"
>
Weekly
</SelectItem>
<SelectItem
value="monthly"
className="cursor-pointer hover:bg-accent"
>
Monthly
</SelectItem>
<SelectItem
value="yearly"
className="cursor-pointer hover:bg-accent"
>
Yearly
</SelectItem>
</SelectContent>
</Select>
<Button
variant="ghost"
size="icon"
onClick={() =>
handleRecurSaveClick(task)
}
>
<CheckIcon className="h-4 w-4 text-green-500" />
</Button>
<Button
variant="ghost"
size="icon"
onClick={() =>
setIsEditingRecur(false)
}
>
<XIcon className="h-4 w-4 text-red-500" />
</Button>
</div>
) : (
<div className="flex items-center">
<span>
{task.recur || 'None'}
</span>
<Button
variant="ghost"
size="icon"
onClick={() => {
setIsEditingRecur(true);
setOriginalRecur(
task.recur || ''
);
setEditedRecur(
task.recur || 'none'
);
}}
>
<PencilIcon className="h-4 w-4 text-gray-500" />
</Button>
</div>
)}
</TableCell>
</TableRow>
<TableRow>
<TableCell>RType:</TableCell>
<TableCell>
<span>{task.rtype || 'None'}</span>
{!task.rtype && (
<span className="text-xs text-gray-500 ml-2">
(Auto-set by recur)
</span>
)}
</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 @@ -95,6 +95,7 @@ export const editTaskOnBackend = async ({
end,
depends,
due,
recur,
}: {
email: string;
encryptionSecret: string;
Expand All @@ -110,6 +111,7 @@ export const editTaskOnBackend = async ({
end: string;
depends: string[];
due: string;
recur: string;
}) => {
const response = await fetch(`${backendURL}edit-task`, {
method: 'POST',
Expand All @@ -127,6 +129,7 @@ export const editTaskOnBackend = async ({
end,
depends,
due,
recur,
}),
headers: {
'Content-Type': 'application/json',
Expand Down
Loading