|
1 | 1 | ## Setup
|
2 |
| -1. Install React Native CLI |
| 2 | +1. Git clone |
| 3 | +``` |
| 4 | +git clone https://github.com/ChannelizeIO/Channelize-React-Native-Redux |
| 5 | +``` |
| 6 | + |
| 7 | +2. Install React Native CLI |
3 | 8 | ```
|
4 | 9 | npm install -g react-native-cli
|
5 | 10 | ```
|
6 |
| -2. Install npm dependencies |
| 11 | +3. Install npm dependencies |
7 | 12 | ```
|
8 | 13 | npm run install
|
9 | 14 | ```
|
10 |
| -3. **For Android**: (Please see all the steps in detail in [React native doc](https://reactnative.dev/docs/environment-setup)) |
| 15 | +4. **For Android**: (Please see all the steps in detail in [React native doc](https://reactnative.dev/docs/environment-setup)) |
11 | 16 | a) Install Android Studio (https://developer.android.com/studio/index.html)
|
12 | 17 | b) Install Android SDK
|
13 | 18 | c) Configure the ANDROID_HOME environment variable
|
14 | 19 | d) Connect Android device or Virtual device to Android Studio
|
15 | 20 |
|
16 |
| -4. Run the react native application by following commands: |
| 21 | +5. Run the react native application by following commands: |
17 | 22 |
|
18 | 23 | ```
|
19 | 24 | npm run start
|
@@ -55,88 +60,84 @@ To add the components, you need channelize public key and access token which can
|
55 | 60 | To add the components, you need channelize public key and access token which can explore more [here](https://docs.channelize.io/platform-api-authentication-public/)
|
56 | 61 |
|
57 | 62 | ```
|
58 |
| -import ConversationList from './src/components/ConversationList'; |
59 |
| -import ConversationWindow from './src/components/ConversationWindow'; |
60 |
| -import { Channelize } from 'channelize-chat'; |
| 63 | +import { App, ConversationList, ConversationWindow, store } from './src'; |
| 64 | +// You can use your store file also |
61 | 65 |
|
| 66 | +import { Channelize } from 'channelize-chat'; |
62 | 67 | import { Provider } from 'react-redux';
|
63 |
| -import { store } from './src/store'; |
64 |
| -// You can use your store file also |
65 | 68 |
|
66 | 69 | export default = (props) => {
|
67 |
| - var client = new Channelize.client({publicKey: PUBLIC_KEY}); |
68 |
| -
|
69 |
| - return ( |
70 |
| - <Provider store={store}> |
71 |
| - <App client={client} userId={LOGGEDIN_USER_ID} accessToken={CH_ACCESS_TOKEN}> |
72 |
| - <ConversationList /> |
73 |
| - <ConversationWindow /> |
74 |
| - </App> |
75 |
| - </Provider> |
76 |
| - ) |
| 70 | + var client = new Channelize.client({publicKey: PUBLIC_KEY}); |
| 71 | +
|
| 72 | + return ( |
| 73 | + <Provider store={store}> |
| 74 | + <App client={client} userId={LOGGEDIN_USER_ID} accessToken={CH_ACCESS_TOKEN}> |
| 75 | + <ConversationList /> |
| 76 | + <ConversationWindow /> |
| 77 | + </App> |
| 78 | + </Provider> |
| 79 | + ) |
77 | 80 | }
|
78 | 81 | ```
|
79 | 82 |
|
80 | 83 | ## Conversation window `userId` prop
|
81 | 84 |
|
82 | 85 | ```
|
83 |
| -import ConversationWindow from './src/components/ConversationList'; |
84 |
| -import { Channelize } from 'channelize-chat'; |
| 86 | +import { App, ConversationWindow, store } from './src'; |
| 87 | +// You can use your store file also |
85 | 88 |
|
| 89 | +import { Channelize } from 'channelize-chat'; |
86 | 90 | import { Provider } from 'react-redux';
|
87 |
| -import { store } from './src/store'; |
88 |
| -// You can use your store file also |
89 | 91 |
|
90 | 92 | export default (props) => {
|
91 |
| - var client = new Channelize.client({publicKey: PUBLIC_KEY}); |
92 |
| -
|
93 |
| - return ( |
94 |
| - <Provider store={store}> |
95 |
| - <App client={client} userId={LOGGEDIN_USER_ID} accessToken={CH_ACCESS_TOKEN}> |
96 |
| - <ConversationWindow userId={USER_ID}/> |
97 |
| - </App> |
98 |
| - </Provider> |
99 |
| - ) |
| 93 | + var client = new Channelize.client({publicKey: PUBLIC_KEY}); |
| 94 | +
|
| 95 | + return ( |
| 96 | + <Provider store={store}> |
| 97 | + <App client={client} userId={LOGGEDIN_USER_ID} accessToken={CH_ACCESS_TOKEN}> |
| 98 | + <ConversationWindow userId={USER_ID}/> |
| 99 | + </App> |
| 100 | + </Provider> |
| 101 | + ) |
100 | 102 | }
|
101 | 103 | ```
|
102 | 104 |
|
103 | 105 | ## Conversation window `conversation` prop
|
104 | 106 |
|
105 | 107 | ```
|
106 | 108 | import React, { useEffect, useState } from 'react';
|
107 |
| -import ConversationWindow from './src/components/ConversationList'; |
108 |
| -import { Channelize } from 'channelize-chat'; |
| 109 | +import { App, ConversationWindow, store } from './src'; |
| 110 | +// You can use your store file also |
109 | 111 |
|
| 112 | +import { Channelize } from 'channelize-chat'; |
110 | 113 | import { Provider } from 'react-redux';
|
111 |
| -import { store } from './src/store'; |
112 |
| -// You can use your store file also |
113 | 114 |
|
114 | 115 | export default (props) => {
|
115 |
| - const [conversation, setConversation] = useState(''); |
| 116 | + const [conversation, setConversation] = useState(''); |
116 | 117 |
|
117 |
| - const client = new Channelize.client({publicKey: PUBLIC_KEY}); |
| 118 | + const client = new Channelize.client({publicKey: PUBLIC_KEY}); |
118 | 119 |
|
119 |
| - useEffect(() => { |
120 |
| - getConversation(); |
121 |
| - }, [conversation]); |
| 120 | + useEffect(() => { |
| 121 | + getConversation(); |
| 122 | + }, []); |
122 | 123 |
|
123 |
| - const getConversation = async () => { |
124 |
| - const res = await client.connect(USER_ID, ACCESS_TOKEN); |
125 |
| - const conversation = await client.Conversation.getConversation(CONVERSATION_ID) |
126 |
| - setConversation(conversation); |
127 |
| - }; |
| 124 | + const getConversation = async () => { |
| 125 | + const res = await client.connect(USER_ID, ACCESS_TOKEN); |
| 126 | + const conversation = await client.Conversation.getConversation(CONVERSATION_ID) |
| 127 | + setConversation(conversation); |
| 128 | + }; |
128 | 129 |
|
129 |
| - if (!conversation) { |
130 |
| - return null; |
131 |
| - } |
| 130 | + if (!conversation) { |
| 131 | + return null; |
| 132 | + } |
132 | 133 |
|
133 | 134 |
|
134 |
| - return ( |
135 |
| - <Provider store={store}> |
136 |
| - <App client={client} userId={LOGGEDIN_USER_ID} accessToken={CH_ACCESS_TOKEN}> |
137 |
| - <ConversationWindow conversation={conversation}/> |
138 |
| - </App> |
139 |
| - </Provider> |
140 |
| - ) |
| 135 | + return ( |
| 136 | + <Provider store={store}> |
| 137 | + <App client={client} userId={LOGGEDIN_USER_ID} accessToken={CH_ACCESS_TOKEN}> |
| 138 | + <ConversationWindow conversation={conversation}/> |
| 139 | + </App> |
| 140 | + </Provider> |
| 141 | + ) |
141 | 142 | }
|
142 | 143 | ```
|
0 commit comments