|
1 | 1 | /* @flow strict-local */ |
2 | | -import React, { useState } from 'react'; |
| 2 | +import React, { useCallback, useState } from 'react'; |
3 | 3 | import type { Node } from 'react'; |
4 | 4 |
|
5 | 5 | import type { RouteProp } from '../react-navigation'; |
6 | 6 | import type { AppNavigationProp } from '../nav/AppNavigator'; |
7 | 7 | import Screen from '../common/Screen'; |
8 | | -import UsersCard from './UsersCard'; |
| 8 | +import UserList from './UserList'; |
| 9 | +import type { UserOrBot } from '../types'; |
| 10 | +import { useSelector, useDispatch } from '../react-redux'; |
| 11 | +import { pm1to1NarrowFromUser } from '../utils/narrow'; |
| 12 | +import { getUsers, getPresence } from '../selectors'; |
| 13 | +import { navigateBack, doNarrow } from '../actions'; |
| 14 | +import { useNavigation } from '../react-navigation'; |
9 | 15 |
|
10 | 16 | type Props = $ReadOnly<{| |
11 | 17 | navigation: AppNavigationProp<'users'>, |
12 | 18 | route: RouteProp<'users', void>, |
13 | 19 | |}>; |
14 | 20 |
|
15 | 21 | export default function UsersScreen(props: Props): Node { |
| 22 | + const dispatch = useDispatch(); |
| 23 | + const users = useSelector(getUsers); |
| 24 | + const presences = useSelector(getPresence); |
| 25 | + |
| 26 | + const navigation = useNavigation(); |
| 27 | + const handleUserNarrow = useCallback( |
| 28 | + (user: UserOrBot) => { |
| 29 | + navigation.dispatch(navigateBack()); |
| 30 | + dispatch(doNarrow(pm1to1NarrowFromUser(user))); |
| 31 | + }, |
| 32 | + [dispatch, navigation], |
| 33 | + ); |
| 34 | + |
16 | 35 | const [filter, setFilter] = useState<string>(''); |
17 | 36 |
|
18 | 37 | return ( |
19 | 38 | <Screen search scrollEnabled={false} searchBarOnChange={setFilter}> |
20 | | - <UsersCard filter={filter} /> |
| 39 | + <UserList users={users} filter={filter} presences={presences} onPress={handleUserNarrow} /> |
21 | 40 | </Screen> |
22 | 41 | ); |
23 | 42 | } |
0 commit comments