Skip to content

Commit 279ec85

Browse files
authored
chore: Migrate RoomsListView to hooks (#6502)
1 parent 4a9307b commit 279ec85

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+972
-1387
lines changed

app/actions/actionsTypes.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ function createRequestTypes(base = {}, types = defaultTypes): Record<string, str
1212
export const LOGIN = createRequestTypes('LOGIN', [...defaultTypes, 'SET_SERVICES', 'SET_PREFERENCE', 'SET_LOCAL_AUTHENTICATED']);
1313
export const SHARE = createRequestTypes('SHARE', ['SET_PARAMS']);
1414
export const USER = createRequestTypes('USER', ['SET', 'CLEAR']);
15-
export const ROOMS = createRequestTypes('ROOMS', [
16-
...defaultTypes,
17-
'REFRESH',
18-
'SET_SEARCH',
19-
'OPEN_SEARCH_HEADER',
20-
'CLOSE_SEARCH_HEADER'
21-
]);
15+
export const ROOMS = createRequestTypes('ROOMS', [...defaultTypes, 'REFRESH']);
2216
export const ROOM = createRequestTypes('ROOM', [
2317
'SUBSCRIBE',
2418
'UNSUBSCRIBE',

app/actions/rooms.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,3 @@ export function roomsRefresh(): Action {
4545
type: ROOMS.REFRESH
4646
};
4747
}
48-
49-
export function setSearch(searchText: string): ISetSearch {
50-
return {
51-
type: ROOMS.SET_SEARCH,
52-
searchText
53-
};
54-
}
55-
56-
export function openSearchHeader(): Action {
57-
return {
58-
type: ROOMS.OPEN_SEARCH_HEADER
59-
};
60-
}
61-
62-
export function closeSearchHeader(): Action {
63-
return {
64-
type: ROOMS.CLOSE_SEARCH_HEADER
65-
};
66-
}

app/containers/Header/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const Header = ({ options, navigation, route }: IHeader) => {
2626
route.name === 'RoomsListView' ||
2727
route.name === 'ShareListView' ||
2828
route.name === 'ShareView' ||
29-
route.name === 'AttachmentView';
29+
route.name === 'AttachmentView' ||
30+
route.name === 'DrawerNavigator';
3031

3132
const handleOnLayout = ({
3233
nativeEvent: {

app/containers/RoomHeader/RoomHeader.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { TUserStatus, IOmnichannelSource } from '../../definitions';
1111
import { useTheme } from '../../theme';
1212
import { useAppSelector } from '../../lib/hooks';
1313
import useStatusAccessibilityLabel from '../../lib/hooks/useStatusAccessibilityLabel';
14+
import { IUsersTyping } from '../../reducers/usersTyping';
1415

1516
const HIT_SLOP = {
1617
top: 5,
@@ -46,7 +47,7 @@ const styles = StyleSheet.create({
4647
});
4748

4849
type TRoomHeaderSubTitle = {
49-
usersTyping: [];
50+
usersTyping: IUsersTyping;
5051
subtitle?: string;
5152
renderFunc?: () => React.ReactElement;
5253
scale: number;
@@ -71,7 +72,7 @@ interface IRoomHeader {
7172
tmid?: string;
7273
teamMain?: boolean;
7374
status?: TUserStatus;
74-
usersTyping: [];
75+
usersTyping: IUsersTyping;
7576
isGroupChat?: boolean;
7677
parentTitle?: string;
7778
onPress: Function;

app/containers/RoomItem/RoomItem.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ const RoomItem = ({
4747
swipeEnabled = true,
4848
onPress,
4949
onLongPress,
50-
toggleFav,
51-
toggleRead,
52-
hideChannel,
5350
teamMain,
5451
autoJoin,
5552
showAvatar,
@@ -80,11 +77,8 @@ const RoomItem = ({
8077
onLongPress={onLongPress}
8178
width={width}
8279
favorite={favorite}
83-
toggleFav={toggleFav}
8480
isRead={isRead}
8581
rid={rid}
86-
toggleRead={toggleRead}
87-
hideChannel={hideChannel}
8882
testID={testID}
8983
type={type}
9084
isFocused={!!isFocused}

app/containers/RoomItem/Touchable.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import { LeftActions, RightActions } from './Actions';
2020
import { ITouchableProps } from './interfaces';
2121
import { useTheme } from '../../theme';
2222
import I18n from '../../i18n';
23+
import { toggleFav } from '../../lib/methods/toggleFav';
24+
import { toggleRead } from '../../lib/methods/toggleRead';
25+
import { hideRoom } from '../../lib/methods/hideRoom';
26+
import { useAppSelector } from '../../lib/hooks/useAppSelector';
2327

2428
const Touchable = ({
2529
children,
@@ -31,15 +35,12 @@ const Touchable = ({
3135
favorite,
3236
isRead,
3337
rid,
34-
toggleFav,
35-
toggleRead,
36-
hideChannel,
3738
isFocused,
3839
swipeEnabled,
3940
displayMode
4041
}: ITouchableProps): React.ReactElement => {
4142
const { colors } = useTheme();
42-
43+
const serverVersion = useAppSelector(state => state.server.version);
4344
const rowOffSet = useSharedValue(0);
4445
const transX = useSharedValue(0);
4546
const rowState = useSharedValue(0); // 0: closed, 1: right opened, -1: left opened
@@ -52,22 +53,16 @@ const Touchable = ({
5253
};
5354

5455
const handleToggleFav = () => {
55-
if (toggleFav) {
56-
toggleFav(rid, favorite);
57-
}
56+
toggleFav(rid, favorite);
5857
close();
5958
};
6059

6160
const handleToggleRead = () => {
62-
if (toggleRead) {
63-
toggleRead(rid, isRead);
64-
}
61+
toggleRead(rid, isRead, serverVersion);
6562
};
6663

6764
const handleHideChannel = () => {
68-
if (hideChannel) {
69-
hideChannel(rid, type);
70-
}
65+
hideRoom(rid, type);
7166
};
7267

7368
const onToggleReadPress = () => {

app/containers/RoomItem/index.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ const RoomItemContainer = React.memo(
1515
onPress,
1616
onLongPress,
1717
width,
18-
toggleFav,
19-
toggleRead,
20-
hideChannel,
2118
isFocused,
2219
showLastMessage,
2320
username,
@@ -73,9 +70,6 @@ const RoomItemContainer = React.memo(
7370
favorite={item.f}
7471
rid={item.rid}
7572
userId={userId}
76-
toggleFav={toggleFav}
77-
toggleRead={toggleRead}
78-
hideChannel={hideChannel}
7973
testID={testID}
8074
type={item.t}
8175
isFocused={isFocused}

app/containers/RoomItem/interfaces.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import Animated from 'react-native-reanimated';
33

44
import { TSupportedThemes } from '../../theme';
5-
import { TUserStatus, ILastMessage, SubscriptionType, IOmnichannelSource } from '../../definitions';
5+
import { TUserStatus, ILastMessage, SubscriptionType, IOmnichannelSource, ISubscription } from '../../definitions';
66

77
export interface ILeftActionsProps {
88
transX: Animated.SharedValue<number>;
@@ -156,3 +156,8 @@ export interface IIconOrAvatar {
156156
showLastMessage: boolean;
157157
sourceType: IOmnichannelSource;
158158
}
159+
160+
export interface IRoomItem extends ISubscription {
161+
search?: boolean;
162+
outside?: boolean;
163+
}

app/definitions/redux/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ import { ITroubleshootingNotification } from '../../reducers/troubleshootingNoti
4444
import { TActionTroubleshootingNotification } from '../../actions/troubleshootingNotification';
4545
import { ISupportedVersionsState } from '../../reducers/supportedVersions';
4646
import { IInAppFeedbackState } from '../../reducers/inAppFeedback';
47+
import { IRooms } from '../../reducers/rooms';
48+
import { IPreferences } from '../IPreferences';
49+
import { ICustomEmojis } from '../IEmoji';
50+
import { IUsersTyping } from '../../reducers/usersTyping';
4751

4852
export interface IApplicationState {
4953
settings: TSettingsState;
@@ -54,12 +58,12 @@ export interface IApplicationState {
5458
app: IApp;
5559
createChannel: ICreateChannel;
5660
room: IRoom;
57-
rooms: any;
58-
sortPreferences: any;
61+
rooms: IRooms;
62+
sortPreferences: IPreferences;
5963
share: IShare;
60-
customEmojis: any;
64+
customEmojis: ICustomEmojis;
6165
activeUsers: IActiveUsers;
62-
usersTyping: any;
66+
usersTyping: IUsersTyping;
6367
inviteLinks: IInviteLinks;
6468
createDiscussion: ICreateDiscussion;
6569
inquiry: IInquiry;

app/ee/omnichannel/containers/OmnichannelHeader/index.tsx

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,36 @@
1-
import React, { memo, useEffect, useState } from 'react';
1+
import React, { memo } from 'react';
22
import { View } from 'react-native';
3+
import { useNavigation } from '@react-navigation/native';
4+
import { shallowEqual } from 'react-redux';
35

46
import * as List from '../../../../containers/List';
57
import styles from './styles';
6-
import { themes } from '../../../../lib/constants';
78
import { useTheme } from '../../../../theme';
8-
import { IUser } from '../../../../definitions';
99
import { showConfirmationAlert } from '../../../../lib/methods/helpers/info';
1010
import I18n from '../../../../i18n';
1111
import { changeLivechatStatus, isOmnichannelStatusAvailable } from '../../lib';
1212
import OmnichannelQueue from './OmnichannelQueue';
1313
import { isOmnichannelModuleAvailable } from '../../../../lib/methods';
1414
import Switch from '../../../../containers/Switch';
15+
import { useAppSelector } from '../../../../lib/hooks/useAppSelector';
16+
import { getUserSelector } from '../../../../selectors/login';
17+
import { events, logEvent } from '../../../../lib/methods/helpers/log';
18+
import { getInquiryQueueSelector } from '../../selectors/inquiry';
1519

16-
interface IOmnichannelStatus {
17-
searching: boolean;
18-
goQueue: () => void;
19-
queueSize: number;
20-
inquiryEnabled: boolean;
21-
user: IUser;
22-
}
20+
const OmnichannelStatus = memo(() => {
21+
const { colors } = useTheme();
22+
const { roles, statusLivechat } = useAppSelector(state => getUserSelector(state), shallowEqual);
23+
const inquiryEnabled = useAppSelector(state => state.inquiry.enabled);
24+
const queueSize = useAppSelector(state => getInquiryQueueSelector(state).length);
25+
const isMasterDetail = useAppSelector(state => state.app.isMasterDetail);
26+
const navigation = useNavigation<any>();
2327

24-
const OmnichannelStatus = memo(({ searching, goQueue, queueSize, user }: IOmnichannelStatus) => {
25-
const { theme } = useTheme();
26-
const [status, setStatus] = useState(isOmnichannelStatusAvailable(user));
27-
28-
useEffect(() => {
29-
setStatus(isOmnichannelStatusAvailable(user));
30-
}, [user.statusLivechat]);
31-
32-
if (searching || !(isOmnichannelModuleAvailable() && user?.roles?.includes('livechat-agent'))) {
28+
if (!(isOmnichannelModuleAvailable() && roles?.includes('livechat-agent'))) {
3329
return null;
3430
}
3531

3632
const toggleLivechat = async () => {
37-
// if not-available, prompt to change to available
38-
if (!isOmnichannelStatusAvailable(user)) {
33+
if (!isOmnichannelStatusAvailable(statusLivechat)) {
3934
showConfirmationAlert({
4035
message: I18n.t('Omnichannel_enable_alert'),
4136
confirmationText: I18n.t('Yes'),
@@ -49,29 +44,42 @@ const OmnichannelStatus = memo(({ searching, goQueue, queueSize, user }: IOmnich
4944
});
5045
} else {
5146
try {
52-
setStatus(v => !v);
5347
await changeLivechatStatus();
5448
} catch {
55-
setStatus(v => !v);
49+
// Do nothing
5650
}
5751
}
5852
};
5953

54+
const goQueue = () => {
55+
logEvent(events.RL_GO_QUEUE);
56+
57+
if (!inquiryEnabled) {
58+
return;
59+
}
60+
61+
if (isMasterDetail) {
62+
navigation.navigate('ModalStackNavigator', { screen: 'QueueListView' });
63+
} else {
64+
navigation.navigate('QueueListView');
65+
}
66+
};
67+
6068
return (
6169
<>
6270
<List.Item
6371
title='Omnichannel'
64-
color={themes[theme].fontDefault}
72+
color={colors.fontDefault}
6573
onPress={toggleLivechat}
66-
additionalAcessibilityLabel={status}
74+
additionalAcessibilityLabel={statusLivechat}
6775
right={() => (
6876
<View style={styles.omnichannelRightContainer}>
69-
<Switch value={status} onValueChange={toggleLivechat} />
77+
<Switch value={isOmnichannelStatusAvailable(statusLivechat)} onValueChange={toggleLivechat} />
7078
</View>
7179
)}
7280
/>
7381
<List.Separator />
74-
{status ? <OmnichannelQueue queueSize={queueSize} onPress={goQueue} /> : null}
82+
{isOmnichannelStatusAvailable(statusLivechat) ? <OmnichannelQueue queueSize={queueSize} onPress={goQueue} /> : null}
7583
</>
7684
);
7785
});

0 commit comments

Comments
 (0)