@messenger-box/platform-mobile 0.0.1-alpha.310 → 0.0.1-alpha.314

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,10 +2,10 @@ import React, { useCallback, useMemo, useEffect, useState } from 'react';
2
2
  import { FlatList, Box, Heading, Input, Text, Icon, Center } from 'native-base';
3
3
  import { Ionicons } from '@expo/vector-icons';
4
4
  import { useSelector, useDispatch } from 'react-redux';
5
- import { useNavigation, useRoute, useIsFocused } from '@react-navigation/native';
5
+ import { useNavigation, useRoute, useIsFocused, useFocusEffect } from '@react-navigation/native';
6
6
 
7
7
  import { DialogsListItem } from '../components/DialogsListItem';
8
- import { useGetAllUsersQuery, useGetChannelsByUserQuery } from '@messenger-box/platform-client';
8
+ import { useGetChannelsByUserQuery } from '@messenger-box/platform-client';
9
9
  import { userSelector } from '@adminide-stack/user-auth0-client';
10
10
  import { CHANGE_SETTINGS_ACTION } from '@admin-layout/client';
11
11
  import { config } from '../config';
@@ -15,7 +15,7 @@ export interface InboxProps {
15
15
  channelRole?: string;
16
16
  }
17
17
 
18
- export function Dialogs(props: InboxProps) {
18
+ export const Dialogs = (props: InboxProps) => {
19
19
  const { channelFilters, channelRole } = props;
20
20
  const { params } = useRoute<any>();
21
21
  const auth = useSelector(userSelector);
@@ -35,17 +35,18 @@ export function Dialogs(props: InboxProps) {
35
35
  },
36
36
  });
37
37
 
38
- const { data: users } = useGetAllUsersQuery();
38
+ useFocusEffect(
39
+ React.useCallback(() => {
40
+ // Do something when the screen is focused
41
+ getChannelsRefetch({ role: channelRole, criteria: channelFilters });
39
42
 
40
- const currentUser = useMemo(
41
- () => users?.getUsers?.find(({ alias }: any) => alias?.includes(auth?.auth0UserId)),
42
- [users, auth],
43
+ return () => {
44
+ // Do something when the screen is unfocused
45
+ // Useful for cleanup functions
46
+ };
47
+ }, [channelFilters]),
43
48
  );
44
49
 
45
- useEffect(() => {
46
- getChannelsRefetch();
47
- }, [isFocused, navigation]);
48
-
49
50
  useEffect(() => {
50
51
  setTimeout(() => {
51
52
  dispatch({
@@ -67,11 +68,13 @@ export function Dialogs(props: InboxProps) {
67
68
 
68
69
  useEffect(() => {
69
70
  if (userChannels?.channelsByUser) {
70
- //Direct channel Memebers
71
+ //Direct channel
71
72
  let userDirectChannels: any =
72
73
  userChannels?.channelsByUser
73
74
  ?.filter((i: any) => i.type == 'DIRECT')
74
- ?.filter((c: any) => c.members.some((u: any) => u.user.__typename == 'UserAccount')) ?? [];
75
+ ?.filter((c: any) =>
76
+ c.members.some((u: any) => u?.user?.id != auth?.id && u.user.__typename == 'UserAccount'),
77
+ ) ?? [];
75
78
 
76
79
  if (userDirectChannels?.length > 0) setUserDirectChannel(userDirectChannels);
77
80
  }
@@ -93,49 +96,41 @@ export function Dialogs(props: InboxProps) {
93
96
  }
94
97
  }, []);
95
98
 
96
- //let cuc = userChannels?.channelsByUser?.filter((i:any)=>i.type=='DIRECT')?.map((k:any) => k?.members?.filter((e:any) => e?.user?.id != currentUser?.id))??[];
97
- let cuc = userDirectChannel?.map((k: any) => k?.members?.filter((e: any) => e?.user?.id != currentUser?.id)) ?? [];
98
- cuc = cuc.filter((e: any) => e.length);
99
99
  return (
100
100
  <Box p={2}>
101
- {/* {!userChannels?.channelsByUser?.filter((i:any)=>i.type=='DIRECT')?.length || cuc && cuc.length == 0 ? ( */}
102
- {!userDirectChannel || userDirectChannel?.length == 0 || (cuc && cuc.length == 0) ? (
103
- <Box p={5}>
104
- <Heading>Chat</Heading>
105
- <Input
106
- height={50}
107
- mt={3}
108
- placeholder="Search"
109
- borderRadius={50}
110
- borderColor={'gray.200'}
111
- borderWidth={2}
101
+ <FlatList
102
+ data={userDirectChannel?.length > 0 ? userDirectChannel : []}
103
+ onRefresh={getChannelsRefetch}
104
+ refreshing={userChannelsLoading}
105
+ contentContainerStyle={{ minHeight: '100%' }}
106
+ ItemSeparatorComponent={() => <Box height="0.5" backgroundColor="gray.200" />}
107
+ renderItem={({ item: channel }) => (
108
+ <DialogsListItem
109
+ onOpen={handleSelectChannel}
110
+ currentUser={auth}
111
+ channel={channel}
112
+ selectedChannelId={params?.channelId}
112
113
  />
113
- <Center mt={6}>
114
- <Icon as={Ionicons} name="chatbubbles" size={'xl'} />
115
- <Text>You don't have any messages yet!</Text>
116
- </Center>
117
- </Box>
118
- ) : (
119
- <>
120
- <FlatList
121
- // data={userChannels?.channelsByUser?.filter((i:any)=>i.type=='DIRECT')??[]}
122
- data={userDirectChannel?.length > 0 ? userDirectChannel : []}
123
- onRefresh={getChannelsRefetch}
124
- refreshing={userChannelsLoading}
125
- contentContainerStyle={{ minHeight: '100%' }}
126
- ItemSeparatorComponent={() => <Box height="0.5" backgroundColor="gray.200" />}
127
- renderItem={({ item: channel }) => (
128
- <DialogsListItem
129
- users={users?.getUsers}
130
- onOpen={handleSelectChannel}
131
- currentUser={currentUser}
132
- channel={channel}
133
- selectedChannelId={params?.channelId}
134
- />
135
- )}
136
- />
137
- </>
138
- )}
114
+ )}
115
+ ListEmptyComponent={() => (
116
+ <Box p={5}>
117
+ <Heading>Chat</Heading>
118
+ <Input
119
+ height={50}
120
+ mt={3}
121
+ placeholder="Search"
122
+ borderRadius={50}
123
+ borderColor={'gray.200'}
124
+ borderWidth={2}
125
+ />
126
+ <Center mt={6}>
127
+ <Icon as={Ionicons} name="chatbubbles" size={'xl'} />
128
+ <Text>You don't have any messages yet!</Text>
129
+ </Center>
130
+ </Box>
131
+ )}
132
+ keyExtractor={(item, index) => 'key' + index}
133
+ />
139
134
  </Box>
140
135
  );
141
- }
136
+ };