From 6b082a6c796f79153f9beeb51a345b75dcf1b9a8 Mon Sep 17 00:00:00 2001 From: vuvnguyen95 Date: Mon, 22 Apr 2024 21:47:54 -0400 Subject: [PATCH] changed birthday --- components/DailyView.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/components/DailyView.js b/components/DailyView.js index 6dc85545..15bbd988 100644 --- a/components/DailyView.js +++ b/components/DailyView.js @@ -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; @@ -111,7 +128,7 @@ const DailyView = ({ Daily Tasks for {format(selectedDate, "PPP")} {isBirthday && ( - 🎉 Happy Birthday! 🎉 + 🎉 Your Birthday! 🎉 )}