Merge branch 'main' into calender-nav

This commit is contained in:
Lucid Kobold
2022-03-25 23:53:17 -05:00
3 changed files with 25 additions and 2 deletions

View File

@@ -2,12 +2,13 @@ import React, { useContext } from "react";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { HStack, IconButton } from "@chakra-ui/react"; import { HStack, IconButton } from "@chakra-ui/react";
import { Icon } from "@iconify/react"; import { Icon } from "@iconify/react";
import { sub, add, format } from "date-fns"; import { sub, add, format, isSameMonth } from "date-fns";
import DatePicker from "./DatePicker"; import DatePicker from "./DatePicker";
import { CalenderContext } from "../../contexts/CalenderContext"; import { CalenderContext } from "../../contexts/CalenderContext";
const CalenderNav = (): JSX.Element => { const CalenderNav = (): JSX.Element => {
const { selectedDate } = useContext(CalenderContext); const { selectedDate, validDateRange } = useContext(CalenderContext);
const { start: validStart, end: validEnd } = validDateRange;
const router = useRouter(); const router = useRouter();
@@ -43,12 +44,14 @@ const CalenderNav = (): JSX.Element => {
return ( return (
<HStack spacing={10} as="nav" w="auto" h="10vh" textAlign="center"> <HStack spacing={10} as="nav" w="auto" h="10vh" textAlign="center">
<IconButton <IconButton
isDisabled={isSameMonth(selectedDate, validStart)}
aria-label="Previous Month" aria-label="Previous Month"
icon={<Icon icon="akar-icons:chevron-left" />} icon={<Icon icon="akar-icons:chevron-left" />}
onClick={() => handleNavButtons("prev")} onClick={() => handleNavButtons("prev")}
/> />
<DatePicker /> <DatePicker />
<IconButton <IconButton
isDisabled={isSameMonth(selectedDate, validEnd)}
aria-label="Next Month" aria-label="Next Month"
icon={<Icon icon="akar-icons:chevron-right" />} icon={<Icon icon="akar-icons:chevron-right" />}
onClick={() => handleNavButtons("next")} onClick={() => handleNavButtons("next")}

View File

@@ -208,6 +208,19 @@ const CalenderContextProvider = ({
// TODO: Make a function that will give the valid date range for the front end. Either starting at the chart creation date or the oldest month with stickers (when enabled in filters). // TODO: Make a function that will give the valid date range for the front end. Either starting at the chart creation date or the oldest month with stickers (when enabled in filters).
const setValidDateRange = (): ValidDateRange => {
const currDate = new Date(); // Current date.
const startDate = startOfMonth(currDate); // Will eventually be the creation date of the account or the creation date of the oldest chart within the account. Whichever is older.
const endDate = endOfMonth(currDate); // Always needs to be the last day on the current month within the current year.
return {
start: startDate,
end: endDate
};
};
const [validDateRange] = useState<ValidDateRange>(setValidDateRange());
// TODO: Add a function that validated if a date has at least one sticker in it. Use that within the nav function (when filter is enabled). // TODO: Add a function that validated if a date has at least one sticker in it. Use that within the nav function (when filter is enabled).
// TODO: Add a function that will give the closest date, if available, when the nav func detects an empty month. // TODO: Add a function that will give the closest date, if available, when the nav func detects an empty month.
@@ -246,6 +259,7 @@ const CalenderContextProvider = ({
selectedDate, selectedDate,
title: selectedDateInfo.title, title: selectedDateInfo.title,
layout: selectedDateInfo.layout, layout: selectedDateInfo.layout,
validDateRange,
updateDate updateDate
}; };

View File

@@ -48,6 +48,11 @@ interface MonthContext extends MonthInfo {
layout: MonthLayout; layout: MonthLayout;
} }
interface ValidDateRange {
start: Date;
end: Date;
}
interface UpdateCalendarProps { interface UpdateCalendarProps {
year: number; year: number;
month: number; month: number;
@@ -58,5 +63,6 @@ interface CalenderContextState {
selectedDate: Date; selectedDate: Date;
title: string; title: string;
layout: MonthLayout; layout: MonthLayout;
validDateRange: ValidDateRange;
updateDate: (input: UpdateCalendarProps) => void; updateDate: (input: UpdateCalendarProps) => void;
} }