2022-05-23 17:33:58 +00:00
|
|
|
import React, { useEffect, useRef } from 'react';
|
|
|
|
import { CompositeNavigationProp, useNavigation } from '@react-navigation/native';
|
2022-03-07 21:16:20 +00:00
|
|
|
import { StackNavigationOptions, StackNavigationProp } from '@react-navigation/stack';
|
|
|
|
import { FlatList, ListRenderItem } from 'react-native';
|
2022-05-23 17:33:58 +00:00
|
|
|
import { shallowEqual, useSelector } from 'react-redux';
|
2020-07-31 18:22:30 +00:00
|
|
|
|
2020-08-28 19:41:08 +00:00
|
|
|
import I18n from '../../../i18n';
|
2022-04-20 21:37:54 +00:00
|
|
|
import RoomItem, { ROW_HEIGHT } from '../../../containers/RoomItem';
|
2020-08-28 19:41:08 +00:00
|
|
|
import { getUserSelector } from '../../../selectors/login';
|
2022-05-23 17:33:58 +00:00
|
|
|
import { useTheme } from '../../../theme';
|
|
|
|
import { useDimensions } from '../../../dimensions';
|
2020-08-28 19:41:08 +00:00
|
|
|
import SafeAreaView from '../../../containers/SafeAreaView';
|
|
|
|
import StatusBar from '../../../containers/StatusBar';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { goRoom } from '../../../lib/methods/helpers/goRoom';
|
2020-10-30 16:15:58 +00:00
|
|
|
import * as HeaderButton from '../../../containers/HeaderButton';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { events, logEvent } from '../../../lib/methods/helpers/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';
|
2022-05-23 17:33:58 +00:00
|
|
|
import { MAX_SIDEBAR_WIDTH } from '../../../lib/constants';
|
2022-03-07 21:16:20 +00:00
|
|
|
import { ChatsStackParamList } from '../../../stacks/types';
|
|
|
|
import { MasterDetailInsideStackParamList } from '../../../stacks/MasterDetailStack/types';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { getRoomAvatar, getRoomTitle, getUidDirectMessage, isIOS, isTablet } from '../../../lib/methods/helpers';
|
2022-03-07 21:16:20 +00:00
|
|
|
|
2022-05-23 17:33:58 +00:00
|
|
|
type TNavigation = CompositeNavigationProp<
|
|
|
|
StackNavigationProp<ChatsStackParamList, 'QueueListView'>,
|
|
|
|
StackNavigationProp<MasterDetailInsideStackParamList>
|
|
|
|
>;
|
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-05-23 17:33:58 +00:00
|
|
|
const QueueListView = React.memo(() => {
|
|
|
|
const navigation = useNavigation<TNavigation>();
|
|
|
|
const getScrollRef = useRef<FlatList<IOmnichannelRoom>>(null);
|
2022-06-27 18:23:43 +00:00
|
|
|
const { colors } = useTheme();
|
2022-05-23 17:33:58 +00:00
|
|
|
const { width } = useDimensions();
|
|
|
|
|
2022-06-27 18:23:43 +00:00
|
|
|
const { username } = useSelector(
|
2022-05-23 17:33:58 +00:00
|
|
|
(state: IApplicationState) => ({
|
|
|
|
userId: getUserSelector(state).id,
|
|
|
|
username: getUserSelector(state).username,
|
|
|
|
token: getUserSelector(state).token
|
|
|
|
}),
|
|
|
|
shallowEqual
|
|
|
|
);
|
|
|
|
|
|
|
|
const { showAvatar, displayMode } = useSelector(
|
|
|
|
(state: IApplicationState) => ({
|
|
|
|
showAvatar: state.sortPreferences.showAvatar,
|
|
|
|
displayMode: state.sortPreferences.displayMode
|
|
|
|
}),
|
|
|
|
shallowEqual
|
|
|
|
);
|
|
|
|
|
|
|
|
const isMasterDetail = useSelector((state: IApplicationState) => state.app.isMasterDetail);
|
|
|
|
const useRealName = useSelector((state: IApplicationState) => state.settings.UI_Use_Real_Name);
|
|
|
|
const queued = useSelector((state: IApplicationState) => getInquiryQueueSelector(state));
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-03-07 21:16:20 +00:00
|
|
|
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
|
|
|
}
|
2022-05-23 17:33:58 +00:00
|
|
|
navigation.setOptions(options);
|
|
|
|
}, [isMasterDetail, navigation]);
|
2020-07-31 18:22:30 +00:00
|
|
|
|
2022-05-23 17:33:58 +00:00
|
|
|
const onPressItem = (item = {} as IOmnichannelRoom) => {
|
2020-07-31 18:22:30 +00:00
|
|
|
logEvent(events.QL_GO_ROOM);
|
|
|
|
goRoom({
|
|
|
|
item: {
|
|
|
|
...item,
|
|
|
|
// we're calling v as visitor on our mergeSubscriptionsRooms
|
|
|
|
visitor: item.v
|
|
|
|
},
|
2022-11-25 13:21:56 +00:00
|
|
|
isMasterDetail,
|
|
|
|
popToRoot: true
|
2020-07-31 18:22:30 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-05-23 17:33:58 +00:00
|
|
|
const renderItem: ListRenderItem<IOmnichannelRoom> = ({ item }) => {
|
2022-04-28 20:37:25 +00:00
|
|
|
const id = getUidDirectMessage(item);
|
2020-07-31 18:22:30 +00:00
|
|
|
return (
|
|
|
|
<RoomItem
|
|
|
|
item={item}
|
|
|
|
id={id}
|
|
|
|
username={username}
|
2022-05-23 17:33:58 +00:00
|
|
|
onPress={onPressItem}
|
2020-07-31 18:22:30 +00:00
|
|
|
width={isMasterDetail ? MAX_SIDEBAR_WIDTH : width}
|
2022-06-27 18:23:43 +00:00
|
|
|
useRealName={!!useRealName}
|
2022-04-28 20:37:25 +00:00
|
|
|
getRoomTitle={getRoomTitle}
|
|
|
|
getRoomAvatar={getRoomAvatar}
|
2020-07-31 18:22:30 +00:00
|
|
|
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
|
|
|
|
2022-05-23 17:33:58 +00:00
|
|
|
return (
|
|
|
|
<SafeAreaView testID='queue-list-view' style={{ backgroundColor: colors.backgroundColor }}>
|
|
|
|
<StatusBar />
|
|
|
|
<FlatList
|
|
|
|
ref={getScrollRef}
|
|
|
|
data={queued}
|
|
|
|
extraData={queued}
|
|
|
|
keyExtractor={keyExtractor}
|
|
|
|
style={{ backgroundColor: colors.backgroundColor }}
|
|
|
|
renderItem={renderItem}
|
|
|
|
getItemLayout={getItemLayout}
|
|
|
|
removeClippedSubviews={isIOS}
|
|
|
|
keyboardShouldPersistTaps='always'
|
|
|
|
initialNumToRender={INITIAL_NUM_TO_RENDER}
|
|
|
|
windowSize={9}
|
|
|
|
onEndReachedThreshold={0.5}
|
|
|
|
/>
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
2020-07-31 18:22:30 +00:00
|
|
|
});
|
2021-12-03 19:27:57 +00:00
|
|
|
|
2022-05-23 17:33:58 +00:00
|
|
|
export default QueueListView;
|