diff --git a/README.md b/README.md index 01d591b..876a1fa 100644 --- a/README.md +++ b/README.md @@ -47,11 +47,11 @@ This app showcases the use of the following tools and technologies: ## Roadmap - [x] **Dark Mode**: Switch between light and dark themes. +- [ ] **Weekly View**: View your habits on a weekly calendar. +- [ ] **Daily View**: Dive into your habits on a daily calendar. - [ ] **Export**: Export your habits and entries. - [ ] **Environments**: Associate habits with environments where they occur. - [ ] **Categories**: Group habits into categories. -- [ ] **Weekly View**: View your habits on a weekly calendar. -- [ ] **Daily View**: Dive into your habits on a daily calendar. - [ ] **Sharing**: Share your calendar with trusted people. - [ ] **Statistics**: Track your progress with insightful statistics. - [ ] **Notifications**: Get reminders to log your habits. diff --git a/src/components/App.tsx b/src/components/App.tsx index b764ca5..55ca56b 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -25,8 +25,14 @@ const App = () => {
- } /> - } /> + } + /> + } + /> } /> } /> } /> diff --git a/src/components/Providers.tsx b/src/components/Providers.tsx index 6bd6e0c..4f6eb4d 100644 --- a/src/components/Providers.tsx +++ b/src/components/Providers.tsx @@ -9,13 +9,17 @@ type ProviderProps = { children: ReactNode; }; -const LowerProviders = ({ children }: ProviderProps) => { +const LowerProviders = React.memo(function WrappedProvider({ + children, +}: ProviderProps) { const navigate = useNavigate(); return {children}; -}; +}); -const PotentialSupabaseProvider = ({ children }: ProviderProps) => { +const PotentialSupabaseProvider = React.memo(function WrappedProvider({ + children, +}: ProviderProps) { if (!Object.keys(supabaseClient).length) { return children; } @@ -25,17 +29,21 @@ const PotentialSupabaseProvider = ({ children }: ProviderProps) => { {children} ); -}; +}); -const UpperProviders = ({ children }: ProviderProps) => { +const UpperProviders = React.memo(function WrappedProvider({ + children, +}: ProviderProps) { return ( {children} ); -}; +}); -const Providers = ({ children }: ProviderProps) => { +const Providers = React.memo(function WrappedProviders({ + children, +}: ProviderProps) { return ( @@ -43,6 +51,6 @@ const Providers = ({ children }: ProviderProps) => { ); -}; +}); export default Providers; diff --git a/src/components/calendar-month/MonthCalendar.tsx b/src/components/calendar-month/MonthCalendar.tsx index 7221207..2ad15ea 100644 --- a/src/components/calendar-month/MonthCalendar.tsx +++ b/src/components/calendar-month/MonthCalendar.tsx @@ -1,14 +1,15 @@ -import { generateCalendarRange } from '@helpers'; import { useDocumentTitle } from '@hooks'; import { CalendarDate, GregorianCalendar } from '@internationalized/date'; import { useDisclosure } from '@nextui-org/react'; import { useOccurrencesStore } from '@stores'; import { capitalizeFirstLetter } from '@utils'; import clsx from 'clsx'; +import { endOfMonth, endOfWeek, startOfMonth, startOfWeek } from 'date-fns'; import React from 'react'; -import { type AriaButtonProps, useCalendar, useLocale } from 'react-aria'; -import { useLocation } from 'react-router-dom'; +import { useCalendar, useLocale } from 'react-aria'; +import { useParams } from 'react-router-dom'; import { useCalendarState } from 'react-stately'; +import { useShallow } from 'zustand/react/shallow'; import MonthCalendarGrid from './MonthCalendarGrid'; import MonthCalendarHeader from './MonthCalendarHeader'; @@ -25,14 +26,15 @@ const createCalendar = (identifier: string) => { }; const MonthCalendar = () => { - const { onRangeChange } = useOccurrencesStore(); + const onRangeChange = useOccurrencesStore( + useShallow((state) => state.onRangeChange) + ); const { locale } = useLocale(); const calendarState = useCalendarState({ locale, createCalendar, }); - const { calendarProps, prevButtonProps, nextButtonProps, title } = - useCalendar({}, calendarState); + const { calendarProps, title } = useCalendar({}, calendarState); const { isOpen: isNoteDialogOpen, onOpen: openNoteDialog, @@ -44,38 +46,35 @@ const MonthCalendar = () => { onClose: closeOccurrenceDialog, } = useDisclosure(); const [activeDate, setActiveDate] = React.useState(null); - const { state: locationState } = useLocation(); - - const setFocusedDate = React.useCallback( - (year: number, month: number, day: number) => { - const nextFocusedDate = new CalendarDate(year, month, day); - calendarState.setFocusedDate(nextFocusedDate); - }, - [calendarState] - ); + const params = useParams(); React.useEffect(() => { - if (!locationState) { + const { year, month, day } = params; + + if (!year || !month || !day) { return; } - const { year, month } = locationState; + const focusedDate = new Date(Number(year), Number(month) - 1, 1); - setFocusedDate(year, month, 1); - }, [locationState, setFocusedDate]); + const rangeStart = startOfWeek(startOfMonth(focusedDate)); + const rangeEnd = endOfWeek(endOfMonth(focusedDate)); - React.useEffect(() => { - onRangeChange( - generateCalendarRange( - calendarState.visibleRange.start.year, - calendarState.visibleRange.start.month - ) + onRangeChange([+rangeStart, +rangeEnd]); + + const nextFocusedDate = new CalendarDate( + focusedDate.getFullYear(), + focusedDate.getMonth() + 1, + focusedDate.getDate() ); - }, [ - calendarState.visibleRange.start.year, - calendarState.visibleRange.start.month, - onRangeChange, - ]); + + const hasFocusedDateChanged = + calendarState.focusedDate.toString() !== nextFocusedDate.toString(); + + if (hasFocusedDateChanged) { + calendarState.setFocusedDate(nextFocusedDate); + } + }, [params, calendarState, onRangeChange]); const [activeMonthLabel, activeYear] = title.split(' '); @@ -83,24 +82,6 @@ const MonthCalendar = () => { `${activeMonthLabel.slice(0, 3)} ${activeYear} | Habitrack Calendar` ); - const navigateToMonth = (month: number) => { - const { year, day } = calendarState.focusedDate; - setFocusedDate(year, month, day); - }; - - const navigateToYear = (year: number) => { - const { month, day } = calendarState.focusedDate; - setFocusedDate(year, month, day); - }; - - const resetFocusedDate = () => { - const now = new Date(); - const day = now.getDate(); - const month = now.getMonth(); - const year = now.getFullYear(); - setFocusedDate(year, month + 1, day); - }; - const handleOccurrenceModalClose = () => { window.setTimeout(() => { closeOccurrenceDialog(); @@ -133,13 +114,6 @@ const MonthCalendar = () => { setActiveDate(new Date(fullYear, monthIndex - 1, dateNumber, 12)); }; - const transformButtonProps = ( - buttonProps: Pick, 'isDisabled' | 'aria-label'> - ) => ({ - 'aria-label': buttonProps['aria-label'] || '', - disabled: Boolean(buttonProps.isDisabled), - }); - const calendarContainerClassName = clsx( 'flex h-full w-full max-w-full flex-1 flex-col gap-2 p-0 px-8 pb-8 lg:gap-4 lg:px-16 lg:py-4', isOccurrenceDialogOpen && 'pointer-events-none' @@ -151,13 +125,6 @@ const MonthCalendar = () => { void; - onAddOccurrence: ( - dateNumber: number, - monthNumber: number, - fullYear: number - ) => void; - onNavigateBack?: () => void; - onNavigateForward?: () => void; + state: CalendarState; + date: CalendarDate; + visibleMonth: Date; + onAddNote: () => void; + onAddOccurrence: () => void; rangeStatus: CellRangeStatus; position: CellPosition; }; const MonthCalendarCell = ({ - dateNumber, - monthNumber, - fullYear, - onNavigateBack, - onNavigateForward, + // state, + date, + visibleMonth, onAddNote, onAddOccurrence, rangeStatus, position, }: CalendarCellProps) => { const cellRef = React.useRef(null); + // const cellProps = useCalendarCell({ date }, state, cellRef); const user = useUser(); const { removeOccurrence, fetchingOccurrences, occurrencesByDate } = useOccurrencesStore(); const { notes, fetchingNotes } = useNotesStore(); - const screenSize = useScreenSize(); - const cellDate = new Date(fullYear, monthNumber - 1, dateNumber); + const { isDesktop, isMobile } = useScreenWidth(); + const cellDate = new Date(date.year, date.month - 1, date.day); const isTodayCell = isToday(cellDate); const isFutureCell = isFuture(cellDate); - const date = format(cellDate, 'yyyy-MM-dd'); - const isDesktop = screenSize >= 1024; + const formattedDay = format(cellDate, 'yyyy-MM-dd'); + const navigate = useNavigate(); - const occurrences = isCalendarDay(date) ? occurrencesByDate[date] || [] : []; - const isMobile = screenSize < 768; - const hasNote = notes.some((note) => note.day === date); + const occurrences = isCalendarDay(formattedDay) + ? occurrencesByDate[formattedDay] || [] + : []; + const hasNote = notes.some((note) => note.day === formattedDay); const groupedOccurrences = Object.groupBy(occurrences, (o) => o.habitId); @@ -79,45 +73,46 @@ const MonthCalendarCell = ({ return null; } - return onAddNote(dateNumber, monthNumber, fullYear); - }, [fetchingOccurrences, user, dateNumber, monthNumber, fullYear, onAddNote]); + return onAddNote(); + }, [fetchingOccurrences, user, onAddNote]); const handleAddOccurrenceClick = React.useCallback( - (e?: React.MouseEvent) => { + (e?: React.MouseEvent, forceOpenDialog = false) => { if (fetchingOccurrences || !user) { return null; } if (!isTodayCell) { if (rangeStatus === 'below-range') { - return onNavigateBack?.(); + const prevMonth = startOfMonth(addMonths(visibleMonth, -1)); + + return navigate( + `/calendar/month/${prevMonth.getFullYear()}/${prevMonth.getMonth() + 1}/1` + ); } if (rangeStatus === 'above-range') { - return onNavigateForward?.(); + const nextMonth = startOfMonth(addMonths(visibleMonth, 1)); + + return navigate( + `/calendar/month/${nextMonth.getFullYear()}/${nextMonth.getMonth() + 1}/1` + ); } } - if ( - !isFutureCell && - (isMobile || e?.currentTarget instanceof HTMLButtonElement) - ) { - return onAddOccurrence(dateNumber, monthNumber, fullYear); + if (!isFutureCell || forceOpenDialog) { + return onAddOccurrence(); } }, [ - dateNumber, fetchingOccurrences, - fullYear, - monthNumber, onAddOccurrence, - onNavigateBack, - onNavigateForward, rangeStatus, user, - isMobile, isTodayCell, isFutureCell, + visibleMonth, + navigate, ] ); @@ -130,7 +125,7 @@ const MonthCalendarCell = ({ const enterHandler = (event: KeyboardEvent) => { if (event.key === 'Enter') { - handleAddOccurrenceClick(); + handleAddOccurrenceClick(undefined, true); } }; @@ -177,13 +172,14 @@ const MonthCalendarCell = ({ return (
handleAddOccurrenceClick(e)} >
-

{dateNumber}

+

{date.day}

{rangeStatus === 'in-range' && !isMobile && (
@@ -192,7 +188,7 @@ const MonthCalendarCell = ({ @@ -136,15 +127,20 @@ const MonthCalendarGrid = ({ const { month, day, year } = calendarDate; - const rangeStatus: CellRangeStatus = - (month < activeMonth || - (month === 12 && activeMonth === 1)) && - month !== 1 + const date = new Date(year, month - 1, day); + const prevMonth = addMonths(visibleMonth, -1); + const nextMonth = addMonths(visibleMonth, 1); + + const rangeStatus: CellRangeStatus = isSameMonth( + date, + visibleMonth + ) + ? 'in-range' + : isSameMonth(date, prevMonth) ? 'below-range' - : month > activeMonth || - (month === 1 && activeMonth === 12) + : isSameMonth(date, nextMonth) ? 'above-range' - : 'in-range'; + : ''; const [cellKey] = calendarDate.toString().split('T'); @@ -153,15 +149,15 @@ const MonthCalendarGrid = ({ return ( + onAddOccurrence(day, month, year) + } + onAddNote={() => onAddNote(day, month, year)} rangeStatus={rangeStatus} position={position} - onNavigateBack={state.focusPreviousPage} - onNavigateForward={state.focusNextPage} /> ); })} diff --git a/src/components/calendar-month/MonthCalendarHeader.test.tsx b/src/components/calendar-month/MonthCalendarHeader.test.tsx index f14c14e..92d30d3 100644 --- a/src/components/calendar-month/MonthCalendarHeader.test.tsx +++ b/src/components/calendar-month/MonthCalendarHeader.test.tsx @@ -9,55 +9,10 @@ describe(MonthCalendarHeader.name, () => { const props: MonthCalendarHeaderProps = { activeMonthLabel: 'January', activeYear: '2022', - prevButtonProps: { - disabled: false, - 'aria-label': 'Previous month', - }, - nextButtonProps: { - disabled: false, - 'aria-label': 'Next month', - }, - onNavigateBack: jest.fn(), - onNavigateForward: jest.fn(), - onNavigateToMonth: jest.fn(), - onNavigateToYear: jest.fn(), - onResetFocusedDate: jest.fn(), }; it.skip('should render month and year', () => { const { getByText } = render(); expect(getByText('January 2022')).toBeInTheDocument(); }); - - it.skip('should disable previous button', () => { - const { getByRole } = render( - - ); - expect(getByRole('navigate-back')).toBeDisabled(); - }); - - it.skip('should disable next button', () => { - const { getByRole } = render( - - ); - expect(getByRole('navigate-forward')).toBeDisabled(); - }); - - it.skip('should call onNavigateBack', () => { - const { getByRole } = render(); - getByRole('navigate-back').click(); - expect(props.onNavigateBack).toHaveBeenCalled(); - }); - - it.skip('should call onNavigateForward', () => { - const { getByRole } = render(); - getByRole('navigate-forward').click(); - expect(props.onNavigateForward).toHaveBeenCalled(); - }); }); diff --git a/src/components/calendar-month/MonthCalendarHeader.tsx b/src/components/calendar-month/MonthCalendarHeader.tsx index c1bad12..a18a6fa 100644 --- a/src/components/calendar-month/MonthCalendarHeader.tsx +++ b/src/components/calendar-month/MonthCalendarHeader.tsx @@ -1,5 +1,5 @@ import { TraitChip } from '@components'; -import { useScreenSize } from '@hooks'; +import { useScreenWidth } from '@hooks'; import type { Habit, Trait } from '@models'; import type { SelectedItems } from '@nextui-org/react'; import { @@ -9,28 +9,22 @@ import { Button, SelectSection, } from '@nextui-org/react'; -import { ArrowFatLeft, ArrowFatRight } from '@phosphor-icons/react'; +import { + ArrowFatLeft, + ArrowFatRight, + ArrowsClockwise, +} from '@phosphor-icons/react'; import { useTraitsStore, useHabitsStore, useOccurrencesStore } from '@stores'; import { useUser } from '@supabase/auth-helpers-react'; import { getHabitIconUrl } from '@utils'; import clsx from 'clsx'; +import { addMonths, startOfToday, startOfMonth } from 'date-fns'; import React from 'react'; - -type NavigationButtonProps = { - disabled: boolean; - 'aria-label': string; -}; +import { Link, useNavigate, useParams } from 'react-router-dom'; export type MonthCalendarHeaderProps = { activeMonthLabel: string; activeYear: string; - prevButtonProps: NavigationButtonProps; - nextButtonProps: NavigationButtonProps; - onNavigateBack: () => void; - onNavigateForward: () => void; - onNavigateToMonth: (month: number) => void; - onNavigateToYear: (year: number) => void; - onResetFocusedDate: () => void; }; const MONTHS = [ @@ -53,20 +47,29 @@ const YEARS = Array.from({ length: 31 }, (_, i) => 2000 + i); const MonthCalendarHeader = ({ activeMonthLabel, activeYear, - prevButtonProps, - nextButtonProps, - onNavigateBack, - onNavigateForward, - onNavigateToMonth, - onNavigateToYear, - onResetFocusedDate, }: MonthCalendarHeaderProps) => { const { habits } = useHabitsStore(); const { traits } = useTraitsStore(); const { filteredBy, filterBy } = useOccurrencesStore(); const user = useUser(); - const screenSize = useScreenSize(); - const isOnCurrentMonth = activeMonthLabel === MONTHS[new Date().getMonth()]; + const { screenWidth, isDesktop, isMobile } = useScreenWidth(); + const isOnCurrentMonth = + activeMonthLabel === MONTHS[new Date().getMonth()] && + activeYear === new Date().getFullYear().toString(); + const { year, month, day } = useParams(); + const navigate = useNavigate(); + + const focusedDate = React.useMemo(() => { + if (!year || !month || !day) { + return new Date(); + } + + return new Date(Number(year), Number(month) - 1, Number(day)); + }, [year, month, day]); + + const prevMonth = startOfMonth(addMonths(focusedDate, -1)); + const nextMonth = startOfMonth(addMonths(focusedDate, 1)); + const today = startOfToday(); const shouldRenderFilters = !!user && habits.length > 0 && traits.length > 0; @@ -77,13 +80,17 @@ const MonthCalendarHeader = ({ const handleMonthChange: React.ChangeEventHandler = ( event ) => { - onNavigateToMonth(MONTHS.indexOf(event.target.value) + 1); + navigate( + `/calendar/month/${focusedDate.getFullYear()}/${MONTHS.indexOf(event.target.value) + 1}/${focusedDate.getDate()}` + ); }; const handleYearChange: React.ChangeEventHandler = ( event ) => { - onNavigateToYear(+event.target.value); + navigate( + `/calendar/month/${event.target.value}/${focusedDate.getMonth() + 1}/${focusedDate.getDate()}` + ); }; const handleHabitsFilterChange: React.ChangeEventHandler< @@ -104,9 +111,6 @@ const MonthCalendarHeader = ({ }); }; - const isMobile = screenSize < 768; - const isDesktop = screenSize > 1024; - return (
@@ -148,20 +152,21 @@ const MonthCalendarHeader = ({ }} > {YEARS.map((year) => ( - {year.toString()} + + {year.toString()} + ))}
)}
diff --git a/src/components/calendar-week/WeekCalendar.tsx b/src/components/calendar-week/WeekCalendar.tsx index 0bbd869..0ac175a 100644 --- a/src/components/calendar-week/WeekCalendar.tsx +++ b/src/components/calendar-week/WeekCalendar.tsx @@ -1,5 +1,3 @@ -import { Button } from '@nextui-org/react'; -import { ArrowFatLeft } from '@phosphor-icons/react'; import { useOccurrencesStore } from '@stores'; import { addDays, @@ -15,24 +13,26 @@ import { } from 'date-fns'; import { motion } from 'framer-motion'; import React from 'react'; -import { Link, useLocation } from 'react-router-dom'; +import { useParams } 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 { year, month, day } = useParams(); const { occurrences } = useOccurrencesStore(); const [startOfTheWeek, setStartOfTheWeek] = React.useState(new Date()); React.useEffect(() => { - if (!state) { + if (!year || !month || !day) { return; } - setStartOfTheWeek(startOfWeek(startOfDay(state.startDate || new Date()))); - }, [state]); + const date = new Date(Number(year), Number(month) - 1, Number(day)); + + setStartOfTheWeek(startOfWeek(startOfDay(date))); + }, [year, month, day]); const days = eachDayOfInterval({ start: startOfTheWeek, @@ -71,35 +71,8 @@ const WeekCalendar = () => { [days, occurrencesInWeek] ); - if (!state) { - return ( -
-

Week Calendar

-

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

-
- ); - } - - const { prevPathname, month, year } = state; - return ( -
- +

Week {getWeek(startOfTheWeek)} of {getISOWeekYear(startOfTheWeek)} @@ -113,10 +86,15 @@ const WeekCalendar = () => { const weekDayName = WEEK_DAYS[getDay(day) - 1] || WEEK_DAYS[6]; return ( -
-

- {weekDayName} -

+
+
+

+ {weekDayName} +

+
+ {day.getDate()} +
+
{eachMinuteOfInterval( { @@ -133,11 +111,11 @@ const WeekCalendar = () => { className="group/minutes-cell relative flex gap-4" > {dayIndex === 0 && ( -

+

{hour !== 0 && hour}

)} -
+
{groupOccurrences(dayIndex, hour).map( ([habitId, habitOccurrences]) => { if (!habitOccurrences) { diff --git a/src/components/habit/habits-page/HabitsPage.test.tsx b/src/components/habit/habits-page/HabitsPage.test.tsx index ce0859d..4285b9b 100644 --- a/src/components/habit/habits-page/HabitsPage.test.tsx +++ b/src/components/habit/habits-page/HabitsPage.test.tsx @@ -40,7 +40,11 @@ jest.mock('@hooks', () => ({ .fn() .mockReturnValue(['', jest.fn(), jest.fn(), jest.fn()]), useFileField: jest.fn().mockReturnValue([null, jest.fn(), jest.fn()]), - useScreenSize: jest.fn(), + useScreenWidth: jest.fn().mockReturnValue({ + screenWidth: 1400, + isMobile: false, + isDesktop: true, + }), })); describe(HabitsPage.name, () => { diff --git a/src/components/habit/habits-page/HabitsPage.tsx b/src/components/habit/habits-page/HabitsPage.tsx index d300d75..df031c1 100644 --- a/src/components/habit/habits-page/HabitsPage.tsx +++ b/src/components/habit/habits-page/HabitsPage.tsx @@ -4,7 +4,7 @@ import { EditHabitDialog, TraitChip, } from '@components'; -import { useDocumentTitle, useScreenSize } from '@hooks'; +import { useDocumentTitle, useScreenWidth } from '@hooks'; import { type Habit } from '@models'; import { Button, @@ -69,7 +69,7 @@ const HabitsPage = () => { const { removeOccurrencesByHabitId } = useOccurrencesStore(); const [habitToEdit, setHabitToEdit] = React.useState(null); const [habitToRemove, setHabitToRemove] = React.useState(null); - const screenSize = useScreenSize(); + const { isMobile } = useScreenWidth(); useDocumentTitle('My Habits | Habitrack'); @@ -99,8 +99,6 @@ const HabitsPage = () => { setHabitToEdit(null); }; - const isMobile = screenSize < 768; - return ( <>

diff --git a/src/components/header/Header.tsx b/src/components/header/Header.tsx index 47f1022..0a7f8b5 100644 --- a/src/components/header/Header.tsx +++ b/src/components/header/Header.tsx @@ -1,5 +1,5 @@ import { AuthModalButton } from '@components'; -import { useScreenSize, useFetchOnAuth } from '@hooks'; +import { useScreenWidth, useFetchOnAuth } from '@hooks'; import { Button, Tooltip, Spinner } from '@nextui-org/react'; import { GithubLogo } from '@phosphor-icons/react'; import { useSessionContext } from '@supabase/auth-helpers-react'; @@ -11,7 +11,7 @@ import ThemeToggle from './ThemeToggle'; const Header = () => { useFetchOnAuth(); - const screenSize = useScreenSize(); + const { screenWidth, isMobile, isDesktop } = useScreenWidth(); const session = useSessionContext(); return ( @@ -36,8 +36,8 @@ const Header = () => { color="primary" as={Link} to="/calendar/month" - size={screenSize > 1024 ? 'md' : 'sm'} - className={screenSize < 339 ? 'min-w-fit px-2' : ''} + size={isDesktop ? 'md' : 'sm'} + className={screenWidth < 339 ? 'min-w-fit px-2' : ''} > Calendar @@ -46,16 +46,16 @@ const Header = () => { variant="flat" as={Link} to="/habits" - size={screenSize > 1024 ? 'md' : 'sm'} + size={isDesktop ? 'md' : 'sm'} className={clsx( 'dark:text-secondary-800', - screenSize < 339 && 'min-w-fit px-2' + screenWidth < 339 && 'min-w-fit px-2' )} > Habits - {screenSize > 768 && ( + {!isMobile && ( { as={Link} to="https://github.com/domhhv/habitrack" target="_blank" - size={screenSize > 1024 ? 'md' : 'sm'} + size={isDesktop ? 'md' : 'sm'} > - 1024 ? 20 : 16} /> + )} diff --git a/src/components/header/ThemeToggle.tsx b/src/components/header/ThemeToggle.tsx index b6860b0..ee552cd 100644 --- a/src/components/header/ThemeToggle.tsx +++ b/src/components/header/ThemeToggle.tsx @@ -1,4 +1,4 @@ -import { ThemeMode, useScreenSize, useThemeMode } from '@hooks'; +import { ThemeMode, useScreenWidth, useThemeMode } from '@hooks'; import { ButtonGroup, Button } from '@nextui-org/react'; import { SunDim as SunIcon, @@ -17,7 +17,7 @@ const modesToIcons = { const ThemeToggle = () => { const { themeMode, setThemeMode } = useThemeMode(); - const screenSize = useScreenSize(); + const { screenWidth } = useScreenWidth(); const handleThemeChange = (newThemeMode: ThemeMode) => () => { setThemeMode(newThemeMode); @@ -42,7 +42,7 @@ const ThemeToggle = () => { isIconOnly variant="flat" color="secondary" - size={screenSize > 1024 ? 'md' : 'sm'} + size={screenWidth > 1024 ? 'md' : 'sm'} > { const user = useUser(); - const screenSize = useScreenSize(); + const { screenWidth } = useScreenWidth(); const { showSnackbar } = useSnackbarsStore(); const { isOpen, onOpen, onOpenChange, onClose } = useDisclosure(); const [authenticating, setAuthenticating] = React.useState(false); @@ -114,16 +114,16 @@ const AuthModalButton = () => { return ( <> {user?.id ? ( - 1024 ? 'md' : 'sm'}> + 1024 ? 'md' : 'sm'}>