Skip to content

Commit 17bf4a5

Browse files
committed
user: Use UserItemById in ReactionUserList; simplify whole call stack.
This is a nice chain of simplifications we get from this conversion.
1 parent 9737c9a commit 17bf4a5

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

src/reactions/MessageReactionList.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,11 @@ import * as NavigationService from '../nav/NavigationService';
99
import * as logging from '../utils/logging';
1010
import ReactionUserList from './ReactionUserList';
1111
import { connect } from '../react-redux';
12-
import type {
13-
AggregatedReaction,
14-
Dispatch,
15-
EmojiType,
16-
Message,
17-
ReactionType,
18-
UserOrBot,
19-
} from '../types';
12+
import type { AggregatedReaction, Dispatch, EmojiType, Message, ReactionType } from '../types';
2013
import { Screen, Label, RawLabel } from '../common';
2114
import { getOwnUser } from '../selectors';
2215
import aggregateReactions from './aggregateReactions';
2316
import styles from '../styles';
24-
import { getAllUsersById } from '../users/userSelectors';
2517
import { materialTopTabNavigatorConfig } from '../styles/tabs';
2618
import Emoji from '../emoji/Emoji';
2719
import { objectFromEntries } from '../jsBackport';
@@ -39,16 +31,13 @@ const emojiTypeFromReactionType = (reactionType: ReactionType): EmojiType => {
3931
const getReactionsTabs = (
4032
aggregatedReactions: $ReadOnlyArray<AggregatedReaction>,
4133
reactionName?: string,
42-
allUsersById: Map<number, UserOrBot>,
4334
) => {
4435
// Each tab corresponds to an aggregated reaction, and has a user list.
4536
const reactionsTabs = objectFromEntries(
4637
aggregatedReactions.map(aggregatedReaction => [
4738
aggregatedReaction.name,
4839
{
49-
screen: () => (
50-
<ReactionUserList reactedUserIds={aggregatedReaction.users} allUsersById={allUsersById} />
51-
),
40+
screen: () => <ReactionUserList reactedUserIds={aggregatedReaction.users} />,
5241
navigationOptions: {
5342
tabBarLabel: () => (
5443
<View style={styles.row}>
@@ -100,7 +89,6 @@ const getReactionsTabs = (
10089
type SelectorProps = $ReadOnly<{|
10190
message: Message | void,
10291
ownUserId: number,
103-
allUsersById: Map<number, UserOrBot>,
10492
|}>;
10593

10694
type Props = $ReadOnly<{|
@@ -144,7 +132,7 @@ class MessageReactionList extends PureComponent<Props> {
144132
}
145133

146134
render() {
147-
const { message, navigation, ownUserId, allUsersById } = this.props;
135+
const { message, navigation, ownUserId } = this.props;
148136
const { reactionName } = navigation.state.params;
149137

150138
const content: React$Node = (() => {
@@ -162,7 +150,7 @@ class MessageReactionList extends PureComponent<Props> {
162150
// more than one navigator in the app, and the recommended
163151
// workaround isn't feasible; see discussion at
164152
// https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Dynamic.20routes.20in.20react-navigation/near/1008268.
165-
const TabView = getReactionsTabs(aggregatedReactions, reactionName, allUsersById);
153+
const TabView = getReactionsTabs(aggregatedReactions, reactionName);
166154
return (
167155
<View style={styles.flexed}>
168156
<TabView />
@@ -183,5 +171,4 @@ export default connect<SelectorProps, _, _>((state, props) => ({
183171
// message *can* be undefined; see componentDidUpdate for explanation and handling.
184172
message: (state.messages[props.navigation.state.params.messageId]: Message | void),
185173
ownUserId: getOwnUser(state).user_id,
186-
allUsersById: getAllUsersById(state),
187174
}))(MessageReactionList);

src/reactions/ReactionUserList.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ import { connect } from '../react-redux';
55

66
import * as NavigationService from '../nav/NavigationService';
77
import type { Dispatch, UserOrBot } from '../types';
8-
import UserItem from '../users/UserItem';
8+
import { UserItemById } from '../users/UserItem';
99
import { navigateToAccountDetails } from '../actions';
1010

1111
type Props = $ReadOnly<{|
1212
dispatch: Dispatch,
1313
reactedUserIds: $ReadOnlyArray<number>,
14-
allUsersById: Map<number, UserOrBot>,
1514
|}>;
1615

1716
/**
@@ -25,19 +24,15 @@ class ReactionUserList extends PureComponent<Props> {
2524
};
2625

2726
render() {
28-
const { reactedUserIds, allUsersById } = this.props;
27+
const { reactedUserIds } = this.props;
2928

3029
return (
3130
<FlatList
3231
data={reactedUserIds}
3332
keyExtractor={userId => `${userId}`}
34-
renderItem={({ item }) => {
35-
const user = allUsersById.get(item);
36-
if (!user) {
37-
return null;
38-
}
39-
return <UserItem key={user.user_id} user={user} onPress={this.handlePress} />;
40-
}}
33+
renderItem={({ item }) => (
34+
<UserItemById key={item} user={item} onPress={this.handlePress} />
35+
)}
4136
/>
4237
);
4338
}

0 commit comments

Comments
 (0)