diff --git a/src/components/App.tsx b/src/components/App.tsx index 54da305..25b6d01 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -23,7 +23,7 @@ const App = () => { return ( -
+
} /> } /> @@ -31,7 +31,7 @@ const App = () => { } /> } /> -
+
); diff --git a/src/components/calendar-month/CalendarCell.tsx b/src/components/calendar-month/CalendarCell.tsx index 6ec9b46..7b97fd2 100644 --- a/src/components/calendar-month/CalendarCell.tsx +++ b/src/components/calendar-month/CalendarCell.tsx @@ -10,7 +10,7 @@ import { import { useNotesStore, useOccurrencesStore } from '@stores'; import { useUser } from '@supabase/auth-helpers-react'; import clsx from 'clsx'; -import { format } from 'date-fns'; +import { format, isToday, isFuture } from 'date-fns'; import { AnimatePresence, motion } from 'framer-motion'; import React from 'react'; @@ -61,16 +61,10 @@ const CalendarCell = ({ const { removeOccurrence, fetchingOccurrences, occurrencesByDate } = useOccurrencesStore(); const { notes, fetchingNotes } = useNotesStore(); - const today = new Date(); - const isToday = - today.getDate() === dateNumber && - today.getMonth() + 1 === monthNumber && - today.getFullYear() === fullYear; const screenSize = useScreenSize(); - const date = format( - new Date(fullYear, monthNumber - 1, dateNumber), - 'yyyy-MM-dd' - ); + const cellDate = new Date(fullYear, monthNumber - 1, dateNumber); + const isTodayCell = isToday(cellDate); + const date = format(cellDate, 'yyyy-MM-dd'); const occurrences = isCalendarDay(date) ? occurrencesByDate[date] || [] : []; const isMobile = screenSize < 768; @@ -103,7 +97,6 @@ const CalendarCell = ({ return onAddOccurrence(dateNumber, monthNumber, fullYear); }, [ - isToday, dateNumber, fetchingOccurrences, fullYear, @@ -152,21 +145,21 @@ const CalendarCell = ({ }; const cellRootClassName = clsx( - 'group/cell flex h-auto flex-1 flex-col gap-2 border-r-2 border-neutral-500 transition-colors last-of-type:border-r-0 hover:bg-neutral-200 dark:border-neutral-400 dark:hover:bg-neutral-800 lg:h-28', + 'group/cell flex h-auto flex-1 flex-col gap-2 border-r-2 border-neutral-500 transition-colors last-of-type:border-r-0 hover:bg-neutral-200 dark:border-neutral-400 dark:hover:bg-neutral-800 lg:h-36', rangeStatus === 'below-range' && 'cursor-w-resize', rangeStatus === 'above-range' && 'cursor-e-resize', position === 'top-left' && 'rounded-tl-md', position === 'top-right' && 'rounded-tr-md', position === 'bottom-left' && 'rounded-bl-md', position === 'bottom-right' && 'rounded-br-md', - isToday && - 'bg-neutral-200 hover:bg-neutral-300 dark:bg-neutral-800 dark:hover:bg-neutral-700' + isTodayCell && + 'bg-background-200 hover:bg-background-300 dark:bg-background-800 dark:hover:bg-background-700' ); const cellHeaderClassName = clsx( - 'flex w-full items-center justify-between border-b-1 border-neutral-500 px-1.5 py-0.5 text-sm dark:border-neutral-400 md:text-base', + 'flex w-full items-center justify-between border-b-1 border-neutral-500 px-1.5 py-1.5 text-sm dark:border-neutral-400 md:text-base', rangeStatus !== 'in-range' && 'text-neutral-400 dark:text-neutral-600', - isToday ? 'w-full self-auto md:self-start' : 'w-full' + isTodayCell ? 'w-full self-auto md:self-start' : 'w-full' ); return ( @@ -181,24 +174,26 @@ const CalendarCell = ({
{rangeStatus === 'in-range' && !isMobile && (
- - - + {!isFuture(cellDate) && ( + + + + )}
activeMonth + : month > activeMonth || + (month === 1 && activeMonth === 12) ? 'above-range' : 'in-range'; diff --git a/src/components/calendar-month/MonthCalendar.tsx b/src/components/calendar-month/MonthCalendar.tsx index 2725f22..8ee6710 100644 --- a/src/components/calendar-month/MonthCalendar.tsx +++ b/src/components/calendar-month/MonthCalendar.tsx @@ -7,7 +7,6 @@ import { capitalizeFirstLetter } from '@utils'; import clsx from 'clsx'; import React from 'react'; import { type AriaButtonProps, useCalendar, useLocale } from 'react-aria'; -import { useNavigate } from 'react-router-dom'; import { useCalendarState } from 'react-stately'; import CalendarGrid from './CalendarGrid'; @@ -44,7 +43,6 @@ const MonthCalendar = () => { onClose: closeOccurrenceDialog, } = useDisclosure(); const [activeDate, setActiveDate] = React.useState(null); - const navigate = useNavigate(); React.useEffect(() => { onRangeChange( @@ -120,10 +118,6 @@ const MonthCalendar = () => { setActiveDate(new Date(fullYear, monthIndex - 1, dateNumber, 12)); }; - const handleWeekClick = (weekNumber: number) => { - navigate('/calendar/week', { state: { weekNumber } }); - }; - const transformButtonProps = ( buttonProps: Pick, 'isDisabled' | 'aria-label'> ) => ({ @@ -156,7 +150,6 @@ const MonthCalendar = () => { state={state} onAddOccurrence={handleOccurrenceModalOpen} onAddNote={handleNoteModalOpen} - onWeekClick={handleWeekClick} />
diff --git a/src/components/calendar-week/WeekCalendar.tsx b/src/components/calendar-week/WeekCalendar.tsx index 507af36..1385dee 100644 --- a/src/components/calendar-week/WeekCalendar.tsx +++ b/src/components/calendar-week/WeekCalendar.tsx @@ -1,12 +1,130 @@ -// import { useLocation } from 'react-router-dom'; +/* eslint-disable */ + +import { useOccurrencesStore } from '@stores'; +import { addDays, eachDayOfInterval, startOfDay, startOfWeek } from 'date-fns'; +import { motion } from 'framer-motion'; +import React from 'react'; +import { useLocation } from 'react-router-dom'; + +import OccurrenceChip from '../calendar-month/OccurrenceChip'; + +const WEEK_DAYS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']; const WeekCalendar = () => { - // const { state } = useLocation(); - // const { weekNumber } = state; + const { state } = useLocation(); + const { occurrences } = useOccurrencesStore(); + const [startOfTheWeek, setStartOfTheWeek] = React.useState(() => { + const initialDate = state?.startDate || new Date(); + + return startOfWeek(startOfDay(initialDate)); + }); + + if (!state) { + return ( +
+

Week Calendar

+

+ Weekly calendar is only available when navigating from the month + calendar for now +

+
+ ); + } + + const { startDate }: { startDate: Date } = state; + + const days = eachDayOfInterval({ + start: startOfTheWeek, + end: addDays(startOfTheWeek, 6), + }); + + // console.log({ startDate, startOfTheWeek, days }); + + // const groupOccurrences = (dayIndex: number, hour: number) => { + // const day = dayIndex === 6 ? 0 : dayIndex + 1; + // + // const relatedOccurrences = occurrences.filter((o) => { + // const date = new Date(o.timestamp); + // return ( + // date.getFullYear() === year && + // date.getMonth() === month && + // date.getDate() === dates[dayIndex]?.day && + // date.getDay() === day && + // date.getHours() === hour + // ); + // }); + // + // if (hour === 0) { + // console.log('relatedOccurrences', relatedOccurrences); + // } + // return Object.entries(Object.groupBy(relatedOccurrences, (o) => o.habitId)); + // }; return ( -
-

Weekly Calendar

+
+

+ {/*Week {week} of {year}*/} + Weekly Calendar +

+

+ Coming soon +

+ {/*{[...Array(25)].map((_, hourIndex) => (*/} + {/* */} + {/* {[...Array(7)].map((_, dayIndex) => {*/} + {/* if (hourIndex === 0) {*/} + {/* return (*/} + {/* */} + {/*

{WEEK_DAYS[dayIndex]}

*/} + {/*
*/} + {/* );*/} + {/* }*/} + + {/* return (*/} + {/* */} + {/* {hourIndex > 1 && dayIndex === 0 && (*/} + {/*

*/} + {/* {hourIndex - 1}*/} + {/*

*/} + {/* )}*/} + {/*
*/} + {/* {groupOccurrences(dayIndex, hourIndex - 1).map(*/} + {/* ([habitId, habitOccurrences]) => {*/} + {/* if (!habitOccurrences) {*/} + {/* return null;*/} + {/* }*/} + + {/* return (*/} + {/* */} + {/* null}*/} + {/* />*/} + {/* */} + {/* );*/} + {/* }*/} + {/* )}*/} + {/*
*/} + {/*
*/} + {/* );*/} + {/* })}*/} + {/*
*/} + {/*))}*/}
); }; diff --git a/src/components/common/ConfirmDialog/ConfirmDialog.tsx b/src/components/common/ConfirmDialog/ConfirmDialog.tsx index e5e0dc3..dcef5c9 100644 --- a/src/components/common/ConfirmDialog/ConfirmDialog.tsx +++ b/src/components/common/ConfirmDialog/ConfirmDialog.tsx @@ -32,7 +32,7 @@ const ConfirmDialog = ({ {children}
-
+ setAddTraitModalOpen(false)} @@ -125,6 +123,7 @@ const AddHabitDialogButton = () => {