diff --git a/src/app/(site)/(internal)/dashboard/calendar/components/DreamCalendar.tsx b/src/app/(site)/(internal)/dashboard/calendar/components/DreamCalendar.tsx index b53a3cb..bf23fdf 100644 --- a/src/app/(site)/(internal)/dashboard/calendar/components/DreamCalendar.tsx +++ b/src/app/(site)/(internal)/dashboard/calendar/components/DreamCalendar.tsx @@ -12,6 +12,9 @@ import {SelectItem} from "@nextui-org/react"; import DreamCalendarDay from "@/app/(site)/(internal)/dashboard/calendar/components/DreamCalendarDay"; import {useDreamsData} from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/DreamsProvider"; import useDayDreams from "@/app/(site)/(internal)/dashboard/(your-dreams)/components/dreams/hooks/useDayDreams"; +import {Button} from "@nextui-org/button"; +import DoubleBackIcon from "@/app/(site)/components/icons/DoubleBackIcon"; +import DoubleForwardIcon from "@/app/(site)/components/icons/DoubleForwardIcon"; const DreamCalendar: FC = () => { const [[currentYear, currentMonth], setCurrentYearAndMonth] = useState<[number, number]>([new Date().getFullYear(), new Date().getMonth() + 1]); @@ -29,16 +32,63 @@ const DreamCalendar: FC = () => { ...nextMonthDays ]; - const selectMonths = useMemo(() => getMonthDropdownOptions(), []) - const selectYears = useMemo(() => getYearDropdownOptions(new Date().getUTCFullYear()), []) const {dreams, tags, characters} = useDreamsData() const dayDreams = useDayDreams({dreams: dreams.data}) + const earliestYear = useMemo(() => dayDreams.length ? new Date(dayDreams[0].timestamp).getFullYear() : undefined, [dayDreams]) + + const selectMonths = useMemo(() => getMonthDropdownOptions(), []) + const selectYears = useMemo(() => getYearDropdownOptions(new Date().getUTCFullYear(), { + startingYear: earliestYear + }), [earliestYear]) + + const displayPreviousMonth = () => { + setCurrentYearAndMonth(([prevYear, prevMonth]) => { + let nextYear = prevYear + let nextMonth = prevMonth - 1 + + if (nextMonth === 0) { + nextMonth = 12 + nextYear = prevYear - 1 + } + + if (earliestYear && nextYear < earliestYear) + return [prevYear, prevMonth] + + return [nextYear, nextMonth] + }) + } + + const displayNextMonth = () => { + setCurrentYearAndMonth(([prevYear, prevMonth]) => { + let nextYear = prevYear + let nextMonth = prevMonth + 1 + + if (nextMonth === 13) { + nextMonth = 1 + nextYear = prevYear + 1 + } + + if (nextYear > new Date().getFullYear()) + return [prevYear, prevMonth] + + return [nextYear, nextMonth] + }) + } return ( -
+
-
+
+ +
diff --git a/src/app/(site)/(internal)/dashboard/calendar/utils/calendar-utils.ts b/src/app/(site)/(internal)/dashboard/calendar/utils/calendar-utils.ts index e66d6d1..ea61897 100644 --- a/src/app/(site)/(internal)/dashboard/calendar/utils/calendar-utils.ts +++ b/src/app/(site)/(internal)/dashboard/calendar/utils/calendar-utils.ts @@ -16,9 +16,14 @@ export const daysOfWeek = [ "Saturday" ]; -export function getYearDropdownOptions(currentYear: number): CalendarDropdownOptions[] { - let minYear = currentYear - 4; - let maxYear = currentYear + 5; +export function getYearDropdownOptions(currentYear: number, opts?: { + maxOffset?: number, + minOffset?: number, + startingYear?: number, + endingYear?: number, +}): CalendarDropdownOptions[] { + let minYear = opts?.startingYear ?? currentYear - Math.abs(opts?.minOffset ?? 0); + let maxYear = opts?.endingYear ?? currentYear + Math.abs(opts?.maxOffset ?? 0); return range(minYear, maxYear + 1).map((y) => ({label: `${y}`, value: y})); } diff --git a/src/app/(site)/components/icons/DoubleBackIcon.tsx b/src/app/(site)/components/icons/DoubleBackIcon.tsx new file mode 100644 index 0000000..571186e --- /dev/null +++ b/src/app/(site)/components/icons/DoubleBackIcon.tsx @@ -0,0 +1,19 @@ +import * as React from "react" +import {IconProps} from "@/app/(site)/components/icons/icon-utils"; +import clsx from "clsx"; + +const DoubleBackIcon = ({className, fill, width, height}: IconProps) => ( + + + +) +export default DoubleBackIcon diff --git a/src/app/(site)/components/icons/DoubleForwardIcon.tsx b/src/app/(site)/components/icons/DoubleForwardIcon.tsx new file mode 100644 index 0000000..099e760 --- /dev/null +++ b/src/app/(site)/components/icons/DoubleForwardIcon.tsx @@ -0,0 +1,19 @@ +import * as React from "react" +import {IconProps} from "@/app/(site)/components/icons/icon-utils"; +import clsx from "clsx"; + +const DoubleForwardIcon = ({className, fill, width, height}: IconProps) => ( + + + +) +export default DoubleForwardIcon