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';
|
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';
|
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';
|
|
|
|
import { goRoom } from '../../../utils/goRoom';
|
2020-10-30 16:15:58 +00:00
|
|
|
import * as HeaderButton from '../../../containers/HeaderButton';
|
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';
|
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-04-28 20:37:25 +00:00
|
|
|
import { getRoomAvatar, getRoomTitle, getUidDirectMessage } from '../../../lib/methods';
|
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);
|
|
|
|
const { theme, colors } = useTheme();
|
|
|
|
const { width } = useDimensions();
|
|
|
|
|
|
|
|
const { userId, token, username } = useSelector(
|
|
|
|
(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 server = useSelector((state: IApplicationState) => state.server.server);
|
|
|
|
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);
|
|
|
|
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-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}
|
|
|
|
theme={theme}
|
|
|
|
id={id}
|
|
|
|
type={item.t}
|
|
|
|
userId={userId}
|
|
|
|
username={username}
|
|
|
|
token={token}
|
|
|
|
baseUrl={server}
|
2022-05-23 17:33:58 +00:00
|
|
|
onPress={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}
|
2022-04-28 20:37:25 +00:00
|
|
|
getRoomTitle={getRoomTitle}
|
|
|
|
getRoomAvatar={getRoomAvatar}
|
2020-07-31 18:22:30 +00:00
|
|
|
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
|
|
|
|
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;
|