diff --git a/components/calender/index.tsx b/components/calender/index.tsx index ec727d6..3a4dc03 100644 --- a/components/calender/index.tsx +++ b/components/calender/index.tsx @@ -7,7 +7,7 @@ import CalenderNav from "./CalenderNav"; import Day from "./Day"; const Calender = (newDate?: UpdateCalendarProps): JSX.Element => { - const { selectedDate, layout, updateDate, currDate } = useContext(CalenderContext); + const { selectedDate, layout, updateDate, currDate, setCurrDate } = useContext(CalenderContext); const { stickersMonth } = useContext(StickersContext); useEffect(() => { @@ -22,6 +22,14 @@ const Calender = (newDate?: UpdateCalendarProps): JSX.Element => { } }, [newDate, updateDate]); + useEffect(() => { + console.info("Check to update date."); + if (!isSameDay(currDate, new Date())) { + console.info("Updated date.") + setCurrDate(new Date()); + } + }, [currDate, setCurrDate]); + // Simulated user settings context const userSettings = { theme: "default", diff --git a/contexts/CalenderContext.tsx b/contexts/CalenderContext.tsx index a558f80..799bba3 100644 --- a/contexts/CalenderContext.tsx +++ b/contexts/CalenderContext.tsx @@ -241,10 +241,11 @@ const CalenderContextProvider = ({ }; // * Attempting to fix an issue with static generation where the date does not appear to be updating after initial generation. - const [currDate] = useState(new Date); + const [currDate, setCurrDate] = useState(new Date); const calenderContextValues: CalenderContextState = { currDate, + setCurrDate, selectedDate, title: selectedDateInfo.title, layout: selectedDateInfo.layout, diff --git a/types/CalenderContext.d.ts b/types/CalenderContext.d.ts index a3e0f71..946a3fd 100644 --- a/types/CalenderContext.d.ts +++ b/types/CalenderContext.d.ts @@ -56,6 +56,7 @@ interface UpdateCalendarProps { interface CalenderContextState { currDate: Date; + setCurrDate: React.Dispatch>; selectedDate: Date; title: string; layout: MonthLayout;