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 SafeAreaView from '../containers/SafeAreaView';
|
||||||
import SearchBox from '../containers/SearchBox';
|
import SearchBox from '../containers/SearchBox';
|
||||||
import StatusBar from '../containers/StatusBar';
|
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 I18n from '../i18n';
|
||||||
import database from '../lib/database';
|
import database from '../lib/database';
|
||||||
import UserItem from '../containers/UserItem';
|
import UserItem from '../containers/UserItem';
|
||||||
|
@ -31,12 +31,11 @@ const getItemLayout = (_: any, index: number) => ({ length: ITEM_WIDTH, offset:
|
||||||
|
|
||||||
interface ISelectedUsersViewState {
|
interface ISelectedUsersViewState {
|
||||||
maxUsers?: number;
|
maxUsers?: number;
|
||||||
search: ISelectedUser[];
|
search: (ISearch | ISearchLocal)[];
|
||||||
chats: ISelectedUser[];
|
chats: ISelectedUser[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ISelectedUsersViewProps extends IBaseScreen<ChatsStackParamList, 'SelectedUsersView'> {
|
interface ISelectedUsersViewProps extends IBaseScreen<ChatsStackParamList, 'SelectedUsersView'> {
|
||||||
// REDUX STATE
|
|
||||||
users: ISelectedUser[];
|
users: ISelectedUser[];
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
user: IUser;
|
user: IUser;
|
||||||
|
@ -106,9 +105,8 @@ class SelectedUsersView extends React.Component<ISelectedUsersViewProps, ISelect
|
||||||
const db = database.active;
|
const db = database.active;
|
||||||
const observable = await db.get('subscriptions').query(Q.where('t', 'd')).observeWithColumns(['room_updated_at']);
|
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 => {
|
||||||
this.querySubscription = observable.subscribe((data: any) => {
|
const chats = orderBy(data, ['roomUpdatedAt'], ['desc']) as ISelectedUser[];
|
||||||
const chats = orderBy(data, ['roomUpdatedAt'], ['desc']);
|
|
||||||
this.setState({ chats });
|
this.setState({ chats });
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -121,9 +119,7 @@ class SelectedUsersView extends React.Component<ISelectedUsersViewProps, ISelect
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSearch = async (text: string) => {
|
handleSearch = async (text: string) => {
|
||||||
// TODO: When migrate rocketchat.js pass the param IUser to there and the return should be
|
const result = await search({ text, filterRooms: false });
|
||||||
// IUser | TSubscriptionModel, this because we do a local search too
|
|
||||||
const result = (await search({ text, filterRooms: false })) as ISelectedUser[];
|
|
||||||
this.setState({
|
this.setState({
|
||||||
search: result
|
search: result
|
||||||
});
|
});
|
||||||
|
@ -131,7 +127,7 @@ class SelectedUsersView extends React.Component<ISelectedUsersViewProps, ISelect
|
||||||
|
|
||||||
isGroupChat = () => {
|
isGroupChat = () => {
|
||||||
const { maxUsers } = this.state;
|
const { maxUsers } = this.state;
|
||||||
return maxUsers! > 2;
|
return maxUsers && maxUsers > 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
isChecked = (username: string) => {
|
isChecked = (username: string) => {
|
||||||
|
@ -166,7 +162,7 @@ class SelectedUsersView extends React.Component<ISelectedUsersViewProps, ISelect
|
||||||
|
|
||||||
_onPressItem = (id: string, item = {} as ISelectedUser) => {
|
_onPressItem = (id: string, item = {} as ISelectedUser) => {
|
||||||
if (item.search) {
|
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 {
|
} else {
|
||||||
this.toggleUser({ _id: item._id, name: item.name, fname: item.fname });
|
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 { theme } = this.props;
|
||||||
|
|
||||||
const name = item.search ? item.name : item.fname;
|
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 };
|
let style = { borderColor: themes[theme].separatorColor };
|
||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
style = { ...style, ...sharedStyles.separatorTop };
|
style = { ...style, ...sharedStyles.separatorTop };
|
||||||
|
@ -258,9 +254,9 @@ class SelectedUsersView extends React.Component<ISelectedUsersViewProps, ISelect
|
||||||
const { search, chats } = this.state;
|
const { search, chats } = this.state;
|
||||||
const { theme } = this.props;
|
const { theme } = this.props;
|
||||||
|
|
||||||
const data = (search.length > 0 ? search : chats)
|
const searchOrChats = (search.length > 0 ? search : chats) as ISelectedUser[];
|
||||||
// filter DM between multiple users
|
// filter DM between multiple users
|
||||||
.filter(sub => !isGroupChat(sub as ISubscription));
|
const data = searchOrChats.filter(sub => !isGroupChat(sub));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FlatList
|
<FlatList
|
||||||
|
|
Loading…
Reference in New Issue