From 18fafca2150010e7efacba0c2a3d5d435ff819aa Mon Sep 17 00:00:00 2001 From: ANIR1604 Date: Fri, 14 Nov 2025 00:55:07 +0530 Subject: [PATCH] Added the Edit Priority Thing --- .../components/HomeComponents/Tasks/Tasks.tsx | 125 +++++++++++++++++- .../components/HomeComponents/Tasks/hooks.ts | 52 ++++++++ 2 files changed, 176 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/HomeComponents/Tasks/Tasks.tsx b/frontend/src/components/HomeComponents/Tasks/Tasks.tsx index 2f2e4b7d..48e48d33 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 [searchTerm, setSearchTerm] = useState(''); const [lastSyncTime, setLastSyncTime] = useState(null); @@ -364,9 +374,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'); } }; @@ -444,6 +459,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 c9568247..aeb90f54 100644 --- a/frontend/src/components/HomeComponents/Tasks/hooks.ts +++ b/frontend/src/components/HomeComponents/Tasks/hooks.ts @@ -120,6 +120,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;