This repository has been archived by the owner on Jun 10, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: optimized event filtering (#9889)
* fix: optimized event filtering proposed changes: * created a new file `filterEvent.js` to store re-usable filtering logic * added a new state variable `eventsToShow` and `eventsOptions` * implemented `useMemo` hook to avoid redundant computations and enhance overall performance * refactor: EventTabs props
- Loading branch information
Showing
4 changed files
with
97 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export function filterByEventType(event, eventType) { | ||
switch (eventType) { | ||
case "future": | ||
return event.date.future; | ||
case "ongoing": | ||
return event.date.ongoing; | ||
case "virtual": | ||
return (event.date.future && event.isVirtual) || event.isVirtual; | ||
case "inPerson": | ||
return (event.date.future && event.isInPerson) || event.isInPerson; | ||
case "cfpOpen": | ||
return event.date.cfpOpen; | ||
case "free": | ||
return event.price?.startingFrom === 0; | ||
case "paid": | ||
return event.price?.startingFrom > 0; | ||
case "past": | ||
return !event.date.future; | ||
default: | ||
return true; | ||
} | ||
} | ||
|
||
export function getFilteredEvents(events, eventType) { | ||
if (eventType === "all") { | ||
return events; | ||
} | ||
let filteredEvents = events.filter((event) => | ||
filterByEventType(event, eventType), | ||
); | ||
if (eventType === "future" && filteredEvents.length === 0) { | ||
filteredEvents = events.filter((event) => | ||
filterByEventType(event, eventType), | ||
); | ||
} | ||
return filteredEvents; | ||
} |