1
1
import React , { useState } from 'react' ;
2
- import { View , Text , StyleSheet , Image , ScrollView , Button } from 'react-native' ;
2
+ import { View , Text , StyleSheet , Image , ScrollView , TouchableOpacity , Alert } from 'react-native' ;
3
3
import { useQuery } from 'react-query' ;
4
4
import DateTimePicker , { DateTimePickerEvent } from '@react-native-community/datetimepicker' ;
5
5
import { format } from 'date-fns' ;
@@ -19,6 +19,13 @@ const fetchAPOD = async (date: string): Promise<ApodDataInterface> => {
19
19
if ( ! response . ok ) {
20
20
throw new Error ( 'Network response was not ok' ) ;
21
21
}
22
+
23
+ const rateLimitLimit = response . headers . get ( 'x-ratelimit-limit' ) ;
24
+ const rateLimitRemaining = response . headers . get ( 'x-ratelimit-remaining' ) ;
25
+
26
+ console . log ( `x-ratelimit-limit: ${ rateLimitLimit } ` ) ;
27
+ console . log ( `x-ratelimit-remaining: ${ rateLimitRemaining } ` ) ;
28
+
22
29
return response . json ( ) ;
23
30
} ;
24
31
@@ -28,7 +35,6 @@ export const ApodScreen = () => {
28
35
const [ selectedDate , setSelectedDate ] = useState ( new Date ( ) ) ;
29
36
const [ dateString , setDateString ] = useState ( format ( new Date ( ) , 'yyyy-MM-dd' ) ) ;
30
37
const [ showDatePicker , setShowDatePicker ] = useState ( false ) ;
31
- const [ isVideo , setIsVideo ] = useState ( false ) ;
32
38
33
39
const { data, error, isLoading } = useQuery < ApodDataInterface , Error > ( [ 'apod' , dateString ] , ( ) =>
34
40
fetchAPOD ( dateString ) ,
@@ -37,8 +43,6 @@ export const ApodScreen = () => {
37
43
React . useEffect ( ( ) => {
38
44
if ( data ) {
39
45
console . log ( { data } ) ;
40
- const verifyVideo = data . url . includes ( 'youtube' ) ;
41
- setIsVideo ( verifyVideo ) ;
42
46
}
43
47
} , [ data ] ) ;
44
48
@@ -48,9 +52,21 @@ export const ApodScreen = () => {
48
52
setGlobalLoading ( isLoading ) ;
49
53
} , [ isLoading ] ) ;
50
54
55
+ React . useEffect ( ( ) => {
56
+ if ( error ) {
57
+ Alert . alert ( error . toString ( ) ) ;
58
+ }
59
+ } , [ error ] ) ;
60
+
51
61
const handleDateChange = ( event : DateTimePickerEvent , date : Date | undefined ) => {
52
62
setShowDatePicker ( false ) ;
63
+
53
64
if ( date ) {
65
+ if ( date > new Date ( ) ) {
66
+ Alert . alert ( 'Cannot select a date greater than the current date' ) ;
67
+ return false ;
68
+ }
69
+
54
70
setSelectedDate ( date ) ;
55
71
setDateString ( format ( date , 'yyyy-MM-dd' ) ) ;
56
72
}
@@ -62,10 +78,24 @@ export const ApodScreen = () => {
62
78
63
79
return (
64
80
< CustomSafeAreaView style = { styles . screenContainer } >
65
- < ScrollView style = { { padding : 10 } } >
81
+ < ScrollView style = { { paddingHorizontal : 10 , marginBottom : 10 } } >
66
82
< View >
67
- < View style = { { justifyContent : 'center' , alignItems : 'center' , marginBottom : 20 } } >
68
- < Button title = "Select Date" onPress = { openDatePicker } />
83
+ < View
84
+ style = { {
85
+ flexDirection : 'row' ,
86
+ alignItems : 'center' ,
87
+ marginBottom : 10 ,
88
+ gap : 10 ,
89
+ } }
90
+ >
91
+ < Text style = { { marginBottom : 10 , color : Colors . white , fontSize : 16 , flex : 2 } } >
92
+ Change the date to fetch images from other days.
93
+ </ Text >
94
+ < TouchableOpacity style = { styles . dateButton } onPress = { openDatePicker } >
95
+ < Text style = { { color : Colors . white , fontSize : 16 , fontWeight : 700 } } >
96
+ Select Date
97
+ </ Text >
98
+ </ TouchableOpacity >
69
99
{ showDatePicker && (
70
100
< DateTimePicker
71
101
value = { selectedDate }
@@ -76,31 +106,41 @@ export const ApodScreen = () => {
76
106
) }
77
107
</ View >
78
108
79
- < View style = { { gap : 10 } } >
109
+ < View
110
+ style = { {
111
+ flexDirection : 'row' ,
112
+ alignItems : 'center' ,
113
+ paddingBottom : 10 ,
114
+ marginBottom : 20 ,
115
+ borderBottomWidth : 1 ,
116
+ borderColor : Colors . white ,
117
+ } }
118
+ >
119
+ < Text style = { styles . labelValue } > Selected Date: </ Text >
120
+ < Text style = { styles . textValue } > { format ( selectedDate , 'dd/MM/yyyy' ) } </ Text >
121
+ </ View >
122
+
123
+ < View style = { { gap : 4 } } >
80
124
< Text style = { styles . title } > { data ?. title } </ Text >
81
125
< View >
82
- < Text style = { { fontWeight : 'bold' , fontSize : 18 } } > Explanation: </ Text >
83
- < Text style = { { fontSize : 16 } } > { data ?. explanation } </ Text >
126
+ < Text style = { styles . labelValue } > Explanation: </ Text >
127
+ < Text style = { styles . textValue } > { data ?. explanation } </ Text >
84
128
</ View >
85
129
< View style = { { flexDirection : 'row' , alignItems : 'center' } } >
86
- < Text style = { { fontWeight : 'bold' , fontSize : 18 } } > Date: </ Text >
87
- < Text style = { { fontSize : 16 } } > { data ?. date } </ Text >
88
- </ View >
89
- < View style = { { flexDirection : 'row' , alignItems : 'center' } } >
90
- < Text style = { { fontWeight : 'bold' , fontSize : 18 } } > Copyright: </ Text >
91
- < Text style = { { fontSize : 16 } } >
130
+ < Text style = { styles . labelValue } > Copyright: </ Text >
131
+ < Text style = { styles . textValue } >
92
132
{ data ?. copyright ? data . copyright ?. trim ( ) : 'No Copyrights' }
93
133
</ Text >
94
134
</ View >
95
135
< View style = { { flexDirection : 'row' , alignItems : 'center' } } >
96
- < Text style = { { fontWeight : 'bold' , fontSize : 18 } } > Media Type: </ Text >
97
- < Text style = { { fontSize : 16 } } > { data ?. media_type } </ Text >
136
+ < Text style = { styles . labelValue } > Media Type: </ Text >
137
+ < Text style = { styles . textValue } > { data ?. media_type } </ Text >
98
138
</ View >
99
139
</ View >
100
140
101
141
{ data ?. media_type === 'video' ? (
102
- < Text style = { { fontSize : 16 , marginTop : 10 } } >
103
- Video format not yet supported. Please wait for new updates.{ ' ' }
142
+ < Text style = { { fontSize : 16 , marginTop : 10 , color : Colors . white } } >
143
+ Video format not yet supported. Please wait for new updates.
104
144
</ Text >
105
145
) : (
106
146
< View
@@ -124,16 +164,42 @@ const styles = StyleSheet.create({
124
164
screenContainer : {
125
165
flex : 1 ,
126
166
padding : 8 ,
127
- backgroundColor : Colors . lightGray ,
167
+ backgroundColor : Colors . darkGray ,
168
+ } ,
169
+ dateButton : {
170
+ backgroundColor : Colors . purple ,
171
+ flex : 1 ,
172
+ paddingHorizontal : 4 ,
173
+ paddingVertical : 6 ,
174
+ borderRadius : 4 ,
175
+ justifyContent : 'center' ,
176
+ alignItems : 'center' ,
128
177
} ,
129
178
title : {
130
179
fontSize : 24 ,
131
180
fontWeight : 'bold' ,
181
+ color : Colors . white ,
182
+ textShadowColor : Colors . purple ,
183
+ textShadowOffset : { width : 3 , height : 3 } ,
184
+ textShadowRadius : 5 ,
185
+ textAlign : 'center' ,
186
+ } ,
187
+ labelValue : {
188
+ fontWeight : 'bold' ,
189
+ fontSize : 18 ,
190
+ color : Colors . white ,
191
+ textShadowColor : Colors . purple ,
192
+ textShadowOffset : { width : 1 , height : 1 } ,
193
+ textShadowRadius : 5 ,
194
+ } ,
195
+ textValue : {
196
+ fontSize : 16 ,
197
+ color : Colors . white ,
198
+ textAlign : 'justify' ,
132
199
} ,
133
200
image : {
134
201
width : '100%' ,
135
202
height : 300 ,
136
- // marginVertical: 10,
137
203
} ,
138
204
video : {
139
205
alignSelf : 'center' ,
0 commit comments