-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMain.tsx
More file actions
57 lines (51 loc) · 1.53 KB
/
Main.tsx
File metadata and controls
57 lines (51 loc) · 1.53 KB
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
import React, {Component} from 'react';
import {View} from 'react-native';
import {TruckListScreen} from './screens/TruckList/TruckListScreen';
import {globalStyles} from './styles/globalStyles';
import {TruckFormScreen} from "./screens/TruckForm/TruckFormScreen";
import {connect} from "react-redux";
import {TruckSocket} from "./components/TruckSocket";
import {Permissions, Notifications} from 'expo';
import axios from 'axios';
import {BACKEND_URL} from "./constants/backend";
import {IEmptyState} from "./types/react";
import {IUiReducer, Screen} from "./reducers/ui";
interface IProps {
currentScreen: Screen
}
class _Main extends Component<IProps, IEmptyState> {
componentDidMount() {
Permissions.askAsync(Permissions.REMOTE_NOTIFICATIONS)
.then((res: {status: string}) => {
if(res.status !== 'granted'){
return;
}
return Notifications.getExponentPushTokenAsync()
.then((token: string)=> {
return axios.post(BACKEND_URL + '/notifications', {
token
});
});
});
}
render() {
let screen;
switch(this.props.currentScreen){
case 'list':
screen = <TruckListScreen />;
break;
case 'form':
screen = <TruckFormScreen />;
break;
}
return (
<View style={globalStyles.container}>
<TruckSocket/>
{screen}
</View>);
}
}
const mapStateToProps = ({ui: {currentScreen}}: {ui: IUiReducer}) => ({
currentScreen
});
export const Main = connect(mapStateToProps)(_Main);