-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
107 lines (96 loc) · 2.87 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*/
import React, {
useEffect,
} from 'react';
import {
View,
StatusBar,
StyleSheet,
} from 'react-native';
import "./src/api/index.ts";
import { Provider } from 'react-redux';
import Router from './src/router';
import socket from './src/socket/index.tsx';
import store from './src/store/index.ts';
import {
ADD_MESSAGE,
ConversationType,
MessageType,
UPDATE_LAST_MESSAGE,
UPDATE_MESSAGE
} from './src/store/conversation/reducer.ts';
import { UserType } from './src/store/user/reducer.ts';
import { ADD_SEARCH_USERS } from './src/store/search/reducer.ts';
const App = (): JSX.Element => {
useEffect(() => {
socket.on('connect', () => {
console.log('Socket Connected!!!');
});
socket.on('disconnect', (data) => {
console.log('Socket Disconnected!!!');
});
socket.io.on('reconnect_attempt', () => {
console.log('reconnecting');
});
socket.on('room_joined', (data) => {
console.log(`room_joined ${data}`);
});
socket.on('set_user_success', (data) => {
console.log(`set_user_success ${JSON.stringify(data)}`);
});
socket.on('new_message', (data: MessageType) => {
console.log(`new_message ${JSON.stringify(data)}`);
store.dispatch(ADD_MESSAGE(data));
});
socket.on('new_message_error', (data: Object) => {
console.error(`new_message_error ${JSON.stringify(data)}`);
})
socket.on('update_message', (data: MessageType) => {
console.log(`update_message ${JSON.stringify(data)}`);
});
socket.on('see_message_success', (data: MessageType) => {
console.log(`see_message_success ${JSON.stringify(data)}`);
store.dispatch(UPDATE_MESSAGE(data));
});
socket.on('see_message_error', (data: Object) => {
console.error(`see_message_error ${JSON.stringify(data)}`);
});
socket.on('new_conversation', (data: ConversationType) => {
console.log(`new_conversation ${JSON.stringify(data)}`);
});
socket.on('new_conversation_error', (data: Object) => {
console.error(`new_conversation_error ${JSON.stringify(data)}`);
});
socket.on('update_conversation', (data: ConversationType) => {
console.log(`update_conversation ${JSON.stringify(data)}`);
store.dispatch(UPDATE_LAST_MESSAGE(data.last_message));
});
socket.on('search_user', (data: Array<UserType>) => {
console.log(`search_user fetched`);
store.dispatch(ADD_SEARCH_USERS(data));
});
}, [false]);
return (
<View style={styles.container}>
<StatusBar
translucent
backgroundColor={'transparent'}
barStyle={'dark-content'} />
<Provider store={store}>
<Router />
</Provider>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white'
},
});
export default App;