Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32618680
D6461.1767461422.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D6461.1767461422.diff
View Options
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';
+import { threadInfoSelector } from 'lib/selectors/thread-selectors';
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 { 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';
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
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 3, 5:30 PM (16 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5889956
Default Alt Text
D6461.1767461422.diff (2 KB)
Attached To
Mode
D6461: [web] Add a selector fetching thread IDs according to COMMUNITIES calendar filter
Attached
Detach File
Event Timeline
Log In to Comment