From 34af666b5fbed6a6dd49292b6849ce6f1ea44d3c Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Date: Thu, 28 Sep 2023 13:17:46 +0530 Subject: [PATCH] chore: fetch issues from previous and next month in the calendar view (#2282) --- web/hooks/use-calendar-issues-view.tsx | 28 ++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/web/hooks/use-calendar-issues-view.tsx b/web/hooks/use-calendar-issues-view.tsx index 1f6f04ea8..5f21d63c5 100644 --- a/web/hooks/use-calendar-issues-view.tsx +++ b/web/hooks/use-calendar-issues-view.tsx @@ -33,8 +33,28 @@ const useCalendarIssuesView = () => { const [activeMonthDate, setActiveMonthDate] = useState(new Date()); - const firstDayOfMonth = new Date(activeMonthDate.getFullYear(), activeMonthDate.getMonth(), 1); - const lastDayOfMonth = new Date(activeMonthDate.getFullYear(), activeMonthDate.getMonth() + 1, 0); + // previous month's first date + const previousMonthYear = + activeMonthDate.getMonth() === 0 + ? activeMonthDate.getFullYear() - 1 + : activeMonthDate.getFullYear(); + const previousMonthMonth = activeMonthDate.getMonth() === 0 ? 11 : activeMonthDate.getMonth() - 1; + + const previousMonthFirstDate = new Date(previousMonthYear, previousMonthMonth, 1); + + // next month's last date + const nextMonthYear = + activeMonthDate.getMonth() === 11 + ? activeMonthDate.getFullYear() + 1 + : activeMonthDate.getFullYear(); + const nextMonthMonth = (activeMonthDate.getMonth() + 1) % 12; + const nextMonthFirstDate = new Date(nextMonthYear, nextMonthMonth, 1); + + const nextMonthLastDate = new Date( + nextMonthFirstDate.getFullYear(), + nextMonthFirstDate.getMonth() + 1, + 0 + ); const router = useRouter(); const { workspaceSlug, projectId, cycleId, moduleId, viewId } = router.query; @@ -47,8 +67,8 @@ const useCalendarIssuesView = () => { labels: filters?.labels ? filters?.labels.join(",") : undefined, created_by: filters?.created_by ? filters?.created_by.join(",") : undefined, start_date: filters?.start_date ? filters?.start_date.join(",") : undefined, - target_date: `${renderDateFormat(firstDayOfMonth)};after,${renderDateFormat( - lastDayOfMonth + target_date: `${renderDateFormat(previousMonthFirstDate)};after,${renderDateFormat( + nextMonthLastDate )};before`, };