Skip to content

Commit

Permalink
user [nfc]: Have UserList get presence data, not callers
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice committed Nov 7, 2022
1 parent 845b08b commit 0390f3a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/user-picker/New1to1PmScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import UserList from '../users/UserList';
import type { UserOrBot } from '../types';
import { useSelector, useDispatch } from '../react-redux';
import { pm1to1NarrowFromUser } from '../utils/narrow';
import { getUsers, getPresence } from '../selectors';
import { getUsers } from '../selectors';
import { navigateBack, doNarrow } from '../actions';
import { useNavigation } from '../react-navigation';

Expand All @@ -21,7 +21,6 @@ type Props = $ReadOnly<{|
export default function New1to1PmScreen(props: Props): Node {
const dispatch = useDispatch();
const users = useSelector(getUsers);
const presences = useSelector(getPresence);

const navigation = useNavigation();
const handleUserNarrow = useCallback(
Expand All @@ -36,7 +35,7 @@ export default function New1to1PmScreen(props: Props): Node {

return (
<Screen search scrollEnabled={false} searchBarOnChange={setFilter}>
<UserList users={users} filter={filter} presences={presences} onPress={handleUserNarrow} />
<UserList users={users} filter={filter} onPress={handleUserNarrow} />
</Screen>
);
}
4 changes: 1 addition & 3 deletions src/user-picker/UserPickerCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { IconDone } from '../common/Icons';
import UserList from '../users/UserList';
import AvatarList from './AvatarList';
import AnimatedScaleComponent from '../animation/AnimatedScaleComponent';
import { getUsers, getPresence } from '../selectors';
import { getUsers } from '../selectors';
import { getOwnUserId } from '../users/userSelectors';

const styles = createStyleSheet({
Expand Down Expand Up @@ -51,7 +51,6 @@ export default function UserPickerCard(props: Props): Node {
const { filter, showOwnUser } = props;

const users = useSelector(state => getUsersToShow(state, showOwnUser));
const presences = useSelector(getPresence);

const [selectedState, setSelectedState] = useState<$ReadOnlyArray<UserOrBot>>([]);
const listRef = useRef<FlatList<UserOrBot> | null>(null);
Expand Down Expand Up @@ -80,7 +79,6 @@ export default function UserPickerCard(props: Props): Node {
<UserList
filter={filter}
users={users}
presences={presences}
selected={selectedState}
onPress={(user: UserOrBot) => {
setSelectedState(state => {
Expand Down
8 changes: 5 additions & 3 deletions src/users/UserList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import type { Node } from 'react';
import { SectionList } from 'react-native';
import { useSelector } from '../react-redux';

import type { PresenceState, UserOrBot } from '../types';
import type { UserOrBot } from '../types';
import { createStyleSheet } from '../styles';
import SectionHeader from '../common/SectionHeader';
import SearchEmptyState from '../common/SearchEmptyState';
import UserItem from './UserItem';
import { sortUserList, filterUserList, groupUsersByStatus } from './userHelpers';
import { getMutedUsers } from '../selectors';
import { getPresence } from '../directSelectors';

const styles = createStyleSheet({
list: {
Expand All @@ -22,13 +23,14 @@ type Props = $ReadOnly<{|
filter: string,
users: $ReadOnlyArray<UserOrBot>,
selected?: $ReadOnlyArray<UserOrBot>,
presences: PresenceState,
onPress: (user: UserOrBot) => void,
|}>;

export default function UserList(props: Props): Node {
const { filter, users, presences, onPress, selected = [] } = props;
const { filter, users, onPress, selected = [] } = props;
const mutedUsers = useSelector(getMutedUsers);
const presences = useSelector(getPresence);

const filteredUsers = filterUserList(users, filter).filter(user => !mutedUsers.has(user.user_id));

if (filteredUsers.length === 0) {
Expand Down

0 comments on commit 0390f3a

Please sign in to comment.