Changeset View
Changeset View
Standalone View
Standalone View
web/selectors/calendar-selectors.js
// @flow | // @flow | ||||
import { createSelector } from 'reselect'; | |||||
import { | import { | ||||
useFilterThreadInfos as baseUseFilterThreadInfos, | useFilterThreadInfos as baseUseFilterThreadInfos, | ||||
useFilterThreadSearchIndex as baseUseFilterThreadSearchIndex, | useFilterThreadSearchIndex as baseUseFilterThreadSearchIndex, | ||||
} from 'lib/selectors/calendar-selectors'; | } from 'lib/selectors/calendar-selectors'; | ||||
import { threadInfoSelector } from 'lib/selectors/thread-selectors'; | |||||
import type SearchIndex from 'lib/shared/search-index'; | import type SearchIndex from 'lib/shared/search-index'; | ||||
import { threadInFilterList } from 'lib/shared/thread-utils'; | |||||
import type { FilterThreadInfo } from 'lib/types/filter-types'; | import type { FilterThreadInfo } from 'lib/types/filter-types'; | ||||
import type { ThreadInfo, RawThreadInfo } from 'lib/types/thread-types'; | |||||
import { values } from 'lib/utils/objects'; | |||||
import type { AppState } from '../redux/redux-setup'; | |||||
import { useSelector } from '../redux/redux-utils'; | import { useSelector } from '../redux/redux-utils'; | ||||
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); | ||||
} | } | ||||
export { useFilterThreadInfos, useFilterThreadSearchIndex }; | function threadIDsBelongingToCommunity( | ||||
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), | |||||
inka: This was added relative to what had been accepted | |||||
tomekUnsubmitted Not Done Inline ActionsI'm not sure if it is a good idea to include this check here. Now the function name is no longer relevant as we're returning only a subset of threads from the community. I think this function should be reverted to the previous state and the additional filtering could be performed where it is used. We can also consider renaming this function so that it is more explicit about the additional filtering. tomek: I'm not sure if it is a good idea to include this check here. Now the function name is no… | |||||
inkaAuthorUnsubmitted Done Inline ActionsI moved the function to calendar-selectors.js to be clear that this has to do with calendar, and not simply returning threads of a community. So I'd rather rename the function to be more clear, and do the filtering here. I don't want to have to do this in the reducer, I want this function to abstract that from the reducer. inka: I moved the function to calendar-selectors.js to be clear that this has to do with calendar… | |||||
tomekUnsubmitted Not Done Inline ActionsMakes sense! tomek: Makes sense! | |||||
) | |||||
.map(item => item.id); | |||||
return new Set(threadIDs); | |||||
} | |||||
const threadIDsBelongingToCommunitySelector: ( | |||||
state: AppState, | |||||
) => ?$ReadOnlySet<string> = createSelector( | |||||
(state: AppState) => state.communityIDFilter, | |||||
threadInfoSelector, | |||||
(communityIDFilter: ?string, threadInfos: { +[id: string]: ThreadInfo }) => { | |||||
if (!communityIDFilter) { | |||||
return null; | |||||
} | |||||
return threadIDsBelongingToCommunity(communityIDFilter, threadInfos); | |||||
}, | |||||
); | |||||
export { | |||||
useFilterThreadInfos, | |||||
useFilterThreadSearchIndex, | |||||
threadIDsBelongingToCommunitySelector, | |||||
threadIDsBelongingToCommunity, | |||||
}; |
This was added relative to what had been accepted