Changeset View
Changeset View
Standalone View
Standalone View
lib/selectors/calendar-filter-selectors.js
Show All 27 Lines | |||||
const filteredThreadIDsSelector: ( | const filteredThreadIDsSelector: ( | ||||
state: BaseAppState<*>, | state: BaseAppState<*>, | ||||
) => ?$ReadOnlySet<string> = createSelector( | ) => ?$ReadOnlySet<string> = createSelector( | ||||
(state: BaseAppState<*>) => state.calendarFilters, | (state: BaseAppState<*>) => state.calendarFilters, | ||||
filteredThreadIDs, | filteredThreadIDs, | ||||
); | ); | ||||
function filteredCommunityThreadIDs( | |||||
calendarFilters: $ReadOnlyArray<CalendarFilter>, | |||||
): ?Set<string> { | |||||
let threadIDs = []; | |||||
let threadListFilterExists = false; | |||||
for (const filter of calendarFilters) { | |||||
if (filter.type === calendarThreadFilterTypes.COMMUNITY) { | |||||
threadListFilterExists = true; | |||||
threadIDs = [...threadIDs, ...filter.threadIDs]; | |||||
} | |||||
} | |||||
if (!threadListFilterExists) { | |||||
return null; | |||||
} | |||||
return new Set(threadIDs); | |||||
} | |||||
inka: This is very similar to `filteredThreadIDs`, it just filters out a different… | |||||
const filteredCommunityThreadIDsSelector: ( | |||||
state: BaseAppState<*>, | |||||
) => ?$ReadOnlySet<string> = createSelector( | |||||
(state: BaseAppState<*>) => state.calendarFilters, | |||||
filteredCommunityThreadIDs, | |||||
); | |||||
function filterFilters( | function filterFilters( | ||||
calendarFilters: $ReadOnlyArray<CalendarFilter>, | calendarFilters: $ReadOnlyArray<CalendarFilter>, | ||||
filterTypeToExclude: CalendarThreadFilterType, | filterTypeToExclude: CalendarThreadFilterType, | ||||
): $ReadOnlyArray<CalendarFilter> { | ): $ReadOnlyArray<CalendarFilter> { | ||||
const filteredFilters = []; | const filteredFilters = []; | ||||
for (const filter of calendarFilters) { | for (const filter of calendarFilters) { | ||||
if (filter.type !== filterTypeToExclude) { | if (filter.type !== filterTypeToExclude) { | ||||
filteredFilters.push(filter); | filteredFilters.push(filter); | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | ) => boolean = createSelector( | ||||
(state: BaseAppState<*>) => state.calendarFilters, | (state: BaseAppState<*>) => state.calendarFilters, | ||||
(calendarFilters: $ReadOnlyArray<CalendarFilter>) => | (calendarFilters: $ReadOnlyArray<CalendarFilter>) => | ||||
!filterExists(calendarFilters, calendarThreadFilterTypes.NOT_DELETED), | !filterExists(calendarFilters, calendarThreadFilterTypes.NOT_DELETED), | ||||
); | ); | ||||
export { | export { | ||||
filteredThreadIDs, | filteredThreadIDs, | ||||
filteredThreadIDsSelector, | filteredThreadIDsSelector, | ||||
filteredCommunityThreadIDs, | |||||
filteredCommunityThreadIDsSelector, | |||||
nonThreadCalendarFilters, | nonThreadCalendarFilters, | ||||
nonThreadCalendarFiltersSelector, | nonThreadCalendarFiltersSelector, | ||||
nonExcludeDeletedCalendarFilters, | nonExcludeDeletedCalendarFilters, | ||||
nonExcludeDeletedCalendarFiltersSelector, | nonExcludeDeletedCalendarFiltersSelector, | ||||
nonCommunityCalendarFilters, | nonCommunityCalendarFilters, | ||||
nonCommunityCalendarFiltersSelector, | nonCommunityCalendarFiltersSelector, | ||||
filterExists, | filterExists, | ||||
includeDeletedSelector, | includeDeletedSelector, | ||||
}; | }; |
This is very similar to filteredThreadIDs, it just filters out a different calendarThreadFilterTypes type, but I'm not sure if i should merge them.
I wanted to simply take type: CalendarThreadFilterType as an argument, but then in line 44 I get a flow error, because for type NOT_DELETED filter.threadIDs doesn't exist. And manually specifying the names of the types that work here seems wrong to me.