import React, { useContext, useEffect } from "react"; import { Box, HStack, SimpleGrid, Text, VStack } from "@chakra-ui/react"; import CalenderNav from "./CalenderNav"; import { CalenderContext } from "../../contexts/CalenderContext"; import { format } from "date-fns"; import Day from "./Day"; // TODO: import types const Calender = (newDate?: UpdateCalendarProps): JSX.Element => { const { selectedDate, layout, updateDate } = useContext(CalenderContext); useEffect(() => { if (newDate) { const { year, month, day } = newDate; if (year > 0 && month > 0 && day > 0) { updateDate(newDate); } else { console.warn("Invalid date format: ", newDate); } } }, [newDate, updateDate]); // Simulated user settings context const userSettings = { theme: "default", startOfWeek: "Sunday" }; const currMonth = layout[`${userSettings.startOfWeek.toLowerCase()}`]; const { month, weekdays } = currMonth; return ( {weekdays.map((weekDay) => { return ( {weekDay} ); })} {Object.keys(month).map((week) => { const thisWeek = month[week]; return thisWeek.map((day: MonthDay) => { const { sticker, date, isOverflow, overflowDirection } = day; return ( // { // if (overflowDirection === "next") { // console.log(overflowDirection); // const newMonth = add(selectedDate, { months: 1 }); // const year = getYear(newMonth); // const month = getMonth(newMonth) + 1; // router.push(`/calendar/${year}/${month}`); // } else if (overflowDirection === "prev") { // const newMonth = sub(selectedDate, { months: 1 }); // const year = getYear(newMonth); // const month = getMonth(newMonth) + 1; // router.push(`/calendar/${year}/${month}`); // } // } // })} // > // // {!isOverflow && } // {`Day ${getDate(date)}`} // // ); }); })} ); }; export default Calender;