@@ -10,7 +10,9 @@ import {
1010 TrendingUp ,
1111 MessageCircle ,
1212 Map ,
13- HeartPulse
13+ HeartPulse ,
14+ ArrowDown ,
15+ ArrowUp
1416} from 'lucide-react' ;
1517import { Button } from '@/components/ui/button' ;
1618import { Card , CardContent , CardDescription , CardFooter , CardHeader , CardTitle } from '@/components/ui/card' ;
@@ -21,6 +23,7 @@ import CommunityMap from '@/components/CommunityMap';
2123import { motion } from 'framer-motion' ;
2224import { toast } from 'sonner' ;
2325import VerseSlideshow from '@/components/VerseSlideshow' ;
26+ import DatePicker from '@/components/ui/date-picker' ;
2427
2528const formatDate = ( date : Date ) => {
2629 return new Intl . DateTimeFormat ( 'en-US' , {
@@ -35,6 +38,8 @@ const Dashboard: React.FC = () => {
3538 const [ streak , setStreak ] = useState ( 0 ) ;
3639 const [ lastCheckIn , setLastCheckIn ] = useState < Date | null > ( null ) ;
3740 const [ isCheckedInToday , setIsCheckedInToday ] = useState ( false ) ;
41+ const [ isCheckInSide , setIsCheckInSide ] = useState ( true ) ;
42+ const [ selectedDate , setSelectedDate ] = useState < Date > ( new Date ( ) ) ;
3843
3944 // Simulate featured meditations
4045 const featuredMeditations = [
@@ -77,9 +82,10 @@ const Dashboard: React.FC = () => {
7782
7883 const handleCheckIn = async ( ) => {
7984 if ( ! currentUser ) return ;
80-
85+ console . log ( currentUser . uid )
8186 try {
8287 const result = await updateStreak ( currentUser . uid ) ;
88+ console . log ( result )
8389
8490 if ( result . success ) {
8591 // Refresh user data
@@ -109,11 +115,11 @@ const Dashboard: React.FC = () => {
109115 }
110116 } ;
111117
112- const handleStreakSet = async ( startDate : Date ) => {
118+ const handleStreakSet = async ( ) => {
113119 if ( ! currentUser ) return ;
114120
115121 try {
116- const result = await updateStreakStart ( currentUser . uid , startDate ) ;
122+ const result = await updateStreakStart ( currentUser . uid , selectedDate ) ;
117123
118124 if ( result . success ) {
119125 // Refresh user data
@@ -125,7 +131,7 @@ const Dashboard: React.FC = () => {
125131
126132 if ( result . message === 'Streak start updated successfully' ) {
127133 toast . success ( "Streak start updated!" , {
128- description : `Your streak has been reset to start from ${ formatDate ( startDate ) } .` ,
134+ description : `Your streak has been reset to start from ${ formatDate ( selectedDate ) } .` ,
129135 } ) ;
130136 }
131137 }
@@ -134,6 +140,8 @@ const Dashboard: React.FC = () => {
134140 toast . error ( "Failed to set streak start date" , {
135141 description : "Please try again later." ,
136142 } ) ;
143+ } finally {
144+ setIsCheckInSide ( true ) ;
137145 }
138146 } ;
139147
@@ -175,40 +183,86 @@ const Dashboard: React.FC = () => {
175183 "border-primary/20 h-full" ,
176184 streak > 0 && "bg-gradient-to-br from-primary/10 to-transparent"
177185 ) } >
178- < CardHeader className = "pb-2" >
179- < CardTitle className = "flex items-center" >
180- < Trophy className = "h-5 w-5 mr-2 text-primary" />
181- Your Current Streak
182- </ CardTitle >
183- < CardDescription >
184- { isCheckedInToday
185- ? 'You\'ve checked in today. Great job!'
186- : 'Remember to check in daily to maintain your streak' }
187- </ CardDescription >
188- </ CardHeader >
189- < CardContent >
190- < div className = "flex items-center justify-center py-6" >
191- < div className = "text-center" >
192- < div className = "text-5xl font-bold mb-2 text-primary" >
193- { streak }
186+ { /* Current Streak Card - Check In Side */ }
187+ { isCheckInSide ? (
188+ < div >
189+ < CardHeader className = "pb-2" >
190+ < CardTitle className = "flex items-center" >
191+ < Trophy className = "h-5 w-5 mr-2 text-primary" />
192+ Your Current Streak
193+ </ CardTitle >
194+ < CardDescription >
195+ { isCheckedInToday
196+ ? 'You\'ve checked in today. Great job!'
197+ : 'Remember to check in daily to maintain your streak' }
198+ </ CardDescription >
199+ </ CardHeader >
200+ < CardContent >
201+ < div className = "flex items-center justify-center py-6" >
202+ < div className = "text-center" >
203+ < div className = "text-5xl font-bold mb-2 text-primary" >
204+ { streak }
205+ </ div >
206+ < div className = "text-muted-foreground" >
207+ consecutive { streak === 1 ? 'day' : 'days' }
208+ </ div >
209+ </ div >
194210 </ div >
195- < div className = "text-muted-foreground" >
196- consecutive { streak === 1 ? 'day' : 'days' }
211+ </ CardContent >
212+ < CardFooter className = "flex flex-col items-center space-y-2" >
213+ < Button
214+ onClick = { handleCheckIn }
215+ disabled = { isCheckedInToday }
216+ variant = { isCheckedInToday ? "outline" : "default" }
217+ className = "w-full"
218+ >
219+ { isCheckedInToday ? 'Already Checked In Today' : 'Check In for Today' }
220+ { ! isCheckedInToday && < Calendar className = "ml-2 h-4 w-4" /> }
221+ </ Button >
222+ < Button
223+ variant = "outline"
224+ className = "w-full text-xs"
225+ onClick = { ( ) => setIsCheckInSide ( false ) }
226+ >
227+ Edit Streak Start Date
228+ </ Button >
229+ </ CardFooter >
230+ </ div >
231+ ) : (
232+ // Current Streak Card - Set Streak Start Date Side
233+ < div >
234+ < CardHeader className = "pb-2" >
235+ < CardTitle className = "flex items-center" >
236+ < Trophy className = "h-5 w-5 mr-2 text-primary" />
237+ Set Your Streak
238+ </ CardTitle >
239+ < CardDescription >
240+ Change Your Streak Start Date
241+ </ CardDescription >
242+ </ CardHeader >
243+ < CardContent >
244+ < div className = "flex items-center justify-center py-6" >
245+ { /* calculate the streak start date to display in DatePicker */ }
246+ < DatePicker onDateChange = { setSelectedDate } preselectedDate = { new Date ( Date . now ( ) - streak * 24 * 60 * 60 * 1000 ) } />
197247 </ div >
198- </ div >
248+ </ CardContent >
249+ < CardFooter className = "flex flex-col items-center space-y-2" >
250+ < Button
251+ onClick = { handleStreakSet }
252+ className = "w-full"
253+ >
254+ Set Streak Start Date
255+ </ Button >
256+ < Button
257+ variant = "outline"
258+ className = "w-full text-xs"
259+ onClick = { ( ) => setIsCheckInSide ( true ) }
260+ >
261+ Cancel
262+ </ Button >
263+ </ CardFooter >
199264 </ div >
200- </ CardContent >
201- < CardFooter >
202- < Button
203- onClick = { handleCheckIn }
204- disabled = { isCheckedInToday }
205- variant = { isCheckedInToday ? "outline" : "default" }
206- className = "w-full"
207- >
208- { isCheckedInToday ? 'Already Checked In Today' : 'Check In for Today' }
209- { ! isCheckedInToday && < Calendar className = "ml-2 h-4 w-4" /> }
210- </ Button >
211- </ CardFooter >
265+ ) }
212266 </ Card >
213267 </ motion . div >
214268
0 commit comments