Skip to content

Commit ecedf04

Browse files
committed
feat: create handleStreakSet function
to call updateStreakStart function in firebase
1 parent 6783ff7 commit ecedf04

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/pages/Dashboard.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,33 @@ const Dashboard: React.FC = () => {
109109
}
110110
};
111111

112+
const handleStreakSet = async (startDate: Date) => {
113+
if (!currentUser) return;
114+
115+
try {
116+
const result = await updateStreakStart(currentUser.uid, startDate);
117+
118+
if (result.success) {
119+
// Refresh user data
120+
const updatedProfile = await getUserProfile(currentUser.uid);
121+
122+
if (updatedProfile) {
123+
setStreak(updatedProfile.streakDays || 0);
124+
}
125+
126+
if (result.message === 'Streak start updated successfully') {
127+
toast.success("Streak start updated!", {
128+
description: `Your streak has been reset to start from ${formatDate(startDate)}.`,
129+
});
130+
}
131+
}
132+
} catch (error) {
133+
console.error('Error updating streak:', error);
134+
toast.error("Failed to set streak start date", {
135+
description: "Please try again later.",
136+
});
137+
}
138+
};
112139

113140

114141
return (

0 commit comments

Comments
 (0)