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
125 changes: 124 additions & 1 deletion frontend/src/components/HomeComponents/Tasks/Tasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ import {
} from 'lucide-react';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import CopyToClipboard from 'react-copy-to-clipboard';
import {
formattedDate,
Expand All @@ -56,6 +63,7 @@ import BottomBar from '../BottomBar/BottomBar';
import {
addTaskToBackend,
editTaskOnBackend,
modifyTaskOnBackend,
fetchTaskwarriorTasks,
TasksDatabase,
} from './hooks';
Expand Down Expand Up @@ -101,6 +109,8 @@ export const Tasks = (
_selectedTask?.tags || []
);
const [isEditingTags, setIsEditingTags] = useState(false);
const [isEditingPriority, setIsEditingPriority] = useState(false);
const [editedPriority, setEditedPriority] = useState('NONE');
const [isEditingProject, setIsEditingProject] = useState(false);
const [editedProject, setEditedProject] = useState(
_selectedTask?.project || ''
Expand Down Expand Up @@ -385,9 +395,14 @@ export const Tasks = (
if (!_isDialogOpen) {
setIsEditing(false);
setEditedDescription('');
setIsEditingTags(false);
setEditedTags([]);
setIsEditingPriority(false);
setEditedPriority('NONE');
} else {
setSelectedTask(task);
setEditedDescription(task?.description || '');
setEditedPriority(task?.priority || 'NONE');
}
};

Expand Down Expand Up @@ -466,6 +481,48 @@ export const Tasks = (
setEditedTags([]); // Reset tags
};

const handleEditPriorityClick = (task: Task) => {
// Convert empty priority to "NONE" for the select component
setEditedPriority(task.priority || 'NONE');
setIsEditingPriority(true);
};

const handleSavePriority = async (task: Task) => {
try {
// Convert "NONE" to empty string for backend
const priorityValue = editedPriority === 'NONE' ? '' : editedPriority;

await modifyTaskOnBackend({
email: props.email,
encryptionSecret: props.encryptionSecret,
UUID: props.UUID,
taskID: task.id.toString(),
description: task.description,
project: task.project || '',
priority: priorityValue,
status: task.status,
due: task.due || '',
tags: task.tags || [],
backendURL: url.backendURL,
});

console.log('Priority updated successfully!');
toast.success('Priority updated successfully!');
setIsEditingPriority(false);
} catch (error) {
console.error('Failed to update priority:', error);
toast.error('Failed to update priority. Please try again.');
}
};

const handleCancelPriority = () => {
setIsEditingPriority(false);
// Reset to the task's original priority
if (_selectedTask) {
setEditedPriority(_selectedTask.priority || 'NONE');
}
};

return (
<section
id="tasks"
Expand Down Expand Up @@ -960,7 +1017,73 @@ export const Tasks = (
</TableRow>
<TableRow>
<TableCell>Priority:</TableCell>
<TableCell>{task.priority}</TableCell>
<TableCell>
{isEditingPriority ? (
<div className="flex items-center">
<Select
value={editedPriority}
onValueChange={setEditedPriority}
>
<SelectTrigger className="flex-grow mr-2">
<SelectValue placeholder="Select priority" />
</SelectTrigger>
<SelectContent>
<SelectItem value="NONE">
None
</SelectItem>
<SelectItem value="H">
High (H)
</SelectItem>
<SelectItem value="M">
Medium (M)
</SelectItem>
<SelectItem value="L">
Low (L)
</SelectItem>
</SelectContent>
</Select>
<Button
variant="ghost"
size="icon"
onClick={() =>
handleSavePriority(task)
}
>
<CheckIcon className="h-4 w-4 text-green-500" />
</Button>
<Button
variant="ghost"
size="icon"
onClick={handleCancelPriority}
>
<XIcon className="h-4 w-4 text-red-500" />
</Button>
</div>
) : (
<div className="flex items-center">
<span>
{task.priority
? task.priority === 'H'
? 'High (H)'
: task.priority === 'M'
? 'Medium (M)'
: task.priority === 'L'
? 'Low (L)'
: task.priority
: 'None'}
</span>
<Button
variant="ghost"
size="icon"
onClick={() =>
handleEditPriorityClick(task)
}
>
<PencilIcon className="h-4 w-4 text-gray-500" />
</Button>
</div>
)}
</TableCell>
</TableRow>
<TableRow>
<TableCell>Project:</TableCell>
Expand Down
52 changes: 52 additions & 0 deletions frontend/src/components/HomeComponents/Tasks/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,58 @@ export const editTaskOnBackend = async ({
return response;
};

export const modifyTaskOnBackend = async ({
email,
encryptionSecret,
UUID,
taskID,
description,
project,
priority,
status,
due,
tags,
backendURL,
}: {
email: string;
encryptionSecret: string;
UUID: string;
taskID: string;
description: string;
project: string;
priority: string;
status: string;
due: string;
tags: string[];
backendURL: string;
}) => {
const response = await fetch(`${backendURL}modify-task`, {
method: 'POST',
body: JSON.stringify({
email,
encryptionSecret,
UUID,
taskid: taskID,
description,
project,
priority,
status,
due,
tags,
}),
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
const errorText = await response.text();
throw new Error(errorText || 'Failed to modify task');
}

return response;
};

export class TasksDatabase extends Dexie {
tasks: Dexie.Table<Task, string>;

Expand Down
Loading