-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
108 lines (101 loc) · 4.16 KB
/
App.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import React from 'react';
import { StyleSheet, StatusBar, AsyncStorage, Dimensions, Alert } from 'react-native';
import { Font, AppLoading } from 'expo';
import { View, Examples, Screen } from '@shoutem/ui';
import Login from './src/Login'
import Swiping from './src/Swiping'
import Profile from './src/Profile'
import Editor from './src/Editor'
let screen = Dimensions.get('window')
export default class App extends React.Component {
state = {
fontsAreLoaded: false,
user: null,
shortcode: null,
screen: ''
}
constructor(props) {
super(props)
console.info("Starting!")
}
async componentWillMount() {
await Font.loadAsync({
'Rubik-Black': require('./node_modules/@shoutem/ui/fonts/Rubik-Black.ttf'),
'Rubik-BlackItalic': require('./node_modules/@shoutem/ui/fonts/Rubik-BlackItalic.ttf'),
'Rubik-Bold': require('./node_modules/@shoutem/ui/fonts/Rubik-Bold.ttf'),
'Rubik-BoldItalic': require('./node_modules/@shoutem/ui/fonts/Rubik-BoldItalic.ttf'),
'Rubik-Italic': require('./node_modules/@shoutem/ui/fonts/Rubik-Italic.ttf'),
'Rubik-Light': require('./node_modules/@shoutem/ui/fonts/Rubik-Light.ttf'),
'Rubik-LightItalic': require('./node_modules/@shoutem/ui/fonts/Rubik-LightItalic.ttf'),
'Rubik-Medium': require('./node_modules/@shoutem/ui/fonts/Rubik-Medium.ttf'),
'Rubik-MediumItalic': require('./node_modules/@shoutem/ui/fonts/Rubik-MediumItalic.ttf'),
'Rubik-Regular': require('./node_modules/@shoutem/ui/fonts/Rubik-Regular.ttf'),
'rubicon-icon-font': require('./node_modules/@shoutem/ui/fonts/rubicon-icon-font.ttf'),
})
this.setState({ fontsAreLoaded: true })
}
getScreen() {
switch (this.state.screen) {
case 'login': return (
<Login user={(u) => {
AsyncStorage.setItem('@Pimperial:shortcode', u.code)
.then(() => {
this.setState({ user: u, shortcode: u.code, screen: 'edit-profile' })
})
}} />
)
case 'matchmaking': return (
<Swiping edit={() => {
this.setState({ screen: 'edit-profile' })
}} chat={() => {
Alert.alert('chat')
}} />
)
case 'edit-profile': return (
<Editor user={this.state.user} swiping={() => {
this.setState({ screen: 'matchmaking' })
}} />
)
default:
AsyncStorage.getItem('@Pimperial:shortcode')
.then((c) => {
if (c)
fetch(
`http://54.91.147.183:3415/who/is/${c}`,
{ method: 'post' }
).then((s) => s.json()).then((j) => {
this.setState({ user: j, shortcode: c, screen: 'matchmaking' })
}).catch((e) => {
if (e) {
console.debug(e)
Alert.alert(
"It's not you, it's us! 😞",
"We couldn't log you in, try again later!"
)
}
})
else this.setState({ screen: 'login' })
})
.catch(() => {
this.setState({ screen: 'login' })
})
return (
<AppLoading />
)
}
}
render() {
if (!this.state.fontsAreLoaded) {
return <AppLoading />;
}
return (
<Screen style={{
backgroundColor: '#003b73',
alignItems: 'center',
}}>
{this.getScreen()}
<StatusBar barStyle="default" hidden={true} />
</Screen>
)
}
}