@messenger-box/platform-mobile 0.0.1-alpha.174

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +21 -0
  3. package/jest.config.js +24 -0
  4. package/lib/index.d.ts +4 -0
  5. package/lib/index.js +902 -0
  6. package/lib/index.js.map +1 -0
  7. package/lib/module.d.ts +3 -0
  8. package/lib/navigation/InboxNavigation.d.ts +2 -0
  9. package/lib/navigation/index.d.ts +1 -0
  10. package/lib/screens/inbox/DialogMessages.d.ts +2 -0
  11. package/lib/screens/inbox/DialogsList.d.ts +2 -0
  12. package/lib/screens/inbox/components/DialogsHeader.d.ts +8 -0
  13. package/lib/screens/inbox/components/DialogsListItem.d.ts +17 -0
  14. package/lib/screens/inbox/components/MessageInput.d.ts +2 -0
  15. package/lib/screens/inbox/components/MessageItem.d.ts +11 -0
  16. package/lib/screens/inbox/containers/ConversationView.d.ts +2 -0
  17. package/lib/screens/inbox/containers/Dialogs.d.ts +2 -0
  18. package/package.json +43 -0
  19. package/src/components/index.ts +0 -0
  20. package/src/index.ts +6 -0
  21. package/src/module.ts +8 -0
  22. package/src/navigation/InboxNavigation.tsx +26 -0
  23. package/src/navigation/index.ts +1 -0
  24. package/src/screens/inbox/DialogMessages.tsx +20 -0
  25. package/src/screens/inbox/DialogsList.tsx +25 -0
  26. package/src/screens/inbox/components/DialogsHeader.tsx +21 -0
  27. package/src/screens/inbox/components/DialogsListItem.tsx +73 -0
  28. package/src/screens/inbox/components/MessageInput.tsx +54 -0
  29. package/src/screens/inbox/components/MessageItem.tsx +44 -0
  30. package/src/screens/inbox/containers/ConversationView.tsx +98 -0
  31. package/src/screens/inbox/containers/Dialogs.tsx +62 -0
  32. package/src/screens/index.ts +1 -0
  33. package/tsconfig.json +18 -0
  34. package/webpack.config.js +58 -0
@@ -0,0 +1,62 @@
1
+ import { FlatList, ScrollView, Text, View } from 'native-base';
2
+ import { IChannel, useGetAllChannelQuery, useGetAllUsersQuery } from '@messenger-box/platform-client';
3
+ import { useSelector } from 'react-redux';
4
+ import React, { useCallback, useMemo, useState } from 'react';
5
+ import { keyBy } from 'lodash';
6
+ import { useNavigation } from '@react-navigation/native';
7
+
8
+ import { DialogsListItem } from '../components/DialogsListItem';
9
+
10
+ export function Dialogs() {
11
+ const users$ = useGetAllUsersQuery();
12
+ const navigation: any = useNavigation();
13
+ const channels$ = useGetAllChannelQuery();
14
+ const [rk, setRk] = useState(Math.random());
15
+ const userId = useSelector((state: any) => state.user.auth0UserId);
16
+
17
+ /**
18
+ * TODO: add ability to check channel members
19
+ * HostChannels: channel.members[0].user !== userId
20
+ * GuestChannels: channel.members[0].user == userId
21
+ */
22
+ const filter = useCallback(
23
+ (channel) =>
24
+ channel.type === 'DIRECT'
25
+ && channel?.displayName !== 'surveybot'
26
+ && channel?.displayName !== 'admin (you)',
27
+ [userId],
28
+ );
29
+
30
+ const users = useMemo(() => keyBy(users$.data?.getUsers, 'id'), [users$.data?.getUsers]);
31
+
32
+ // Filter all channles
33
+ const list = useMemo(() =>
34
+ channels$.data?.channels?.filter(filter) || [], [filter, channels$.data?.channels]);
35
+
36
+ // Assign users to channel item
37
+ const channels = useMemo(
38
+ () => list.map((channel) => ({ ...channel, users: channel?.members?.map((record) => users[record?.user!]) }))
39
+ , [list, users$.data?.getUsers, userId]);
40
+
41
+ const onRefresh = async () => {
42
+ await users$.refetch();
43
+ await channels$.refetch();
44
+ return setRk(Math.random());
45
+ };
46
+
47
+ const isRefreshing = channels$.loading || users$.loading;
48
+
49
+ const onOpen = (channel: IChannel, options: { title: string }) =>
50
+ navigation.navigate("Inbox.DialogMessages" as any, { ...options, channel, hideTabBar: true });
51
+
52
+ return (
53
+ <FlatList
54
+ data={channels}
55
+ onRefresh={onRefresh}
56
+ refreshing={isRefreshing}
57
+ contentContainerStyle={{ minHeight: '100%' }}
58
+ ItemSeparatorComponent={() => <View height="0.5" backgroundColor="gray.200" marginY="0.5" />}
59
+ renderItem={({ item: channel }) => <DialogsListItem refreshKey={rk} onOpen={onOpen} currentUserId={userId} channel={channel} />}
60
+ />
61
+ );
62
+ }
@@ -0,0 +1 @@
1
+ export * from './inbox';
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "allowSyntheticDefaultImports": true,
5
+ "experimentalDecorators": true,
6
+ "esModuleInterop": true,
7
+ "skipLibCheck": true,
8
+ "rootDir": "./src",
9
+ "outDir": "../lib",
10
+ "declarationDir": "lib"
11
+ },
12
+ "exclude": [
13
+ "node_modules",
14
+ "lib",
15
+ "dist",
16
+ "webpack.config.js"
17
+ ]
18
+ }
@@ -0,0 +1,58 @@
1
+ const nodeExternals = require('webpack-node-externals');
2
+ const webpack = require('webpack');
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+
6
+ const webpackOpts = {
7
+ mode: 'development',
8
+ entry: './src/index.ts',
9
+ target: 'node',
10
+ output: {
11
+ path: path.join(__dirname, 'lib'),
12
+ filename: 'index.js',
13
+ libraryTarget: 'commonjs2',
14
+ },
15
+ node: {
16
+ __dirname: false,
17
+ },
18
+ resolve: {
19
+ extensions: ['.ts', '.tsx', '.graphql', '.gql'],
20
+ },
21
+ plugins: [
22
+ new webpack.LoaderOptionsPlugin({
23
+ options: {
24
+ test: /\.tsx?$/,
25
+ ts: {
26
+ compiler: 'typescript',
27
+ configFile: 'tsconfig.json',
28
+ },
29
+ tslint: {
30
+ emitErrors: true,
31
+ failOnHint: true,
32
+ },
33
+ },
34
+ }),
35
+ ],
36
+ devtool: 'source-map',
37
+ module: {
38
+ rules: [
39
+ {
40
+ test: /\.tsx?$/,
41
+ loaders: 'ts-loader',
42
+ },
43
+ {
44
+ test: /\.graphql?/,
45
+ exclude: /node_modules/,
46
+ use: 'raw-loader',
47
+ },
48
+ {
49
+ test: /\.(gql)$/,
50
+ exclude: /node_modules/,
51
+ use: ['graphql-tag/loader'],
52
+ },
53
+ ],
54
+ },
55
+ externals: [nodeExternals({ modulesDir: '../../../node_modules' }), nodeExternals()],
56
+ };
57
+
58
+ module.exports = webpackOpts;