feat: add 'Mark Prayed' button for prayer items with streak tracking
This commit is contained in:
1 parent
8105d39554
commit
6c33fc4606
5 files changed
+66
-87
No files matched your search
+12
-19
@@ -34,16 +34,25 @@ export default function HomePage({ prayers, todayCount, onStartPraying, onSelect
|
||||
const calculateStreak = () => {
|
||||
if (prayers.length === 0) return 0;
|
||||
|
||||
const prayerDates = Array.from(new Set(prayers.map(p => p.date))).sort().reverse();
|
||||
// Get all dates where user either created a prayer OR marked something as prayed for
|
||||
const activityDates = new Set<string>();
|
||||
prayers.forEach(p => {
|
||||
activityDates.add(p.date); // Date prayer was created
|
||||
if (p.lastPrayedFor) {
|
||||
activityDates.add(p.lastPrayedFor); // Date marked as prayed for
|
||||
}
|
||||
});
|
||||
|
||||
const sortedDates = Array.from(activityDates).sort().reverse();
|
||||
let streak = 0;
|
||||
let checkDate = new Date(today);
|
||||
|
||||
for (let i = 0; i < 365; i++) {
|
||||
const dateStr = checkDate.toISOString().split('T')[0];
|
||||
if (prayerDates.includes(dateStr)) {
|
||||
if (sortedDates.includes(dateStr)) {
|
||||
streak++;
|
||||
} else if (i === 0) {
|
||||
// If today has no prayer, streak is broken (unless we haven't prayed today yet, which is ok)
|
||||
// If today has no activity, streak is broken
|
||||
break;
|
||||
} else {
|
||||
break;
|
||||
@@ -54,23 +63,7 @@ export default function HomePage({ prayers, todayCount, onStartPraying, onSelect
|
||||
return streak;
|
||||
};
|
||||
|
||||
// Calculate frequency compliance - how many active items being prayed for
|
||||
const frequencyCompliance = () => {
|
||||
const activePrayers = prayers.filter(p => !p.answered && p.prayFrequency);
|
||||
if (activePrayers.length === 0) return 0;
|
||||
|
||||
// Check today's date
|
||||
const todayPrayers = prayers.filter(p => p.date === today);
|
||||
return {
|
||||
total: activePrayers.length,
|
||||
prayedToday: activePrayers.filter(ap =>
|
||||
todayPrayers.some(tp => tp.prayFor === ap.prayFor || tp.id === ap.id)
|
||||
).length,
|
||||
};
|
||||
};
|
||||
|
||||
const streak = calculateStreak();
|
||||
const frequencyStats = frequencyCompliance();
|
||||
|
||||
// Calculate more stats
|
||||
const avgPrayerLength = totalPrayers > 0
|
||||
|
||||
Reference in new issue
Block a user