diff --git a/src/app/selectors/selectCalendars.tsx b/src/app/selectors/selectCalendars.tsx new file mode 100644 index 0000000..fde5bf7 --- /dev/null +++ b/src/app/selectors/selectCalendars.tsx @@ -0,0 +1,7 @@ +import { RootState } from "@/app/store"; +import { createSelector } from "@reduxjs/toolkit"; + +export const selectCalendars = createSelector( + (state: RootState) => state.calendars.list, + (list) => Object.values(list) +); diff --git a/src/components/Menubar/EventSearchBar.tsx b/src/components/Menubar/EventSearchBar.tsx index 07ea2ed..aa01dea 100644 --- a/src/components/Menubar/EventSearchBar.tsx +++ b/src/components/Menubar/EventSearchBar.tsx @@ -1,4 +1,5 @@ import { useAppDispatch, useAppSelector } from "@/app/hooks"; +import { selectCalendars } from "@/app/selectors/selectCalendars"; import { searchEventsAsync } from "@/features/Search/SearchSlice"; import { setView } from "@/features/Settings/SettingsSlice"; import { userAttendee } from "@/features/User/models/attendee"; @@ -31,12 +32,12 @@ import UserSearch from "../Attendees/AttendeeSearch"; import { PeopleSearch, User } from "../Attendees/PeopleSearch"; import { CalendarItemList } from "../Calendar/CalendarItemList"; +const SEARCH_OBJECT_TYPES = ["user", "contact"]; + export default function SearchBar() { const { t } = useI18n(); const dispatch = useAppDispatch(); - const calendars = Object.values( - useAppSelector((state) => state.calendars.list) - ); + const calendars = useAppSelector(selectCalendars); const userId = useAppSelector((state) => state.user.userData?.openpaasId); const personnalCalendars = userId ? calendars.filter((c) => extractEventBaseUuid(c.id) === userId) @@ -227,7 +228,7 @@ export default function SearchBar() { onChange={(_event, users) => { handleContactSelect(users); }} - objectTypes={["user", "contact"]} + objectTypes={SEARCH_OBJECT_TYPES} onToggleEventPreview={() => {}} customSlotProps={{ popper: {