Skip to content

Commit e678830

Browse files
committed
feat: close calendar on day press
1 parent 1e27590 commit e678830

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

apps/expo/src/components/home/home-calendar.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ import { BasicCalendar } from "~/components/basic-calendar";
1212
import { useDateStore } from "~/stores/dateStore";
1313

1414
export function HomeCalendar() {
15-
const { selectedDate, setSelectedDate } = useDateStore();
15+
const { selectedDate, setSelectedDate, setIsCalendarOpen } = useDateStore();
1616
const [currentCalendarMonth, setCurrentCalendarMonth] =
1717
useState(selectedDate);
1818

1919
const handleDayPress = useCallback<CalendarOnDayPress>(
2020
(dateId) => {
2121
setCurrentCalendarMonth(fromDateId(dateId));
2222
setSelectedDate(fromDateId(dateId));
23+
setIsCalendarOpen(false); // Close the dialog after selecting a date
2324
},
24-
[setSelectedDate],
25+
[setSelectedDate, setIsCalendarOpen],
2526
);
2627

2728
const calendarActiveDateRanges = useMemo<CalendarActiveDateRange[]>(

apps/expo/src/components/home/home-header.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import { Calendar } from "~/lib/icons/calendar";
1515
import { useDateStore } from "~/stores/dateStore";
1616

1717
export default function HomeHeader() {
18-
const { selectedDate } = useDateStore();
18+
const { selectedDate, isCalendarOpen, setIsCalendarOpen } = useDateStore();
1919

2020
const formattedDate = isToday(selectedDate)
2121
? "Today"
2222
: format(selectedDate, "MMMM do, yyyy");
2323

2424
return (
2525
<View className="flex-row items-center justify-between px-2">
26-
<Dialog>
26+
<Dialog open={isCalendarOpen} onOpenChange={setIsCalendarOpen}>
2727
<DialogTrigger asChild>
2828
<Button variant="ghost" className="flex-row items-center gap-2">
2929
<Calendar className="text-foreground" size={24} />

apps/expo/src/stores/dateStore.ts

+4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import { create } from "zustand";
33
interface DateState {
44
selectedDate: Date;
55
setSelectedDate: (date: Date) => void;
6+
isCalendarOpen: boolean;
7+
setIsCalendarOpen: (isOpen: boolean) => void;
68
}
79

810
export const useDateStore = create<DateState>((set) => ({
911
selectedDate: new Date(),
1012
setSelectedDate: (date: Date) => set({ selectedDate: date }),
13+
isCalendarOpen: false,
14+
setIsCalendarOpen: (isOpen: boolean) => set({ isCalendarOpen: isOpen }),
1115
}));
1216

1317
// Example persist-middleware with MMKV

0 commit comments

Comments
 (0)