Attempted to force the app to stay within the valid date ranges. This caused app crashed due to infinite useEffect loops. Added documentation.

This commit is contained in:
Lucid Kobold
2022-03-26 02:49:14 -05:00
parent 39b9a13e39
commit d8c9db9475
4 changed files with 70 additions and 33 deletions

View File

@@ -2,7 +2,7 @@ import React, { useContext } from "react";
import { useRouter } from "next/router";
import { HStack, IconButton } from "@chakra-ui/react";
import { Icon } from "@iconify/react";
import { sub, add, format, isSameMonth } from "date-fns";
import { format, isSameMonth, addMonths, subMonths } from "date-fns";
import findValidDateRange from "../../lib/findValidDateRange";
import DatePicker from "./DatePicker";
import { CalenderContext } from "../../contexts/CalenderContext";
@@ -17,18 +17,14 @@ const CalenderNav = (): JSX.Element => {
const handleNavButtons = (direction: "next" | "prev") => {
if (direction === "next") {
const newMonth = add(selectedDate, {
months: 1
});
const newMonth = addMonths(selectedDate, 1);
const year = format(newMonth, "y");
const month = format(newMonth, "L");
router.push(`/calendar/${year}/${month}`);
} else if (direction === "prev") {
const newMonth = sub(selectedDate, {
months: 1
});
const newMonth = subMonths(selectedDate, 1);
const year = format(newMonth, "y");
const month = format(newMonth, "L");