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 ( -