Skip to content

Commit

Permalink
chore: fetch issues from previous and next month in the calendar view (
Browse files Browse the repository at this point in the history
  • Loading branch information
aaryan610 authored Sep 28, 2023
1 parent 6afbd3f commit 34af666
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions web/hooks/use-calendar-issues-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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`,
};

Expand Down

0 comments on commit 34af666

Please # to comment.