diff --git a/src/pages/home/components/calendar-section.tsx b/src/pages/home/components/calendar-section.tsx index d3ed4a89..f4dbde5a 100644 --- a/src/pages/home/components/calendar-section.tsx +++ b/src/pages/home/components/calendar-section.tsx @@ -10,6 +10,7 @@ interface CalendarSectionProps { onDateChange: (date: Date) => void; baseWeekDate: Date; onOpenBottomSheet: () => void; + onWeekChange: (direction: 'prev' | 'next') => void; } const CalendarSection = ({ @@ -19,6 +20,7 @@ const CalendarSection = ({ onDateChange, baseWeekDate, onOpenBottomSheet, + onWeekChange, }: CalendarSectionProps) => { const handleTabChange = (type: TabType) => { onTabChange(type); @@ -33,6 +35,7 @@ const CalendarSection = ({ onChange={(date) => { onDateChange(date); }} + onWeekChange={onWeekChange} />
diff --git a/src/pages/home/home.tsx b/src/pages/home/home.tsx index bd497787..f994b9e7 100644 --- a/src/pages/home/home.tsx +++ b/src/pages/home/home.tsx @@ -56,6 +56,10 @@ const Home = () => { setBaseWeekDate(date); }; + const handleWeekChange = (direction: 'prev' | 'next') => { + setBaseWeekDate((prev) => addDays(prev, direction === 'next' ? 7 : -7)); + }; + const handleComplete = () => { gaEvent('condition_set_start'); navigate(ROUTES.ONBOARDING); @@ -71,6 +75,7 @@ const Home = () => { onDateChange={setSelectedDate} baseWeekDate={baseWeekDate} onOpenBottomSheet={() => setIsCalendarBottomSheetOpen(true)} + onWeekChange={handleWeekChange} /> void; + onWeekChange?: (direction: 'prev' | 'next') => void; } -const WeekCalendar = ({ entryDate, baseDate, value, onChange }: WeekCalendarProps) => { +const SWIPE_THRESHOLD = 50; + +const slideVariants = { + enter: (direction: number) => ({ + x: direction > 0 ? '100%' : '-100%', + opacity: 0, + }), + center: { x: 0, opacity: 1 }, + exit: (direction: number) => ({ + x: direction > 0 ? '-100%' : '100%', + opacity: 0, + }), +}; + +const WeekCalendar = ({ + entryDate, + baseDate, + value, + onChange, + onWeekChange, +}: WeekCalendarProps) => { const days = getWeekDays(baseDate); + const directionRef = useRef(0); + const touchStartXRef = useRef(0); + + const handleTouchStart = (e: React.TouchEvent) => { + touchStartXRef.current = e.touches[0].clientX; + }; + + const handleTouchEnd = (e: React.TouchEvent) => { + const diff = touchStartXRef.current - e.changedTouches[0].clientX; + if (Math.abs(diff) < SWIPE_THRESHOLD || !onWeekChange) return; + + if (diff > 0) { + directionRef.current = 1; + onWeekChange('next'); + } else { + directionRef.current = -1; + onWeekChange('prev'); + } + }; return ( -
- {days.map((day) => { - const isSelected = isSameDay(day, value); - - const dateColor = 'text-gray-white'; - const dayColor = isSelected ? 'text-main-400' : 'text-gray-500'; - - const handleClick = (day: Date) => { - const isBlocked = day <= addDays(entryDate, 1); - - if (isBlocked) { - showErrorToast(DATE_SELECT_TOAST_MESSAGE, '7.6rem'); - return; - } - onChange(day); - }; - - return ( - - ); - })} +
+ + + {days.map((day) => { + const isSelected = isSameDay(day, value); + + const dateColor = 'text-gray-white'; + const dayColor = isSelected ? 'text-main-400' : 'text-gray-500'; + + const handleClick = (day: Date) => { + const isBlocked = day <= addDays(entryDate, 1); + + if (isBlocked) { + showErrorToast(DATE_SELECT_TOAST_MESSAGE, '7.6rem'); + return; + } + onChange(day); + }; + + return ( + + ); + })} + +
); };