diff --git a/src/app/(app)/(tabs)/index.tsx b/src/app/(app)/(tabs)/index.tsx index 4f18253..042c03f 100644 --- a/src/app/(app)/(tabs)/index.tsx +++ b/src/app/(app)/(tabs)/index.tsx @@ -94,7 +94,8 @@ const HomePage = () => { setCurrentMonth(currentMonth - 1); } }; - + // Function to handle next month button press + // This function updates the current month and year state variables const handleNextMonth = () => { Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light); if (currentMonth === 11) { @@ -116,6 +117,14 @@ const HomePage = () => { if (loading) { return Loading...; } + const entriesForSelectedDate = selectedDate + ? allEntries + .filter((entry) => { + const dateStr = entry.createdAt?.toDate().toLocaleDateString("en-CA"); + return !entry.collectionId && dateStr === selectedDate; + }) + .sort((a, b) => b.createdAt.toDate() - a.createdAt.toDate()) + : []; return ( { /> {selectedDate ? ( - // Show entries only for selected date - <> - {entries.filter((entry) => { - const dateStr = entry.createdAt - ?.toDate() - .toISOString() - .split("T")[0]; - return dateStr === selectedDate; - }).length === 0 ? ( - - ) : ( - entries - .filter((entry) => { - const dateStr = entry.createdAt - ?.toDate() - .toISOString() - .split("T")[0]; - return dateStr === selectedDate; - }) - .map((entry) => ) - )} - + entriesForSelectedDate.length === 0 ? ( + + ) : ( + entriesForSelectedDate.map((entry) => ( + + )) + ) ) : ( - // Show all entries for the current month - <> - {entries.length === 0 ? ( - - ) : ( - entries.map((entry) => ) - )} - + entries.length === 0 ? ( + + ) : ( + entries.map((entry) => ) + ) )} {/* Prompt Card */} diff --git a/src/components/JournalCalendar.tsx b/src/components/JournalCalendar.tsx index c26bc36..8bfd27a 100644 --- a/src/components/JournalCalendar.tsx +++ b/src/components/JournalCalendar.tsx @@ -14,17 +14,15 @@ const JournalCalendar = ({ setSelectedDate: (date: string) => void; }) => { const markedDates = Object.fromEntries( - entries.map((entry) => { - const dateStr = entry.createdAt?.toDate().toISOString().split("T")[0]; - return [ - dateStr, - { - marked: true, - dotColor: "#9C27B0", - }, - ]; + entries.flatMap((entry) => { + const dateObj = entry.createdAt?.toDate?.(); + if (!dateObj) return []; // return empty array instead of null + const dateStr = dateObj.toLocaleDateString("en-CA"); + return [[dateStr, { marked: true, dotColor: "#9C27B0" }]]; }) ); + + return (