2020-07-31 18:22:30 +00:00
|
|
|
import React from 'react';
|
2022-03-07 21:16:20 +00:00
|
|
|
import { CompositeNavigationProp } from '@react-navigation/native';
|
|
|
|
import { StackNavigationOptions, StackNavigationProp } from '@react-navigation/stack';
|
|
|
|
import { FlatList, ListRenderItem } from 'react-native';
|
2020-07-31 18:22:30 +00:00
|
|
|
import { connect } from 'react-redux';
|
2021-02-26 16:01:45 +00:00
|
|
|
import { dequal } from 'dequal';
|
2020-07-31 18:22:30 +00:00
|
|
|
|
2020-08-28 19:41:08 +00:00
|
|
|
import I18n from '../../../i18n';
|
|
|
|
import RoomItem, { ROW_HEIGHT } from '../../../presentation/RoomItem';
|
|
|
|
import { MAX_SIDEBAR_WIDTH } from '../../../constants/tablet';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { isIOS, isTablet } from '../../../utils/deviceInfo';
|
2020-08-28 19:41:08 +00:00
|
|
|
import { getUserSelector } from '../../../selectors/login';
|
|
|
|
import { withTheme } from '../../../theme';
|
|
|
|
import { withDimensions } from '../../../dimensions';
|
|
|
|
import SafeAreaView from '../../../containers/SafeAreaView';
|
|
|
|
import { themes } from '../../../constants/colors';
|
|
|
|
import StatusBar from '../../../containers/StatusBar';
|
|
|
|
import { goRoom } from '../../../utils/goRoom';
|
2020-10-30 16:15:58 +00:00
|
|
|
import * as HeaderButton from '../../../containers/HeaderButton';
|
2020-08-28 19:41:08 +00:00
|
|
|
import RocketChat from '../../../lib/rocketchat';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { events, logEvent } from '../../../utils/log';
|
2020-07-31 18:22:30 +00:00
|
|
|
import { getInquiryQueueSelector } from '../selectors/inquiry';
|
2022-03-07 21:16:20 +00:00
|
|
|
import { IOmnichannelRoom, IApplicationState } from '../../../definitions';
|
|
|
|
import { DisplayMode } from '../../../constants/constantDisplayMode';
|
|
|
|
import { ChatsStackParamList } from '../../../stacks/types';
|
|
|
|
import { MasterDetailInsideStackParamList } from '../../../stacks/MasterDetailStack/types';
|
|
|
|
import { TSettingsValues } from '../../../reducers/settings';
|
|
|
|
|
|
|
|
interface INavigationOptions {
|
|
|
|
isMasterDetail: boolean;
|
|
|
|
navigation: CompositeNavigationProp<
|
|
|
|
StackNavigationProp<ChatsStackParamList, 'QueueListView'>,
|
|
|
|
StackNavigationProp<MasterDetailInsideStackParamList>
|
|
|
|
>;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IQueueListView extends INavigationOptions {
|
|
|
|
user: {
|
|
|
|
id: string;
|
|
|
|
username: string;
|
|
|
|
token: string;
|
|
|
|
};
|
|
|
|
width: number;
|
|
|
|
queued: IOmnichannelRoom[];
|
|
|
|
server: string;
|
|
|
|
useRealName?: TSettingsValues;
|
|
|
|
theme: string;
|
|
|
|
showAvatar: any;
|
|
|
|
displayMode: DisplayMode;
|
|
|
|
}
|
2020-07-31 18:22:30 +00:00
|
|
|
|
|
|
|
const INITIAL_NUM_TO_RENDER = isTablet ? 20 : 12;
|
2022-03-07 21:16:20 +00:00
|
|
|
const getItemLayout = (data: IOmnichannelRoom[] | null | undefined, index: number) => ({
|
2020-07-31 18:22:30 +00:00
|
|
|
length: ROW_HEIGHT,
|
|
|
|
offset: ROW_HEIGHT * index,
|
|
|
|
index
|
|
|
|
});
|
2022-03-07 21:16:20 +00:00
|
|
|
const keyExtractor = (item: IOmnichannelRoom) => item.rid;
|
2020-07-31 18:22:30 +00:00
|
|
|
|
2022-03-07 21:16:20 +00:00
|
|
|
class QueueListView extends React.Component<IQueueListView, any> {
|
|
|
|
private getScrollRef?: React.Ref<FlatList<IOmnichannelRoom>>;
|
|
|
|
|
|
|
|
private onEndReached: ((info: { distanceFromEnd: number }) => void) | null | undefined;
|
|
|
|
|
|
|
|
static navigationOptions = ({ navigation, isMasterDetail }: INavigationOptions) => {
|
|
|
|
const options: StackNavigationOptions = {
|
2020-07-31 18:22:30 +00:00
|
|
|
title: I18n.t('Queued_chats')
|
|
|
|
};
|
|
|
|
if (isMasterDetail) {
|
2020-10-30 16:15:58 +00:00
|
|
|
options.headerLeft = () => <HeaderButton.CloseModal navigation={navigation} testID='directory-view-close' />;
|
2020-07-31 18:22:30 +00:00
|
|
|
}
|
|
|
|
return options;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-07-31 18:22:30 +00:00
|
|
|
|
2022-03-07 21:16:20 +00:00
|
|
|
shouldComponentUpdate(nextProps: IQueueListView) {
|
2020-07-31 18:22:30 +00:00
|
|
|
const { queued } = this.props;
|
2021-02-26 16:01:45 +00:00
|
|
|
if (!dequal(nextProps.queued, queued)) {
|
2020-07-31 18:22:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-03-07 21:16:20 +00:00
|
|
|
onPressItem = (item = {} as IOmnichannelRoom) => {
|
2020-07-31 18:22:30 +00:00
|
|
|
logEvent(events.QL_GO_ROOM);
|
|
|
|
const { navigation, isMasterDetail } = this.props;
|
|
|
|
if (isMasterDetail) {
|
|
|
|
navigation.navigate('DrawerNavigator');
|
|
|
|
} else {
|
|
|
|
navigation.navigate('RoomsListView');
|
|
|
|
}
|
|
|
|
|
|
|
|
goRoom({
|
|
|
|
item: {
|
|
|
|
...item,
|
|
|
|
// we're calling v as visitor on our mergeSubscriptionsRooms
|
|
|
|
visitor: item.v
|
|
|
|
},
|
|
|
|
isMasterDetail
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-03-07 21:16:20 +00:00
|
|
|
getRoomTitle = (item: IOmnichannelRoom) => RocketChat.getRoomTitle(item);
|
2020-07-31 18:22:30 +00:00
|
|
|
|
2022-03-07 21:16:20 +00:00
|
|
|
getRoomAvatar = (item: IOmnichannelRoom) => RocketChat.getRoomAvatar(item);
|
2020-07-31 18:22:30 +00:00
|
|
|
|
2022-03-07 21:16:20 +00:00
|
|
|
getUidDirectMessage = (room: IOmnichannelRoom) => RocketChat.getUidDirectMessage(room);
|
2020-07-31 18:22:30 +00:00
|
|
|
|
2022-03-07 21:16:20 +00:00
|
|
|
renderItem: ListRenderItem<IOmnichannelRoom> = ({ item }) => {
|
2020-07-31 18:22:30 +00:00
|
|
|
const {
|
2021-09-13 20:41:05 +00:00
|
|
|
user: { id: userId, username, token },
|
2020-07-31 18:22:30 +00:00
|
|
|
server,
|
|
|
|
useRealName,
|
|
|
|
theme,
|
|
|
|
isMasterDetail,
|
2021-10-06 20:30:10 +00:00
|
|
|
width,
|
|
|
|
showAvatar,
|
|
|
|
displayMode
|
2020-07-31 18:22:30 +00:00
|
|
|
} = this.props;
|
|
|
|
const id = this.getUidDirectMessage(item);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<RoomItem
|
|
|
|
item={item}
|
|
|
|
theme={theme}
|
|
|
|
id={id}
|
|
|
|
type={item.t}
|
|
|
|
userId={userId}
|
|
|
|
username={username}
|
|
|
|
token={token}
|
|
|
|
baseUrl={server}
|
|
|
|
onPress={this.onPressItem}
|
2021-09-13 20:41:05 +00:00
|
|
|
testID={`queue-list-view-item-${item.name}`}
|
2020-07-31 18:22:30 +00:00
|
|
|
width={isMasterDetail ? MAX_SIDEBAR_WIDTH : width}
|
|
|
|
useRealName={useRealName}
|
|
|
|
getRoomTitle={this.getRoomTitle}
|
|
|
|
getRoomAvatar={this.getRoomAvatar}
|
|
|
|
visitor={item.v}
|
|
|
|
swipeEnabled={false}
|
2021-10-06 20:30:10 +00:00
|
|
|
showAvatar={showAvatar}
|
|
|
|
displayMode={displayMode}
|
2020-07-31 18:22:30 +00:00
|
|
|
/>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-07-31 18:22:30 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const { queued, theme } = this.props;
|
|
|
|
return (
|
2020-10-30 13:59:44 +00:00
|
|
|
<SafeAreaView testID='queue-list-view' style={{ backgroundColor: themes[theme].backgroundColor }}>
|
|
|
|
<StatusBar />
|
2020-07-31 18:22:30 +00:00
|
|
|
<FlatList
|
|
|
|
ref={this.getScrollRef}
|
|
|
|
data={queued}
|
|
|
|
extraData={queued}
|
|
|
|
keyExtractor={keyExtractor}
|
|
|
|
style={{ backgroundColor: themes[theme].backgroundColor }}
|
|
|
|
renderItem={this.renderItem}
|
|
|
|
getItemLayout={getItemLayout}
|
|
|
|
removeClippedSubviews={isIOS}
|
|
|
|
keyboardShouldPersistTaps='always'
|
|
|
|
initialNumToRender={INITIAL_NUM_TO_RENDER}
|
|
|
|
windowSize={9}
|
|
|
|
onEndReached={this.onEndReached}
|
|
|
|
onEndReachedThreshold={0.5}
|
|
|
|
/>
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-07 21:16:20 +00:00
|
|
|
const mapStateToProps = (state: IApplicationState) => ({
|
2020-07-31 18:22:30 +00:00
|
|
|
user: getUserSelector(state),
|
|
|
|
isMasterDetail: state.app.isMasterDetail,
|
|
|
|
server: state.server.server,
|
|
|
|
useRealName: state.settings.UI_Use_Real_Name,
|
2021-10-06 20:30:10 +00:00
|
|
|
queued: getInquiryQueueSelector(state),
|
|
|
|
showAvatar: state.sortPreferences.showAvatar,
|
|
|
|
displayMode: state.sortPreferences.displayMode
|
2020-07-31 18:22:30 +00:00
|
|
|
});
|
2021-12-03 19:27:57 +00:00
|
|
|
|
2020-07-31 18:22:30 +00:00
|
|
|
export default connect(mapStateToProps)(withDimensions(withTheme(QueueListView)));
|