chore: move interfaces to reducer and import on screen
This commit is contained in:
parent
f0977ddb22
commit
bad5643a4d
|
@ -7,19 +7,4 @@ export interface BaseScreen {
|
||||||
theme: string;
|
theme: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IUser {
|
|
||||||
_id: string;
|
|
||||||
name: string;
|
|
||||||
fname: string;
|
|
||||||
search?: boolean;
|
|
||||||
// username is used when is from searching
|
|
||||||
username?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserStatus = 'online' | 'offline';
|
|
||||||
export interface ActiveUser {
|
|
||||||
status: UserStatus;
|
|
||||||
statusText?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export * from './redux';
|
export * from './redux';
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
import { ActiveUser, ApplicationActions } from '../definitions';
|
import { ApplicationActions } from '../definitions';
|
||||||
import { SET_ACTIVE_USERS } from '../actions/actionsTypes';
|
import { SET_ACTIVE_USERS } from '../actions/actionsTypes';
|
||||||
|
|
||||||
|
type UserStatus = 'online' | 'offline';
|
||||||
|
export interface ActiveUser {
|
||||||
|
status: UserStatus;
|
||||||
|
statusText?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface IActiveUsers {
|
export interface IActiveUsers {
|
||||||
[key: string]: ActiveUser;
|
[key: string]: ActiveUser;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,17 @@
|
||||||
import { IUser, ApplicationActions } from '../definitions';
|
import { ApplicationActions } from '../definitions';
|
||||||
import { SELECTED_USERS } from '../actions/actionsTypes';
|
import { SELECTED_USERS } from '../actions/actionsTypes';
|
||||||
|
|
||||||
|
export interface ISelectedUser {
|
||||||
|
_id: string;
|
||||||
|
name: string;
|
||||||
|
fname: string;
|
||||||
|
search?: boolean;
|
||||||
|
// username is used when is from searching
|
||||||
|
username?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ISelectedUsers {
|
export interface ISelectedUsers {
|
||||||
users: IUser[];
|
users: ISelectedUser[];
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,14 +14,15 @@ 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 { ApplicationState, BaseScreen } from '../definitions';
|
||||||
import I18n from '../i18n';
|
import I18n from '../i18n';
|
||||||
import database from '../lib/database';
|
import database from '../lib/database';
|
||||||
import RocketChat from '../lib/rocketchat';
|
import RocketChat from '../lib/rocketchat';
|
||||||
import UserItem from '../presentation/UserItem';
|
import UserItem from '../presentation/UserItem';
|
||||||
|
import { ISelectedUser } from '../reducers/selectedUsers';
|
||||||
import { getUserSelector } from '../selectors/login';
|
import { getUserSelector } from '../selectors/login';
|
||||||
import { ChatsStackParamList } from '../stacks/types';
|
import { ChatsStackParamList } from '../stacks/types';
|
||||||
import { withTheme } from '../theme';
|
import { withTheme } from '../theme';
|
||||||
import { ApplicationState, BaseScreen, IUser } from '../definitions';
|
|
||||||
import { showErrorAlert } from '../utils/info';
|
import { showErrorAlert } from '../utils/info';
|
||||||
import log, { events, logEvent } from '../utils/log';
|
import log, { events, logEvent } from '../utils/log';
|
||||||
import sharedStyles from './Styles';
|
import sharedStyles from './Styles';
|
||||||
|
@ -31,14 +32,14 @@ const getItemLayout = (_: any, index: number) => ({ length: ITEM_WIDTH, offset:
|
||||||
|
|
||||||
interface ISelectedUsersViewState {
|
interface ISelectedUsersViewState {
|
||||||
maxUsers?: number;
|
maxUsers?: number;
|
||||||
search: IUser[];
|
search: ISelectedUser[];
|
||||||
chats: IUser[];
|
chats: ISelectedUser[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ISelectedUsersViewProps extends BaseScreen {
|
interface ISelectedUsersViewProps extends BaseScreen {
|
||||||
route: RouteProp<ChatsStackParamList, 'SelectedUsersView'>;
|
route: RouteProp<ChatsStackParamList, 'SelectedUsersView'>;
|
||||||
// REDUX STATE
|
// REDUX STATE
|
||||||
users: IUser[];
|
users: ISelectedUser[];
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
user: {
|
user: {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -146,7 +147,7 @@ class SelectedUsersView extends React.Component<ISelectedUsersViewProps, ISelect
|
||||||
return users.findIndex(el => el.name === username) !== -1;
|
return users.findIndex(el => el.name === username) !== -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
toggleUser = (user: IUser) => {
|
toggleUser = (user: ISelectedUser) => {
|
||||||
const { maxUsers } = this.state;
|
const { maxUsers } = this.state;
|
||||||
const {
|
const {
|
||||||
dispatch,
|
dispatch,
|
||||||
|
@ -171,7 +172,7 @@ class SelectedUsersView extends React.Component<ISelectedUsersViewProps, ISelect
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_onPressItem = (id: string, item = {} as IUser) => {
|
_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!, fname: item.name });
|
||||||
} else {
|
} else {
|
||||||
|
@ -179,7 +180,7 @@ class SelectedUsersView extends React.Component<ISelectedUsersViewProps, ISelect
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_onPressSelectedItem = (item: IUser) => this.toggleUser(item);
|
_onPressSelectedItem = (item: ISelectedUser) => this.toggleUser(item);
|
||||||
|
|
||||||
renderHeader = () => {
|
renderHeader = () => {
|
||||||
const { theme } = this.props;
|
const { theme } = this.props;
|
||||||
|
@ -218,7 +219,7 @@ class SelectedUsersView extends React.Component<ISelectedUsersViewProps, ISelect
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
renderSelectedItem = ({ item }: { item: IUser }) => {
|
renderSelectedItem = ({ item }: { item: ISelectedUser }) => {
|
||||||
const { theme } = this.props;
|
const { theme } = this.props;
|
||||||
return (
|
return (
|
||||||
<UserItem
|
<UserItem
|
||||||
|
@ -232,7 +233,7 @@ class SelectedUsersView extends React.Component<ISelectedUsersViewProps, ISelect
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
renderItem = ({ item, index }: { item: IUser; index: number }) => {
|
renderItem = ({ item, index }: { item: ISelectedUser; index: number }) => {
|
||||||
const { search, chats } = this.state;
|
const { search, chats } = this.state;
|
||||||
const { theme } = this.props;
|
const { theme } = this.props;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue