refactor: calendar view (#636)

This commit is contained in:
Aaryan Khandelwal 2023-03-31 02:43:38 +05:30 committed by GitHub
parent e2921539d0
commit 0c94b494ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,15 +67,21 @@ export const CalendarView = () => {
endDate: lastDayOfWeek(currentDate), endDate: lastDayOfWeek(currentDate),
}); });
const targetDateFilter = {
target_date: `${renderDateFormat(calendarDateRange.startDate)};after,${renderDateFormat(
calendarDateRange.endDate
)};before`,
};
const { data: projectCalendarIssues } = useSWR( const { data: projectCalendarIssues } = useSWR(
workspaceSlug && projectId ? PROJECT_CALENDAR_ISSUES(projectId as string) : null, workspaceSlug && projectId ? PROJECT_CALENDAR_ISSUES(projectId as string) : null,
workspaceSlug && projectId workspaceSlug && projectId
? () => ? () =>
issuesService.getIssuesWithParams(workspaceSlug as string, projectId as string, { issuesService.getIssuesWithParams(
target_date: `${renderDateFormat(calendarDateRange.startDate)};after,${renderDateFormat( workspaceSlug as string,
calendarDateRange.endDate projectId as string,
)};before`, targetDateFilter
}) )
: null : null
); );
@ -89,11 +95,7 @@ export const CalendarView = () => {
workspaceSlug as string, workspaceSlug as string,
projectId as string, projectId as string,
cycleId as string, cycleId as string,
{ targetDateFilter
target_date: `${renderDateFormat(
calendarDateRange.startDate
)};after,${renderDateFormat(calendarDateRange.endDate)};before`,
}
) )
: null : null
); );
@ -108,11 +110,7 @@ export const CalendarView = () => {
workspaceSlug as string, workspaceSlug as string,
projectId as string, projectId as string,
moduleId as string, moduleId as string,
{ targetDateFilter
target_date: `${renderDateFormat(
calendarDateRange.startDate
)};after,${renderDateFormat(calendarDateRange.endDate)};before`,
}
) )
: null : null
); );
@ -166,48 +164,25 @@ export const CalendarView = () => {
if (!destination || !workspaceSlug || !projectId) return; if (!destination || !workspaceSlug || !projectId) return;
if (source.droppableId === destination.droppableId) return; if (source.droppableId === destination.droppableId) return;
if (cycleId) const fetchKey = cycleId
mutate<IIssue[]>( ? CYCLE_CALENDAR_ISSUES(projectId as string, cycleId as string)
CYCLE_CALENDAR_ISSUES(projectId as string, cycleId as string), : moduleId
(prevData) => ? MODULE_CALENDAR_ISSUES(projectId as string, moduleId as string)
(prevData ?? []).map((p) => { : PROJECT_CALENDAR_ISSUES(projectId as string);
if (p.id === draggableId)
return { mutate<IIssue[]>(
...p, fetchKey,
target_date: destination.droppableId, (prevData) =>
}; (prevData ?? []).map((p) => {
return p; if (p.id === draggableId)
}), return {
false ...p,
); target_date: destination.droppableId,
else if (moduleId) };
mutate<IIssue[]>( return p;
MODULE_CALENDAR_ISSUES(projectId as string, moduleId as string), }),
(prevData) => false
(prevData ?? []).map((p) => { );
if (p.id === draggableId)
return {
...p,
target_date: destination.droppableId,
};
return p;
}),
false
);
else
mutate<IIssue[]>(
PROJECT_CALENDAR_ISSUES(projectId as string),
(prevData) =>
(prevData ?? []).map((p) => {
if (p.id === draggableId)
return {
...p,
target_date: destination.droppableId,
};
return p;
}),
false
);
issuesService.patchIssue(workspaceSlug as string, projectId as string, draggableId, { issuesService.patchIssue(workspaceSlug as string, projectId as string, draggableId, {
target_date: destination?.droppableId, target_date: destination?.droppableId,
@ -216,6 +191,7 @@ export const CalendarView = () => {
const updateDate = (date: Date) => { const updateDate = (date: Date) => {
setCurrentDate(date); setCurrentDate(date);
setCalendarDateRange({ setCalendarDateRange({
startDate: startOfWeek(date), startDate: startOfWeek(date),
endDate: lastDayOfWeek(date), endDate: lastDayOfWeek(date),