-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
63 lines (61 loc) · 1.74 KB
/
App.tsx
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
import { useEffect, useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { StatusBar } from 'expo-status-bar';
import BranchesInput from './src/BranchesInput';
import { SearchLocation } from './src/SearchLocation';
import Map from './src/Map';
import Spinner from './src/Spinner';
import useLoading from './src/useLoading';
import { Branch } from './src/Branch';
import { closestBranchTo } from './src/distances';
import BranchDetails from './src/BranchDetails';
export default function App() {
const [state, branches] = useLoading();
const [search, setSearch] = useState<SearchLocation>();
const [closest, setClosest] = useState<undefined | Branch>();
useEffect(() => {
if (branches && typeof search === 'object') {
setClosest(closestBranchTo(search, branches));
} else {
setClosest(undefined);
}
}, [search, branches]);
return (
<View style={styles.container}>
<StatusBar style="auto" />
<Map closest={closest} />
{state === 'ready' ? (
<>
<BranchesInput search={search} setSearch={setSearch} />
{closest && <BranchDetails branch={closest} />}
</>
) : state === 'error' ? (
<View style={styles.centred}>
<Text style={styles.error}>An error has occurred</Text>
</View>
) : (
<View style={styles.centred}>
<Spinner height={60} />
</View>
)}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
error: {
fontFamily: 'textRegular',
fontSize: 24,
color: '#ED0000',
padding: 10,
backgroundColor: '#80808030',
},
centred: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
});