Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 22 additions & 31 deletions src/app/(app)/(tabs)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -116,6 +117,14 @@ const HomePage = () => {
if (loading) {
return <Text>Loading...</Text>;
}
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 (
<ScrollView
Expand All @@ -142,37 +151,19 @@ const HomePage = () => {
/>

{selectedDate ? (
// Show entries only for selected date
<>
{entries.filter((entry) => {
const dateStr = entry.createdAt
?.toDate()
.toISOString()
.split("T")[0];
return dateStr === selectedDate;
}).length === 0 ? (
<NoEntries formattedMonthYear={selectedDate} />
) : (
entries
.filter((entry) => {
const dateStr = entry.createdAt
?.toDate()
.toISOString()
.split("T")[0];
return dateStr === selectedDate;
})
.map((entry) => <JournalEntry key={entry.id} data={entry} />)
)}
</>
entriesForSelectedDate.length === 0 ? (
<NoEntries formattedMonthYear={selectedDate} />
) : (
entriesForSelectedDate.map((entry) => (
<JournalEntry key={entry.id} data={entry} />
))
)
) : (
// Show all entries for the current month
<>
{entries.length === 0 ? (
<NoEntries formattedMonthYear={formattedMonthYear} />
) : (
entries.map((entry) => <JournalEntry key={entry.id} data={entry} />)
)}
</>
entries.length === 0 ? (
<NoEntries formattedMonthYear={formattedMonthYear} />
) : (
entries.map((entry) => <JournalEntry key={entry.id} data={entry} />)
)
)}

{/* Prompt Card */}
Expand Down
16 changes: 7 additions & 9 deletions src/components/JournalCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<View style={styles.calendarWrapper}>
Expand Down