@@ -79,17 +79,34 @@ const DailyView = ({
79
79
} , [ selectedDate , userID ] ) ;
80
80
81
81
const onTaskDelete = async ( taskId ) => {
82
+ const task = tasks . find ( t => t . id === taskId ) ;
83
+ if ( ! task ) {
84
+ Alert . alert ( "Error" , "Task not found." ) ;
85
+ return ;
86
+ }
87
+
82
88
try {
89
+ // Ensure the task is marked as incomplete before deletion if it's currently completed
90
+ if ( task . completed ) {
91
+ await updateTaskForUser ( userID , taskId , { completed : false } ) ;
92
+ }
93
+
94
+ // Proceed to delete the task
83
95
await deleteTask ( userID , taskId ) ;
84
- eventEmitter . emit ( "taskDeleted" , taskId ) ;
96
+
85
97
Alert . alert ( "Success" , "Task deleted successfully." ) ;
86
- setVisibleTaskActions ( prev => ( { ...prev , [ taskId ] : false } ) ) ; // Hide buttons
98
+
99
+ // Update UI by removing the task from the list and hiding the action buttons
100
+ setVisibleTaskActions ( prev => ( { ...prev , [ taskId ] : false } ) ) ;
87
101
setTasks ( prevTasks => prevTasks . filter ( t => t . id !== taskId ) ) ;
102
+ eventEmitter . emit ( "taskDeleted" , taskId ) ;
103
+ eventEmitter . emit ( "taskUpdated" , taskId ) ;
88
104
} catch ( error ) {
89
105
console . error ( "Error deleting task: " , error ) ;
90
106
Alert . alert ( "Error" , "Failed to delete task." ) ;
91
107
}
92
108
} ;
109
+
93
110
94
111
const toggleCompletion = async ( task ) => {
95
112
const updatedStatus = ! task . completed ;
@@ -111,7 +128,7 @@ const DailyView = ({
111
128
Daily Tasks for { format ( selectedDate , "PPP" ) }
112
129
</ Text >
113
130
{ isBirthday && (
114
- < Text style = { styles . BirthdayCelebration } > 🎉 Happy Birthday! 🎉</ Text >
131
+ < Text style = { styles . BirthdayCelebration } > 🎉 Your Birthday! 🎉</ Text >
115
132
) }
116
133
< BirthdayCelebration userName = { userName } isBirthday = { isBirthday } />
117
134
< FlatList
0 commit comments