Page MenuHomePhabricator

D6979.id26770.diff
No OneTemporary

D6979.id26770.diff

diff --git a/web/navigation-panels/app-switcher.react.js b/web/navigation-panels/app-switcher.react.js
--- a/web/navigation-panels/app-switcher.react.js
+++ b/web/navigation-panels/app-switcher.react.js
@@ -4,16 +4,14 @@
import { useDispatch } from 'react-redux';
import SWMansionIcon from 'lib/components/SWMansionIcon.react.js';
-import {
- mostRecentlyReadThreadSelector,
- unreadCount,
-} from 'lib/selectors/thread-selectors.js';
+import { mostRecentlyReadThreadSelector } from 'lib/selectors/thread-selectors.js';
import NavigationPanel from './navigation-panel.react.js';
import css from './topbar.css';
import { updateNavInfoActionType } from '../redux/action-types.js';
import { useSelector } from '../redux/redux-utils.js';
import { navTabSelector } from '../selectors/nav-selectors.js';
+import { unreadCountInSelectedCommunity } from '../selectors/thread-selectors.js';
function AppSwitcher(): React.Node {
const activeChatThreadID = useSelector(
@@ -49,7 +47,7 @@
],
);
- const boundUnreadCount = useSelector(unreadCount);
+ const boundUnreadCount = useSelector(unreadCountInSelectedCommunity);
let chatBadge = null;
if (boundUnreadCount > 0) {
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,18 +3,24 @@
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.js';
import { useLoggedInUserInfo } from 'lib/hooks/account-hooks.js';
-import { createPendingSidebar } from 'lib/shared/thread-utils.js';
+import {
+ createPendingSidebar,
+ threadInHomeChatList,
+} from 'lib/shared/thread-utils.js';
import type {
ComposableMessageInfo,
RobotextMessageInfo,
} from 'lib/types/message-types.js';
-import type { ThreadInfo } from 'lib/types/thread-types.js';
+import type { ThreadInfo, RawThreadInfo } from 'lib/types/thread-types.js';
+import { values } from 'lib/utils/objects.js';
import { getDefaultTextMessageRules } from '../markdown/rules.react.js';
import { updateNavInfoActionType } from '../redux/action-types.js';
+import type { AppState } from '../redux/redux-setup.js';
import { useSelector } from '../redux/redux-utils.js';
function useOnClickThread(
@@ -120,10 +126,27 @@
return inCalendar ? pickedCommunityID : activeChatThreadID;
}
+const unreadCountInSelectedCommunity: (state: AppState) => number =
+ createSelector(
+ (state: AppState) => state.threadStore.threadInfos,
+ (state: AppState) => state.communityPickerStore.chat,
+ (
+ threadInfos: { +[id: string]: RawThreadInfo },
+ communityID: ?string,
+ ): number =>
+ values(threadInfos).filter(
+ threadInfo =>
+ threadInHomeChatList(threadInfo) &&
+ threadInfo.currentUser.unread &&
+ (!communityID || communityID === threadInfo.community),
+ ).length,
+ );
+
export {
useOnClickThread,
useThreadIsActive,
useOnClickPendingSidebar,
useOnClickNewThread,
useDrawerSelectedThreadID,
+ unreadCountInSelectedCommunity,
};

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 26, 6:16 PM (21 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2585501
Default Alt Text
D6979.id26770.diff (3 KB)

Event Timeline