Changeset View
Changeset View
Standalone View
Standalone View
web/selectors/calendar-selectors.js
// @flow | // @flow | ||||
import { createSelector } from 'reselect'; | import { createSelector } from 'reselect'; | ||||
import { | import { | ||||
useFilterThreadInfos as baseUseFilterThreadInfos, | useFilterThreadInfos as baseUseFilterThreadInfos, | ||||
useFilterThreadSearchIndex as baseUseFilterThreadSearchIndex, | useFilterThreadSearchIndex as baseUseFilterThreadSearchIndex, | ||||
} from 'lib/selectors/calendar-selectors.js'; | } from 'lib/selectors/calendar-selectors.js'; | ||||
import { threadInfoSelector } from 'lib/selectors/thread-selectors.js'; | import { threadInfoSelector } from 'lib/selectors/thread-selectors.js'; | ||||
import type SearchIndex from 'lib/shared/search-index.js'; | import type SearchIndex from 'lib/shared/search-index.js'; | ||||
import { threadInFilterList } from 'lib/shared/thread-utils.js'; | |||||
import type { FilterThreadInfo } from 'lib/types/filter-types.js'; | import type { FilterThreadInfo } from 'lib/types/filter-types.js'; | ||||
import type { ThreadInfo, RawThreadInfo } from 'lib/types/thread-types.js'; | import type { ThreadInfo } from 'lib/types/thread-types.js'; | ||||
import { values } from 'lib/utils/objects.js'; | import { filterThreadIDsBelongingToCommunity } from 'lib/utils/drawer-utils.react.js'; | ||||
import type { AppState } from '../redux/redux-setup.js'; | import type { AppState } from '../redux/redux-setup.js'; | ||||
import { useSelector } from '../redux/redux-utils.js'; | import { useSelector } from '../redux/redux-utils.js'; | ||||
function useFilterThreadInfos(): $ReadOnlyArray<FilterThreadInfo> { | function useFilterThreadInfos(): $ReadOnlyArray<FilterThreadInfo> { | ||||
const calendarActive = useSelector(state => state.navInfo.tab === 'calendar'); | const calendarActive = useSelector(state => state.navInfo.tab === 'calendar'); | ||||
return baseUseFilterThreadInfos(calendarActive); | return baseUseFilterThreadInfos(calendarActive); | ||||
} | } | ||||
function useFilterThreadSearchIndex(): SearchIndex { | function useFilterThreadSearchIndex(): SearchIndex { | ||||
const calendarActive = useSelector(state => state.navInfo.tab === 'calendar'); | const calendarActive = useSelector(state => state.navInfo.tab === 'calendar'); | ||||
return baseUseFilterThreadSearchIndex(calendarActive); | return baseUseFilterThreadSearchIndex(calendarActive); | ||||
} | } | ||||
function filterThreadIDsBelongingToCommunity( | |||||
communityID: string, | |||||
threadInfosObj: { +[id: string]: ThreadInfo | RawThreadInfo }, | |||||
): $ReadOnlySet<string> { | |||||
const threadInfos = values(threadInfosObj); | |||||
const threadIDs = threadInfos | |||||
.filter( | |||||
thread => | |||||
(thread.community === communityID || thread.id === communityID) && | |||||
threadInFilterList(thread), | |||||
) | |||||
.map(item => item.id); | |||||
return new Set(threadIDs); | |||||
} | |||||
const filterThreadIDsBelongingToCommunitySelector: ( | const filterThreadIDsBelongingToCommunitySelector: ( | ||||
state: AppState, | state: AppState, | ||||
) => ?$ReadOnlySet<string> = createSelector( | ) => ?$ReadOnlySet<string> = createSelector( | ||||
(state: AppState) => state.communityPickerStore.calendar, | (state: AppState) => state.communityPickerStore.calendar, | ||||
threadInfoSelector, | threadInfoSelector, | ||||
( | ( | ||||
calendarPickedCommunityID: ?string, | calendarPickedCommunityID: ?string, | ||||
threadInfos: { +[id: string]: ThreadInfo }, | threadInfos: { +[id: string]: ThreadInfo }, | ||||
Show All 25 Lines |