Skip to content

Commit

Permalink
removing redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
amankumarrr committed Oct 31, 2024
1 parent 534991e commit 65bb39e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
20 changes: 20 additions & 0 deletions helpers/getTrimmedEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export const getTrimmedEvent = (events) =>
events?.pages.flat().flatMap((item) =>
item.eventsCalendarConnection.edges.map((edge) => ({
...edge.node,
startDateTime: new Date(edge.node.startDateTime),
endDateTime: new Date(edge.node.endDateTime),
category: formatCategory(edge.node.category),
}))
) || [];

export const formatCategory = (category: string): string => {
{
const categoryReplacements = {
"Non-English Courses": "Other",
};
const lookup = categoryReplacements[category];

return lookup ? lookup : category;
}
};
32 changes: 3 additions & 29 deletions hooks/useFetchEvents.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EventFilterAllCategories } from "@/components/filter/FilterBlock";
import { formatCategory, getTrimmedEvent } from "@/helpers/getTrimmedEvents";
import { EVENTS_MAX_SIZE_OVERRIDE } from "@/services/server/getEvents";
import { GetPastEventsQueryQuery } from "@/tina/types";
import { useInfiniteQuery } from "@tanstack/react-query";
Expand All @@ -20,17 +21,6 @@ const getCategoriesForFilter = (category: string) => {
return lookup ? lookup : [category];
};

const formatCategory = (category: string): string => {
{
const categoryReplacements = {
"Non-English Courses": "Other",
};
const lookup = categoryReplacements[category];

return lookup ? lookup : category;
}
};

export const TODAY = new Date();
TODAY.setHours(0, 0, 0, 0);

Expand Down Expand Up @@ -69,15 +59,7 @@ export const useFetchFutureEvents = (filters: SelectedCategories) => {
},
});
return {
futureEvents:
data?.pages.flat().flatMap((item) =>
item.eventsCalendarConnection.edges.map((edge) => ({
...edge.node,
startDateTime: new Date(edge.node.startDateTime),
endDateTime: new Date(edge.node.endDateTime),
category: formatCategory(edge.node.category),
}))
) || [],
futureEvents: getTrimmedEvent(data),
error,
isLoadingFuturePages: isLoading,
fetchFutureNextPage: fetchNextPage,
Expand Down Expand Up @@ -117,15 +99,7 @@ export const useFetchPastEvents = (filters: SelectedCategories) => {
});

return {
pastEvents:
data?.pages.flat().flatMap((item) =>
item.eventsCalendarConnection.edges.map((edge) => ({
...edge.node,
startDateTime: new Date(edge.node.startDateTime),
endDateTime: new Date(edge.node.endDateTime),
category: formatCategory(edge.node.category),
}))
) || [],
pastEvents: getTrimmedEvent(data),
error,
isLoadingPastPages: isLoading,
fetchNextPastPage: fetchNextPage,
Expand Down

0 comments on commit 65bb39e

Please sign in to comment.