Chore: Evaluate SelectedUsersView - TypeScript (#4121)
This commit is contained in:
parent
e5f140e231
commit
8ac38a2e04
|
@ -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<ChatsStackParamList, 'SelectedUsersView'> {
|
||||
// REDUX STATE
|
||||
users: ISelectedUser[];
|
||||
loading: boolean;
|
||||
user: IUser;
|
||||
|
@ -106,9 +105,8 @@ class SelectedUsersView extends React.Component<ISelectedUsersViewProps, ISelect
|
|||
const db = database.active;
|
||||
const observable = await db.get('subscriptions').query(Q.where('t', 'd')).observeWithColumns(['room_updated_at']);
|
||||
|
||||
// TODO: Refactor when migrate room
|
||||
this.querySubscription = observable.subscribe((data: any) => {
|
||||
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<ISelectedUsersViewProps, ISelect
|
|||
}
|
||||
|
||||
handleSearch = async (text: string) => {
|
||||
// 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<ISelectedUsersViewProps, ISelect
|
|||
|
||||
isGroupChat = () => {
|
||||
const { maxUsers } = this.state;
|
||||
return maxUsers! > 2;
|
||||
return maxUsers && maxUsers > 2;
|
||||
};
|
||||
|
||||
isChecked = (username: string) => {
|
||||
|
@ -166,7 +162,7 @@ class SelectedUsersView extends React.Component<ISelectedUsersViewProps, ISelect
|
|||
|
||||
_onPressItem = (id: string, item = {} as ISelectedUser) => {
|
||||
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<ISelectedUsersViewProps, ISelect
|
|||
const { theme } = this.props;
|
||||
|
||||
const name = item.search ? item.name : item.fname;
|
||||
const username = item.search ? item.username! : item.name;
|
||||
const username = item.search ? (item.username as string) : item.name;
|
||||
let style = { borderColor: themes[theme].separatorColor };
|
||||
if (index === 0) {
|
||||
style = { ...style, ...sharedStyles.separatorTop };
|
||||
|
@ -258,9 +254,9 @@ class SelectedUsersView extends React.Component<ISelectedUsersViewProps, ISelect
|
|||
const { search, chats } = this.state;
|
||||
const { theme } = this.props;
|
||||
|
||||
const data = (search.length > 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 (
|
||||
<FlatList
|
||||
|
|
Loading…
Reference in New Issue