From 8ac38a2e04d67c13bc98ed7ce26840cacc3a7be5 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com> Date: Mon, 2 May 2022 10:09:10 -0300 Subject: [PATCH] Chore: Evaluate SelectedUsersView - TypeScript (#4121) --- app/views/SelectedUsersView.tsx | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/app/views/SelectedUsersView.tsx b/app/views/SelectedUsersView.tsx index 99471872..47eafaa8 100644 --- a/app/views/SelectedUsersView.tsx +++ b/app/views/SelectedUsersView.tsx @@ -13,7 +13,7 @@ import Loading from '../containers/Loading'; import SafeAreaView from '../containers/SafeAreaView'; import SearchBox from '../containers/SearchBox'; import StatusBar from '../containers/StatusBar'; -import { IApplicationState, IBaseScreen, ISubscription, IUser } from '../definitions'; +import { IApplicationState, IBaseScreen, ISearch, ISearchLocal, IUser } from '../definitions'; import I18n from '../i18n'; import database from '../lib/database'; import UserItem from '../containers/UserItem'; @@ -31,12 +31,11 @@ const getItemLayout = (_: any, index: number) => ({ length: ITEM_WIDTH, offset: interface ISelectedUsersViewState { maxUsers?: number; - search: ISelectedUser[]; + search: (ISearch | ISearchLocal)[]; chats: ISelectedUser[]; } interface ISelectedUsersViewProps extends IBaseScreen { - // REDUX STATE users: ISelectedUser[]; loading: boolean; user: IUser; @@ -106,9 +105,8 @@ class SelectedUsersView extends React.Component { - const chats = orderBy(data, ['roomUpdatedAt'], ['desc']); + this.querySubscription = observable.subscribe(data => { + const chats = orderBy(data, ['roomUpdatedAt'], ['desc']) as ISelectedUser[]; this.setState({ chats }); }); } catch (e) { @@ -121,9 +119,7 @@ class SelectedUsersView extends React.Component { - // TODO: When migrate rocketchat.js pass the param IUser to there and the return should be - // IUser | TSubscriptionModel, this because we do a local search too - const result = (await search({ text, filterRooms: false })) as ISelectedUser[]; + const result = await search({ text, filterRooms: false }); this.setState({ search: result }); @@ -131,7 +127,7 @@ class SelectedUsersView extends React.Component { const { maxUsers } = this.state; - return maxUsers! > 2; + return maxUsers && maxUsers > 2; }; isChecked = (username: string) => { @@ -166,7 +162,7 @@ class SelectedUsersView extends React.Component { if (item.search) { - this.toggleUser({ _id: item._id, name: item.username!, fname: item.name }); + this.toggleUser({ _id: item._id, name: item.username as string, fname: item.name }); } else { this.toggleUser({ _id: item._id, name: item.name, fname: item.fname }); } @@ -230,7 +226,7 @@ class SelectedUsersView extends React.Component 0 ? search : chats) - // filter DM between multiple users - .filter(sub => !isGroupChat(sub as ISubscription)); + const searchOrChats = (search.length > 0 ? search : chats) as ISelectedUser[]; + // filter DM between multiple users + const data = searchOrChats.filter(sub => !isGroupChat(sub)); return (