File tree 3 files changed +9
-4
lines changed
3 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -12,16 +12,17 @@ import { BasicCalendar } from "~/components/basic-calendar";
12
12
import { useDateStore } from "~/stores/dateStore" ;
13
13
14
14
export function HomeCalendar ( ) {
15
- const { selectedDate, setSelectedDate } = useDateStore ( ) ;
15
+ const { selectedDate, setSelectedDate, setIsCalendarOpen } = useDateStore ( ) ;
16
16
const [ currentCalendarMonth , setCurrentCalendarMonth ] =
17
17
useState ( selectedDate ) ;
18
18
19
19
const handleDayPress = useCallback < CalendarOnDayPress > (
20
20
( dateId ) => {
21
21
setCurrentCalendarMonth ( fromDateId ( dateId ) ) ;
22
22
setSelectedDate ( fromDateId ( dateId ) ) ;
23
+ setIsCalendarOpen ( false ) ; // Close the dialog after selecting a date
23
24
} ,
24
- [ setSelectedDate ] ,
25
+ [ setSelectedDate , setIsCalendarOpen ] ,
25
26
) ;
26
27
27
28
const calendarActiveDateRanges = useMemo < CalendarActiveDateRange [ ] > (
Original file line number Diff line number Diff line change @@ -15,15 +15,15 @@ import { Calendar } from "~/lib/icons/calendar";
15
15
import { useDateStore } from "~/stores/dateStore" ;
16
16
17
17
export default function HomeHeader ( ) {
18
- const { selectedDate } = useDateStore ( ) ;
18
+ const { selectedDate, isCalendarOpen , setIsCalendarOpen } = useDateStore ( ) ;
19
19
20
20
const formattedDate = isToday ( selectedDate )
21
21
? "Today"
22
22
: format ( selectedDate , "MMMM do, yyyy" ) ;
23
23
24
24
return (
25
25
< View className = "flex-row items-center justify-between px-2" >
26
- < Dialog >
26
+ < Dialog open = { isCalendarOpen } onOpenChange = { setIsCalendarOpen } >
27
27
< DialogTrigger asChild >
28
28
< Button variant = "ghost" className = "flex-row items-center gap-2" >
29
29
< Calendar className = "text-foreground" size = { 24 } />
Original file line number Diff line number Diff line change @@ -3,11 +3,15 @@ import { create } from "zustand";
3
3
interface DateState {
4
4
selectedDate : Date ;
5
5
setSelectedDate : ( date : Date ) => void ;
6
+ isCalendarOpen : boolean ;
7
+ setIsCalendarOpen : ( isOpen : boolean ) => void ;
6
8
}
7
9
8
10
export const useDateStore = create < DateState > ( ( set ) => ( {
9
11
selectedDate : new Date ( ) ,
10
12
setSelectedDate : ( date : Date ) => set ( { selectedDate : date } ) ,
13
+ isCalendarOpen : false ,
14
+ setIsCalendarOpen : ( isOpen : boolean ) => set ( { isCalendarOpen : isOpen } ) ,
11
15
} ) ) ;
12
16
13
17
// Example persist-middleware with MMKV
You can’t perform that action at this time.
0 commit comments