-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ios.js
85 lines (70 loc) · 2.15 KB
/
index.ios.js
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
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, View, Modal } from 'react-native';
import { createStore, combineReducers, applyMiddleware } from 'redux';
import thunkMiddleWare from 'redux-thunk';
import { Provider } from 'react-redux';
// utils
import { firebaseUtils } from './src/utils/firebase';
import * as localStorage from './src/utils/localStorage';
// reducers
import { names } from './src/stores/names/reducers';
import { user } from './src/stores/user/reducers';
// scenes
import App from './src/scenes/App';
import Login from './src/scenes/Login/Login';
firebaseUtils.initializeApp();
const rootReducer = combineReducers({
names,
user
});
export const store = createStore(
rootReducer,
applyMiddleware(thunkMiddleWare),
);
export default class Nafnster extends Component {
state = {
loginModalOpen: false,
};
componentWillMount() {
this.checkLogin();
}
checkLogin = async () => {
const user = await localStorage.getUser();
if (user === null) {
this.setState({ loginModalOpen: true })
}
}
onLoginSuccess = () => {
this.setState({ loginModalOpen: false });
}
onLogOutSuccess = async () => {
await localStorage.removeUser();
this.setState({ loginModalOpen: true });
}
render() {
return (
<Provider store={store}>
<View style={styles.container}>
{this.state.loginModalOpen &&
<Modal
animationType={"slide"}
transparent={false}
visible={true}
>
<Login onLoginSuccess={this.onLoginSuccess} />
</Modal>
}
{!this.state.loginModalOpen &&
<App onLogOutSuccess={this.onLogOutSuccess} />
}
</View>
</Provider>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
AppRegistry.registerComponent('Nafnster', () => Nafnster);