-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
115 lines (104 loc) · 3.16 KB
/
App.js
File metadata and controls
115 lines (104 loc) · 3.16 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
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
109
110
111
112
113
114
115
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, {useState, useEffect} from 'react';
import type {Node} from 'react';
import {
ImageBackground,
SafeAreaView,
ScrollView,
StyleSheet,
useColorScheme,
} from 'react-native';
import {Colors} from 'react-native/Libraries/NewAppScreen';
import NavBarComponent from './components/NavBarComponent';
import NasaPoDComponent from './components/NasaPoDComponent';
import PeopleComponent from './components/PeopleComponent';
import ISSLocationComponent from './components/ISSLocationComponent';
import RocketLaunchesComponent from './components/RocketLaunchesComponent';
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
const App: () => Node = () => {
const isDarkMode = useColorScheme() === 'dark';
const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
};
const [nasaPod, setNasaPod] = useState(null);
const [people, setPeople] = useState(null);
const [launches, setLaunches] = useState(null);
const [selection, setSelection] = useState(null);
const [returnView, setReturnView] = useState(<></>);
useEffect(() => {
fetch(
'http://spacer2backend.eba-mmnzm8qm.us-east-1.elasticbeanstalk.com/api/nasapod',
).then(r => {
if (r.ok) {
r.json()
.then(json => setNasaPod(json.Value))
.then(() => setSelection('nasapod'));
}
});
}, []);
useEffect(() => {
fetch(
'http://spacer2backend.eba-mmnzm8qm.us-east-1.elasticbeanstalk.com/api/people',
).then(r => {
if (r.ok) {
r.json().then(json => setPeople(json.Value));
}
});
}, []);
useEffect(() => {
fetch(
'http://spacer2backend.eba-mmnzm8qm.us-east-1.elasticbeanstalk.com/api/launches',
).then(r => {
if (r.ok) {
r.json().then(json => setLaunches(json.Value));
}
});
}, []);
useEffect(() => {
if (selection == 'nasapod') {
setReturnView(<NasaPoDComponent nasaPod={nasaPod} />);
} else if (selection == 'people') {
setReturnView(<PeopleComponent people={people} />);
} else if (selection == 'launches') {
setReturnView(<RocketLaunchesComponent launches={launches} />);
} else if (selection == 'isslocation') {
setReturnView(<ISSLocationComponent />);
}
}, [selection]);
function onButtonPress(buttonPressed) {
setSelection(buttonPressed);
}
return (
<SafeAreaView style={styles.mainContainer}>
<ImageBackground
source={require('./assets/Space_Shuttle_Columbia_launching.jpg')}>
<ScrollView style={styles.returnWindown}>{returnView}</ScrollView>
</ImageBackground>
<NavBarComponent style={styles.navBar} onButtonPress={onButtonPress} />
</SafeAreaView>
);
};
const styles = StyleSheet.create({
mainContainer: {
display: 'flex',
flexDirection: 'column',
alignContent: 'flex-end',
},
navBar: {
flexBasis: '8%',
zIndex: 1,
position: 'fixed',
},
returnWindown: {
flexBasis: '92%',
backgroundColor: 'rgba(0,0,0,0.5)',
},
});
export default App;