diff --git a/frontend/src/components/HomeComponents/Tasks/Tasks.tsx b/frontend/src/components/HomeComponents/Tasks/Tasks.tsx index b1d547f5..a0c6855d 100644 --- a/frontend/src/components/HomeComponents/Tasks/Tasks.tsx +++ b/frontend/src/components/HomeComponents/Tasks/Tasks.tsx @@ -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, @@ -56,6 +63,7 @@ import BottomBar from '../BottomBar/BottomBar'; import { addTaskToBackend, editTaskOnBackend, + modifyTaskOnBackend, fetchTaskwarriorTasks, TasksDatabase, } from './hooks'; @@ -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 || '' @@ -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'); } }; @@ -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 (
Priority: - {task.priority} + + {isEditingPriority ? ( +
+ + + +
+ ) : ( +
+ + {task.priority + ? task.priority === 'H' + ? 'High (H)' + : task.priority === 'M' + ? 'Medium (M)' + : task.priority === 'L' + ? 'Low (L)' + : task.priority + : 'None'} + + +
+ )} +
Project: diff --git a/frontend/src/components/HomeComponents/Tasks/hooks.ts b/frontend/src/components/HomeComponents/Tasks/hooks.ts index 6bf42b88..e5299932 100644 --- a/frontend/src/components/HomeComponents/Tasks/hooks.ts +++ b/frontend/src/components/HomeComponents/Tasks/hooks.ts @@ -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;