-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
93 lines (84 loc) · 2.23 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
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
import React, { useEffect, useState } from "react";
import { StatusBar } from "expo-status-bar";
import {
FlatList,
StyleSheet,
Text,
View,
ListRenderItemInfo,
Button,
} from "react-native";
import Header from "./components/Header";
import Footer from "./components/Footer";
import LoadingScreen from "./components/LoadingScreen";
import Asteroid from "./components/Asteroid";
import DateInput from "./components/DateInput";
import { formatDate, prettifyDate } from "./utils/dates";
import collectData from "./utils/api";
import { AsteroidType } from "./utils/types";
import { SLATE, WHITE, BLACK } from "./styles/globalStyles";
export default function App() {
const [date, setDate] = useState(new Date());
const [showDate, setShowDate] = useState(false);
const [asteroids, setAsteroids] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
collectData(formatDate(date), setAsteroids, setLoading);
}, [date]);
if (loading) {
return <LoadingScreen />;
}
return (
<View style={styles.container}>
<Header />
<View style={styles.content}>
<View style={styles.dateSelector}>
<Text style={{ marginRight: 10, color: WHITE }}>
Choose Your Date:{" "}
</Text>
<Button
onPress={() => setShowDate(true)}
title={prettifyDate(date)}
/>
</View>
<DateInput
setDate={setDate}
setShowDate={setShowDate}
showDate={showDate}
date={date}
/>
<FlatList
data={asteroids}
renderItem={({ item }: ListRenderItemInfo<AsteroidType>) => {
return <Asteroid key={item.id} item={item} />;
}}
/>
</View>
<Footer />
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: BLACK,
alignItems: "center",
justifyContent: "center",
},
content: {
backgroundColor: SLATE,
borderTopLeftRadius: 15,
borderTopRightRadius: 15,
flex: 6,
width: "100%",
padding: 10,
margin: 10,
},
dateSelector: {
marginBottom: 10,
width: "50%",
flexDirection: "row",
alignItems: "center",
},
});