diff --git a/components/calender/Day.tsx b/components/calender/Day.tsx index c6a3ddc..1ec205f 100644 --- a/components/calender/Day.tsx +++ b/components/calender/Day.tsx @@ -1,57 +1,75 @@ import { Box, Text } from "@chakra-ui/react"; -import { add, getYear, getMonth, sub, getDate,format } from "date-fns"; +import { add, getYear, getMonth, sub, getDate } from "date-fns"; import router from "next/router"; import React, { Fragment } from "react"; import AddSticker from "./modals/AddSticker"; -const Day = ( - isOverflow: boolean, - date: Date, - overflowDirection: "next" | "prev" | null, - selectedDate: Date -) => { +interface DayProps { + isOverflow?: boolean; + overflowDirection?: "next" | "prev" | null; + sticker: -2 | -1 | 0 | 1 | 2 | null; + date: Date; + selectedDate: Date; +} + +const Day = (props: DayProps): JSX.Element => { + const { isOverflow, overflowDirection, /*sticker,*/ date, selectedDate } = + props; + + const handleNav = (direction: "next" | "prev") => { + if (direction === "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 (direction === "prev") { + const newMonth = sub(selectedDate, { months: 1 }); + + const year = getYear(newMonth); + const month = getMonth(newMonth) + 1; + + router.push(`/calendar/${year}/${month}`); + } + }; + return ( {isOverflow && ( { - 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}`); - } - } - })} + _hover={{ + cursor: "pointer" + }} + onClick={() => handleNav(overflowDirection)} > - {!isOverflow && } {`Day ${getDate(date)}`} )} + {!isOverflow && ( + + {`Day ${getDate(date)}`} + + + )} ); }; diff --git a/components/calender/index.tsx b/components/calender/index.tsx index 7a5d54f..0e92782 100644 --- a/components/calender/index.tsx +++ b/components/calender/index.tsx @@ -2,9 +2,8 @@ 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 { getDate, sub, add, getYear, getMonth } from "date-fns"; -import { useRouter } from "next/router"; -import AddSticker from "./modals/AddSticker"; +import { format } from "date-fns"; +import Day from "./Day"; // TODO: import types interface UpdateCalendarProps { @@ -15,7 +14,6 @@ interface UpdateCalendarProps { const Calender = (newDate?: UpdateCalendarProps): JSX.Element => { const { selectedDate, layout, updateDate } = useContext(CalenderContext); - const router = useRouter(); useEffect(() => { if (newDate) { @@ -82,48 +80,56 @@ const Calender = (newDate?: UpdateCalendarProps): JSX.Element => { {Object.keys(month).map((week) => { const thisWeek = month[week]; - return thisWeek.map((day) => { - const { date, isOverflow, overflowDirection } = day; + return thisWeek.map((day: MonthDay) => { + const { sticker, date, isOverflow, overflowDirection } = day; return ( - { - if (overflowDirection === "next") { - console.log(overflowDirection); - const newMonth = add(selectedDate, { months: 1 }); + + // { + // if (overflowDirection === "next") { + // console.log(overflowDirection); + // const newMonth = add(selectedDate, { months: 1 }); - const year = getYear(newMonth); - const month = getMonth(newMonth) + 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 }); + // router.push(`/calendar/${year}/${month}`); + // } else if (overflowDirection === "prev") { + // const newMonth = sub(selectedDate, { months: 1 }); - const year = getYear(newMonth); - const month = getMonth(newMonth) + 1; + // const year = getYear(newMonth); + // const month = getMonth(newMonth) + 1; - router.push(`/calendar/${year}/${month}`); - } - } - })} - > - - {!isOverflow && } - {`Day ${getDate(date)}`} - - + // router.push(`/calendar/${year}/${month}`); + // } + // } + // })} + // > + // + // {!isOverflow && } + // {`Day ${getDate(date)}`} + // + // ); }); })} diff --git a/components/calender/modals/AddSticker.tsx b/components/calender/modals/AddSticker.tsx index 10ead41..1f6552d 100644 --- a/components/calender/modals/AddSticker.tsx +++ b/components/calender/modals/AddSticker.tsx @@ -16,7 +16,10 @@ const AddSticker = (): JSX.Element => { return ( - + {/** + * TODO: Add prop that will be the trigger for opening the modal. + * + */} setIsOpen(!isOpen)}>