From 9d7450b300f162f48cf9cabd2a3302eada5ac013 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 21 Dec 2021 10:17:11 -0300 Subject: [PATCH] chore: remove mapDispatchToProps to use dispatch prop and clear some types --- app/views/SelectedUsersView.tsx | 82 +++++++++++++++------------------ 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/app/views/SelectedUsersView.tsx b/app/views/SelectedUsersView.tsx index 8d4a19fc4..3e2ddeb97 100644 --- a/app/views/SelectedUsersView.tsx +++ b/app/views/SelectedUsersView.tsx @@ -1,30 +1,30 @@ -import React from 'react'; -import { StackNavigationProp } from '@react-navigation/stack'; +import { Q } from '@nozbe/watermelondb'; import { RouteProp } from '@react-navigation/native'; +import orderBy from 'lodash/orderBy'; +import React from 'react'; import { FlatList, View } from 'react-native'; import { connect } from 'react-redux'; -import orderBy from 'lodash/orderBy'; -import { Q } from '@nozbe/watermelondb'; import { Subscription } from 'rxjs'; +import { addUser, removeUser, reset } from '../actions/selectedUsers'; +import { themes } from '../constants/colors'; +import * as HeaderButton from '../containers/HeaderButton'; import * as List from '../containers/List'; +import Loading from '../containers/Loading'; +import SafeAreaView from '../containers/SafeAreaView'; +import SearchBox from '../containers/SearchBox'; +import StatusBar from '../containers/StatusBar'; +import I18n from '../i18n'; import database from '../lib/database'; import RocketChat from '../lib/rocketchat'; import UserItem from '../presentation/UserItem'; -import Loading from '../containers/Loading'; -import I18n from '../i18n'; -import log, { events, logEvent } from '../utils/log'; -import SearchBox from '../containers/SearchBox'; -import * as HeaderButton from '../containers/HeaderButton'; -import StatusBar from '../containers/StatusBar'; -import { themes } from '../constants/colors'; -import { withTheme } from '../theme'; import { getUserSelector } from '../selectors/login'; -import { addUser as addUserAction, removeUser as removeUserAction, reset as resetAction } from '../actions/selectedUsers'; -import { showErrorAlert } from '../utils/info'; -import SafeAreaView from '../containers/SafeAreaView'; -import sharedStyles from './Styles'; import { ChatsStackParamList } from '../stacks/types'; +import { withTheme } from '../theme'; +import { ApplicationState, BaseScreen } from '../types'; +import { showErrorAlert } from '../utils/info'; +import log, { events, logEvent } from '../utils/log'; +import sharedStyles from './Styles'; const ITEM_WIDTH = 250; const getItemLayout = (_: any, index: number) => ({ length: ITEM_WIDTH, offset: ITEM_WIDTH * index, index }); @@ -37,19 +37,8 @@ interface IUser { // username is used when is from searching username?: string; } -interface ISelectedUsersViewState { - maxUsers?: number; - search: IUser[]; - chats: IUser[]; -} -interface ISelectedUsersViewProps { - navigation: StackNavigationProp; - route: RouteProp; - baseUrl: string; - addUser(user: IUser): void; - removeUser(user: IUser): void; - reset(): void; +type State = { users: IUser[]; loading: boolean; user: { @@ -58,7 +47,17 @@ interface ISelectedUsersViewProps { username: string; name: string; }; - theme: string; + baseUrl: string; +}; + +interface ISelectedUsersViewState { + maxUsers?: number; + search: IUser[]; + chats: IUser[]; +} + +interface ISelectedUsersViewProps extends BaseScreen, State { + route: RouteProp; } class SelectedUsersView extends React.Component { @@ -75,9 +74,9 @@ class SelectedUsersView extends React.Component { const { maxUsers } = this.state; const { - addUser, - removeUser, + dispatch, users, user: { username } } = this.props; @@ -177,10 +175,10 @@ class SelectedUsersView extends React.Component ({ +const mapStateToProps = (state: ApplicationState) => ({ baseUrl: state.server.server, users: state.selectedUsers.users, loading: state.selectedUsers.loading, user: getUserSelector(state) }); -const mapDispatchToProps = (dispatch: any) => ({ - addUser: (user: any) => dispatch(addUserAction(user)), - removeUser: (user: any) => dispatch(removeUserAction(user)), - reset: () => dispatch(resetAction()) -}); - -export default connect(mapStateToProps, mapDispatchToProps)(withTheme(SelectedUsersView)); +export default connect(mapStateToProps)(withTheme(SelectedUsersView));