From 07e25db25db533d445575e789accc6e99c2ba391 Mon Sep 17 00:00:00 2001 From: Manas <88604968+manaspros@users.noreply.github.com> Date: Wed, 8 Jan 2025 18:31:25 +0530 Subject: [PATCH] Update AttendanceScreen.js --- src/screens/AttendanceScreen.js | 65 ++------------------------------- 1 file changed, 4 insertions(+), 61 deletions(-) diff --git a/src/screens/AttendanceScreen.js b/src/screens/AttendanceScreen.js index d27c51e..c8def58 100644 --- a/src/screens/AttendanceScreen.js +++ b/src/screens/AttendanceScreen.js @@ -161,74 +161,17 @@ const AttendanceScreen = ({ navigation }) => { setMarkedDates(newMarkedDates); }; - const [previousDateColor, setPreviousDateColor] = useState({}); - const handleDateSelect = (date) => { - const { dateString } = date; - const dayOfWeek = getDayOfWeek(dateString); - + const dayOfWeek = getDayOfWeek(date.dateString); if ( courseSchedules[course]?.[dayOfWeek] && - !courseHolidays[course]?.includes(dateString) + !courseHolidays[course]?.includes(date.dateString) ) { - setMarkedDates((prev) => { - const updatedDates = { ...prev }; - - // If there's a previously selected date - if (selectedDate) { - // Dynamically fetch the current color of the previously selected date - const currentColor = - prev[selectedDate]?.customStyles?.container?.backgroundColor || - "white"; - - // Restore the previous date's color - updatedDates[selectedDate] = { - ...updatedDates[selectedDate], - customStyles: { - ...updatedDates[selectedDate]?.customStyles, - container: { - backgroundColor: currentColor, // Use the dynamically fetched color - }, - }, - }; - - // Store this color in previousDateColor for future reference - setPreviousDateColor((prevColors) => ({ - ...prevColors, - [selectedDate]: currentColor, - })); - } - - // Store the current color of the new date - const newDateCurrentColor = - prev[dateString]?.customStyles?.container?.backgroundColor || "white"; - - setPreviousDateColor((prevColors) => ({ - ...prevColors, - [dateString]: newDateCurrentColor, - })); - - // Highlight the new date with blue - updatedDates[dateString] = { - ...updatedDates[dateString], - customStyles: { - ...updatedDates[dateString]?.customStyles, - container: { - backgroundColor: "blue", - }, - }, - }; - - return updatedDates; - }); - - // Update the selected date state - setSelectedDate(dateString); + setSelectedDate(date.dateString); } else { - Alert.alert("No classes scheduled or holiday on this day."); + Alert.alert("No classes scheduled or holiday on this day. "); } }; - const handleMarkAllClasses = async (status) => { if (!selectedDate) { Alert.alert("Please select a valid date.");