Skip to content

Commit

Permalink
changed birthday
Browse files Browse the repository at this point in the history
  • Loading branch information
vuvnguyen95 committed Apr 23, 2024
1 parent 5b7c366 commit 6b082a6
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions components/DailyView.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,34 @@ const DailyView = ({
}, [selectedDate, userID]);

const onTaskDelete = async (taskId) => {
const task = tasks.find(t => t.id === taskId);
if (!task) {
Alert.alert("Error", "Task not found.");
return;
}

try {
// Ensure the task is marked as incomplete before deletion if it's currently completed
if (task.completed) {
await updateTaskForUser(userID, taskId, { completed: false });
}

// Proceed to delete the task
await deleteTask(userID, taskId);
eventEmitter.emit("taskDeleted", taskId);

Alert.alert("Success", "Task deleted successfully.");
setVisibleTaskActions(prev => ({ ...prev, [taskId]: false })); // Hide buttons

// Update UI by removing the task from the list and hiding the action buttons
setVisibleTaskActions(prev => ({ ...prev, [taskId]: false }));
setTasks(prevTasks => prevTasks.filter(t => t.id !== taskId));
eventEmitter.emit("taskDeleted", taskId);
eventEmitter.emit("taskUpdated", taskId);
} catch (error) {
console.error("Error deleting task: ", error);
Alert.alert("Error", "Failed to delete task.");
}
};


const toggleCompletion = async (task) => {
const updatedStatus = !task.completed;
Expand All @@ -111,7 +128,7 @@ const DailyView = ({
Daily Tasks for {format(selectedDate, "PPP")}
</Text>
{isBirthday && (
<Text style={styles.BirthdayCelebration}>πŸŽ‰ Happy Birthday! πŸŽ‰</Text>
<Text style={styles.BirthdayCelebration}>πŸŽ‰ Your Birthday! πŸŽ‰</Text>
)}
<BirthdayCelebration userName={userName} isBirthday={isBirthday} />
<FlatList
Expand Down

0 comments on commit 6b082a6

Please sign in to comment.