-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
68 lines (59 loc) · 1.87 KB
/
App.js
File metadata and controls
68 lines (59 loc) · 1.87 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
58
59
60
61
62
63
64
65
66
67
68
/**
* The main app component.
*
* @author Miika Koskela <koskela.miika.s@outlook.com>
* @copyright Tampereen Kaupunginkirjasto, 2018-
* @license MIT (see LICENSE)
*/
import React, { Component } from 'react';
import SplashScreen from 'react-native-splash-screen';
import PropTypes from 'prop-types';
import { NavigationActions } from 'react-navigation';
import Styles from './src/Styles';
import Navigation from './src/Navigation';
import Downloader from './src/Downloader';
// TODO: Parser can be left out when the server contains only JSON files.
import Parser from './src/Parser';
import ConfigDatasource from './src/Datasources/ConfigDatasource';
/**
* An entry point to the Lukudiplomi application.
*
* It renders the app and also checks if a grade is selected.
*
* If the grade is not selected, then a user is redirected to the grade
* selection screen where the user can select and save the grade.
*/
class App extends Component {
constructor (props) {
super(props);
let downloader = new Downloader(new Parser({}));
let uri = 'https://raw.githubusercontent.com/patill/lukudiplomi-pori-datasources/master/lukudiplomi-config.txt';
this.config = new ConfigDatasource(uri, downloader);
}
componentDidMount () {
SplashScreen.hide();
// First, check if there's current grade set; if not, navigate to the grade
// selection screen to set the grade.
let grade = this.config.getCurrentGrade();
grade.then((value) => {
if (!value) {
this.navigator && this.navigator.dispatch(
NavigationActions.navigate({ routeName: 'GradeSelect' })
);
return null;
}
}).catch((error) => {});
}
render () {
return (
<Navigation
ref={(ref) => { this.navigator = ref; }}
style={Styles.tabNavigator}
/>
);
}
}
export default App;
App.propTypes = {
navigation: PropTypes.object
};