Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3402271
D10349.id34740.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D10349.id34740.diff
View Options
diff --git a/lib/utils/drawer-utils.react.js b/lib/utils/drawer-utils.react.js
--- a/lib/utils/drawer-utils.react.js
+++ b/lib/utils/drawer-utils.react.js
@@ -1,5 +1,7 @@
// @flow
+import * as React from 'react';
+
import { values } from './objects.js';
import { threadInFilterList, threadIsChannel } from '../shared/thread-utils.js';
import { communitySubthreads } from '../types/thread-types-enum.js';
@@ -74,27 +76,29 @@
);
}
-function appendSuffix(
- chats: $ReadOnlyArray<ResolvedThreadInfo>,
-): ResolvedThreadInfo[] {
- const result: ResolvedThreadInfo[] = [];
- const names = new Map<string, number>();
+function useAppendCommunitySuffix(
+ communities: $ReadOnlyArray<ResolvedThreadInfo>,
+): $ReadOnlyArray<ResolvedThreadInfo> {
+ return React.useMemo(() => {
+ const result: ResolvedThreadInfo[] = [];
+ const names = new Map<string, number>();
- for (const chat of chats) {
- let name = chat.uiName;
- const numberOfOccurrences = names.get(name);
- names.set(name, (numberOfOccurrences ?? 0) + 1);
- if (numberOfOccurrences) {
- name = `${name} (${numberOfOccurrences.toString()})`;
- }
- // Branching to appease `flow`.
- if (chat.minimallyEncoded) {
- result.push({ ...chat, uiName: name });
- } else {
- result.push({ ...chat, uiName: name });
+ for (const chat of communities) {
+ let name = chat.uiName;
+ const numberOfOccurrences = names.get(name);
+ names.set(name, (numberOfOccurrences ?? 0) + 1);
+ if (numberOfOccurrences) {
+ name = `${name} (${numberOfOccurrences.toString()})`;
+ }
+ // Branching to appease `flow`.
+ if (chat.minimallyEncoded) {
+ result.push({ ...chat, uiName: name });
+ } else {
+ result.push({ ...chat, uiName: name });
+ }
}
- }
- return result;
+ return result;
+ }, [communities]);
}
function filterThreadIDsBelongingToCommunity(
@@ -116,6 +120,6 @@
export {
createRecursiveDrawerItemsData,
- appendSuffix,
+ useAppendCommunitySuffix,
filterThreadIDsBelongingToCommunity,
};
diff --git a/native/navigation/community-drawer-content.react.js b/native/navigation/community-drawer-content.react.js
--- a/native/navigation/community-drawer-content.react.js
+++ b/native/navigation/community-drawer-content.react.js
@@ -19,7 +19,7 @@
import { useDispatchActionPromise } from 'lib/utils/action-utils.js';
import {
createRecursiveDrawerItemsData,
- appendSuffix,
+ useAppendCommunitySuffix,
} from 'lib/utils/drawer-utils.react.js';
import { useResolvedThreadInfos } from 'lib/utils/entity-helpers.js';
@@ -43,10 +43,7 @@
function CommunityDrawerContent(): React.Node {
const communities = useSelector(communityThreadSelector);
const resolvedCommunities = useResolvedThreadInfos(communities);
- const communitiesSuffixed = React.useMemo(
- () => appendSuffix(resolvedCommunities),
- [resolvedCommunities],
- );
+ const communitiesSuffixed = useAppendCommunitySuffix(resolvedCommunities);
const styles = useStyles(unboundStyles);
const callFetchPrimaryLinks = useFetchPrimaryInviteLinks();
diff --git a/web/sidebar/community-drawer.react.js b/web/sidebar/community-drawer.react.js
--- a/web/sidebar/community-drawer.react.js
+++ b/web/sidebar/community-drawer.react.js
@@ -8,7 +8,7 @@
} from 'lib/selectors/thread-selectors.js';
import {
createRecursiveDrawerItemsData,
- appendSuffix,
+ useAppendCommunitySuffix,
} from 'lib/utils/drawer-utils.react.js';
import { useResolvedThreadInfos } from 'lib/utils/entity-helpers.js';
@@ -25,10 +25,7 @@
const childThreadInfosMap = useSelector(childThreadInfos);
const communities = useSelector(communityThreadSelector);
const resolvedCommunities = useResolvedThreadInfos(communities);
- const communitiesSuffixed = React.useMemo(
- () => appendSuffix(resolvedCommunities),
- [resolvedCommunities],
- );
+ const communitiesSuffixed = useAppendCommunitySuffix(resolvedCommunities);
const drawerItemsData = createRecursiveDrawerItemsData(
childThreadInfosMap,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 3, 3:40 PM (3 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2611833
Default Alt Text
D10349.id34740.diff (3 KB)
Attached To
Mode
D10349: [lib/native/web] convert appendSuffix to useAppendCommunitySuffix
Attached
Detach File
Event Timeline
Log In to Comment