Page MenuHomePhabricator

D6461.id22483.diff
No OneTemporary

D6461.id22483.diff

diff --git a/web/selectors/calendar-selectors.js b/web/selectors/calendar-selectors.js
--- a/web/selectors/calendar-selectors.js
+++ b/web/selectors/calendar-selectors.js
@@ -1,12 +1,19 @@
// @flow
+import { createSelector } from 'reselect';
+
import {
useFilterThreadInfos as baseUseFilterThreadInfos,
useFilterThreadSearchIndex as baseUseFilterThreadSearchIndex,
} from 'lib/selectors/calendar-selectors.js';
+import { threadInfoSelector } from 'lib/selectors/thread-selectors.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 { ThreadInfo, RawThreadInfo } from 'lib/types/thread-types.js';
+import { values } from 'lib/utils/objects.js';
+import type { AppState } from '../redux/redux-setup.js';
import { useSelector } from '../redux/redux-utils.js';
function useFilterThreadInfos(): $ReadOnlyArray<FilterThreadInfo> {
@@ -19,4 +26,37 @@
return baseUseFilterThreadSearchIndex(calendarActive);
}
-export { useFilterThreadInfos, useFilterThreadSearchIndex };
+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: (
+ state: AppState,
+) => ?$ReadOnlySet<string> = createSelector(
+ (state: AppState) => state.communityIDFilter,
+ threadInfoSelector,
+ (communityIDFilter: ?string, threadInfos: { +[id: string]: ThreadInfo }) => {
+ if (!communityIDFilter) {
+ return null;
+ }
+ return filterThreadIDsBelongingToCommunity(communityIDFilter, threadInfos);
+ },
+);
+
+export {
+ useFilterThreadInfos,
+ useFilterThreadSearchIndex,
+ filterThreadIDsBelongingToCommunitySelector,
+ filterThreadIDsBelongingToCommunity,
+};

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 21, 4:10 AM (17 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2683623
Default Alt Text
D6461.id22483.diff (2 KB)

Event Timeline