-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(components): implement memoized selectors for denormalized c…
…onversations (#2743) * refactor(components): implement memoized selectors * refactor: remove logs * refactor(components): implement memoized selectors for denormalized conversations
- Loading branch information
Showing
7 changed files
with
39 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,22 @@ | ||
import { createSelector } from '@reduxjs/toolkit'; | ||
import { RootState } from '../../../../../store/reducer'; | ||
import { denormalizeConversations } from '../../../../../store/channels-list'; | ||
import { UnreadCount } from './useSidekick'; | ||
import { DefaultRoomLabels } from '../../../../../store/channels'; | ||
import { denormalizedConversationsSelector } from '../../../../../store/channels-list/selectors'; | ||
|
||
export const selectSocialChannelsUnreadCounts = createSelector( | ||
[(state: RootState) => denormalizeConversations(state)], | ||
(conversations) => { | ||
return conversations | ||
.filter((c) => c.isSocialChannel && c.zid) | ||
.reduce((acc, channel) => { | ||
acc[channel.zid!] = { total: channel.unreadCount?.total || 0, highlight: channel.unreadCount?.highlight || 0 }; | ||
return acc; | ||
}, {} as { [zid: string]: UnreadCount }); | ||
} | ||
); | ||
export const selectSocialChannelsUnreadCounts = createSelector([denormalizedConversationsSelector], (conversations) => { | ||
return conversations | ||
.filter((c) => c.isSocialChannel && c.zid) | ||
.reduce((acc, channel) => { | ||
acc[channel.zid!] = { total: channel.unreadCount?.total || 0, highlight: channel.unreadCount?.highlight || 0 }; | ||
return acc; | ||
}, {} as { [zid: string]: UnreadCount }); | ||
}); | ||
|
||
export const selectMutedChannels = createSelector( | ||
[(state: RootState) => denormalizeConversations(state)], | ||
(conversations) => { | ||
return conversations | ||
.filter((c) => c.isSocialChannel && c.zid) | ||
.reduce((acc, channel) => { | ||
acc[channel.zid!] = channel.labels?.includes(DefaultRoomLabels.MUTE); | ||
return acc; | ||
}, {} as { [zid: string]: boolean }); | ||
} | ||
); | ||
export const selectMutedChannels = createSelector([denormalizedConversationsSelector], (conversations) => { | ||
return conversations | ||
.filter((c) => c.isSocialChannel && c.zid) | ||
.reduce((acc, channel) => { | ||
acc[channel.zid!] = channel.labels?.includes(DefaultRoomLabels.MUTE); | ||
return acc; | ||
}, {} as { [zid: string]: boolean }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters