Page MenuHomePhabricator

D6461.id22293.diff
No OneTemporary

D6461.id22293.diff

diff --git a/web/selectors/thread-selectors.js b/web/selectors/thread-selectors.js
--- a/web/selectors/thread-selectors.js
+++ b/web/selectors/thread-selectors.js
@@ -3,17 +3,21 @@
import invariant from 'invariant';
import * as React from 'react';
import { useDispatch } from 'react-redux';
+import { createSelector } from 'reselect';
import { ENSCacheContext } from 'lib/components/ens-cache-provider.react';
+import { threadInfoSelector } from 'lib/selectors/thread-selectors';
import { createPendingSidebar } from 'lib/shared/thread-utils';
import type {
ComposableMessageInfo,
RobotextMessageInfo,
} from 'lib/types/message-types';
-import type { ThreadInfo } from 'lib/types/thread-types';
+import type { ThreadInfo, RawThreadInfo } from 'lib/types/thread-types';
+import { values } from 'lib/utils/objects';
import { getDefaultTextMessageRules } from '../markdown/rules.react';
import { updateNavInfoActionType } from '../redux/action-types';
+import type { AppState } from '../redux/redux-setup';
import { useSelector } from '../redux/redux-utils';
function useOnClickThread(
@@ -107,9 +111,37 @@
);
}
+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,
+ )
+ .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 {
useOnClickThread,
useThreadIsActive,
useOnClickPendingSidebar,
useOnClickNewThread,
+ threadIDsBelongingToCommunitySelector,
+ threadIDsBelongingToCommunity,
};

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 21, 5:01 AM (18 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2685975
Default Alt Text
D6461.id22293.diff (2 KB)

Event Timeline