Skip to content

Commit 3dece57

Browse files
committed
feat: add highlights to current date
1 parent 785cb0b commit 3dece57

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/components/ui/date-picker.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>(
7171
selectedDate?.getDate() === day &&
7272
selectedDate?.getMonth() === currentDate.getMonth() &&
7373
selectedDate?.getFullYear() === currentDate.getFullYear(),
74+
}, {
75+
"hover:border-0 bg-primary/20":
76+
new Date().getDate() === day &&
77+
new Date().getMonth() === currentDate.getMonth() &&
78+
new Date().getFullYear() === currentDate.getFullYear()
7479
}
7580
)}
7681
onClick={() => handleDateClick(day)}

src/pages/Dashboard.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ const Dashboard: React.FC = () => {
134134
});
135135
}
136136
}
137+
138+
if (!result.success && result.message === 'Invalid Date') {
139+
toast.error("Invalid date selected", {
140+
description: "Please select a valid date to start your streak.",
141+
});
142+
}
143+
137144
} catch (error) {
138145
console.error('Error updating streak:', error);
139146
toast.error("Failed to set streak start date", {

src/utils/firebase.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,18 @@ export const updateStreakStart = async (userId: string, startDate: Date) => {
318318
const userData = userDoc.data();
319319
const lastCheckIn = userData.lastCheckIn?.toDate() || new Date(0);
320320

321-
const diffInMilliseconds = startDate.getTime() - lastCheckIn.getTime();
321+
const diffInMilliseconds = lastCheckIn.getTime() - startDate.getTime();
322322
const diffInDays = Math.floor(diffInMilliseconds / (1000 * 60 * 60 * 24));
323323

324+
if (diffInDays < 0) {
325+
return { success: false, message: 'Invalid Date' };
326+
}
327+
324328
await updateDoc(userRef, {
325329
streakDays: diffInDays > 0 ? diffInDays : 0, // Ensure streakDays is not negative
326330
});
327331

328-
return { success: true, diffInDays, message: 'Streak start updated successfully' };
332+
return { success: true, message: 'Streak start updated successfully' };
329333
}
330334

331335
return { success: false, message: 'User not found' };

0 commit comments

Comments
 (0)