Skip to content

Commit 6b082a6

Browse files
committed
changed birthday
1 parent 5b7c366 commit 6b082a6

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

components/DailyView.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,34 @@ const DailyView = ({
7979
}, [selectedDate, userID]);
8080

8181
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+
8288
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
8395
await deleteTask(userID, taskId);
84-
eventEmitter.emit("taskDeleted", taskId);
96+
8597
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 }));
87101
setTasks(prevTasks => prevTasks.filter(t => t.id !== taskId));
102+
eventEmitter.emit("taskDeleted", taskId);
103+
eventEmitter.emit("taskUpdated", taskId);
88104
} catch (error) {
89105
console.error("Error deleting task: ", error);
90106
Alert.alert("Error", "Failed to delete task.");
91107
}
92108
};
109+
93110

94111
const toggleCompletion = async (task) => {
95112
const updatedStatus = !task.completed;
@@ -111,7 +128,7 @@ const DailyView = ({
111128
Daily Tasks for {format(selectedDate, "PPP")}
112129
</Text>
113130
{isBirthday && (
114-
<Text style={styles.BirthdayCelebration}>🎉 Happy Birthday! 🎉</Text>
131+
<Text style={styles.BirthdayCelebration}>🎉 Your Birthday! 🎉</Text>
115132
)}
116133
<BirthdayCelebration userName={userName} isBirthday={isBirthday} />
117134
<FlatList

0 commit comments

Comments
 (0)