-
Notifications
You must be signed in to change notification settings - Fork 0
/
Home.js
323 lines (312 loc) · 8.53 KB
/
Home.js
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
import React, {useState, useEffect} from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
TextInput,
TouchableOpacity,
Dimensions,
Button,
Image,
} from 'react-native';
import {
Header,
LearnMoreLinks,
Colors,
DebugInstructions,
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
import axios from 'axios';
import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import {createDrawerNavigator} from '@react-navigation/drawer';
import 'react-native-gesture-handler';
import Category from './components/Explore/Category';
import BigMovie from './components/Explore/BigMovie';
import {withSafeAreaInsets} from 'react-native-safe-area-context';
import AsyncStorage from '@react-native-async-storage/async-storage';
import SlidingUpPanel from 'rn-sliding-up-panel';
import SearchCard from './components/Explore/SearchCard';
const {width, height} = Dimensions.get('window');
export const Home = (props) => {
const date = new Date();
const [movies, setMovies] = useState([]);
const [searchData, setSearchData] = useState([]);
const [newMovies, setNewMovies] = useState([]);
const searchThis = 'searchMovies';
useEffect(() => {
const fetchData = async () => {
try {
const response = await axios.post(
'http://143.110.173.215:2005/api/popMovies',
);
setMovies(
response.data.results.map((m) => ({
id: m.id,
title: m.title,
rating: m.vote_average / 2,
image: m.poster_path,
genre: m.genre_ids,
overview: m.overview,
})),
);
} catch (e) {
console.log(e);
}
};
fetchData();
}, []);
useEffect(() => {
const fetchDataNew = async () => {
try {
const responseNew = await axios.post(
'http://143.110.173.215:2005/api/newMovies',
);
setNewMovies(
responseNew.data.results.map((n) => ({
id: n.id,
title: n.title,
rating: n.vote_average / 2,
image: n.poster_path,
released: n.release_date,
overview: n.overview,
genre: n.genre_ids,
overview: n.overview,
})),
);
} catch (e) {
console.log(e);
}
};
fetchDataNew();
}, []);
if (searchData.length == 0) {
return (
<View>
<StatusBar barStyle="dark-content" />
<SafeAreaView>
<ScrollView>
<ScrollView scrollEventThrottle={16}>
<View
style={{flex: 1, backgroundColor: '#1C1C1C', paddingTop: 20}}>
<SearchCard
setSearch={setSearchData}
data={searchData}
routeTo={searchThis}
/>
<View style={styles.containerText}>
<View style={styles.line}></View>
<Text style={styles.featuredText}>Featured</Text>
</View>
<View style={{height: 220, marginTop: 20}}>
<ScrollView
horizontal={true}
showsHorizontalScrollIndicator={false}>
{movies.map((movie) => (
<Category
name={movie.title}
score={movie.rating}
imageUri={
'https://image.tmdb.org/t/p/w500/' + movie.image
}
key={movie.title}
genre={movie.genre}
desc={movie.overview}
id={movie.id}
/>
))}
</ScrollView>
</View>
</View>
</ScrollView>
<ScrollView scrollEventThrottle={16}>
<View
style={{flex: 1, backgroundColor: '#1C1C1C', paddingTop: 20}}>
<View style={styles.containerTextSecond}>
<View style={styles.line}></View>
<Text style={styles.newReleasesText}>Now Playing</Text>
</View>
{newMovies.map((movie) => (
<BigMovie
name={movie.title}
score={movie.rating}
imageUri={'https://image.tmdb.org/t/p/w500/' + movie.image}
key={movie.id}
id={movie.id}
released={movie.released.split('-')}
overview={movie.overview}
genre={movie.genre}
desc={movie.overview}
/>
))}
</View>
</ScrollView>
</ScrollView>
</SafeAreaView>
</View>
);
} else {
return (
<View>
<StatusBar barStyle="dark-content" />
<SafeAreaView style={{height: height, backgroundColor: '#1C1C1C'}}>
<View
style={{
width: width,
height: height,
backgroundColor: '#1c1c1c',
}}>
<ScrollView>
<TouchableOpacity
onPress={() => setSearchData([])}
style={{
flexDirection: 'row',
marginLeft: 20,
marginTop: 40,
marginBottom: 7,
}}>
<Image
source={require('./images/left-arrowWhite.png')}
style={{width: 20, height: 20, marginRight: 10}}
/>
<Text style={{color: '#fff', fontSize: 16}}>Back</Text>
</TouchableOpacity>
<View style={styles.containerText}>
<View style={styles.line}></View>
<Text style={styles.searchText}>Search Results for: </Text>
<Text
style={{
fontSize: 16,
marginLeft: 4,
marginTop: 4,
color: 'white',
}}>
</Text>
</View>
<ScrollView scrollEventThrottle={16}>
{searchData.map((search) => (
<BigMovie
name={search.title}
score={search.rating}
imageUri={'https://image.tmdb.org/t/p/w500/' + search.image}
released={search.released}
key={search.title}
/>
))}
</ScrollView>
</ScrollView>
</View>
</SafeAreaView>
</View>
);
}
};
const styles = StyleSheet.create({
searchInputText: {
fontSize: 16,
marginLeft: 4,
marginTop: 4,
},
containerText: {
flexDirection: 'row',
marginTop: 15,
marginLeft: 20,
color: '#333333',
},
containerTextSecond: {
flexDirection: 'row',
marginTop: 24,
marginLeft: 20,
color: '#333333',
},
line: {
width: 70,
height: 6,
backgroundColor: '#F7AA36',
marginTop: 14,
},
featuredText: {
fontSize: 25,
fontWeight: 'bold',
marginLeft: 14,
color: 'white',
},
searchText: {
fontSize: 22,
fontWeight: 'bold',
marginLeft: 14,
color: 'white',
},
newReleasesText: {
fontSize: 25,
fontWeight: 'bold',
marginLeft: 14,
color: 'white',
},
icon: {
backgroundColor: '#e1e6e2',
borderRadius: 90,
width: 45,
height: 45,
marginTop: 24,
marginRight: 23,
alignSelf: 'flex-end',
zIndex: 1000,
justifyContent: 'center',
alignContent: 'center',
alignItems: 'center',
},
container: {
backgroundColor: 'white',
height: height,
},
closePanel: {
alignSelf: 'flex-end',
marginRight: 30,
marginTop: 25,
},
mainFieldBox: {
flexDirection: 'row',
width: width - 120,
height: 40,
borderColor: '#333',
borderWidth: 2,
backgroundColor: '#e1e6e2',
justifyContent: 'space-between',
alignItems: 'center',
alignContent: 'center',
marginTop: 20,
},
editIcon: {
marginRight: 13,
},
imageEdit: {
height: 20,
width: 20,
},
inputName: {
paddingLeft: 10,
},
wrapperFields: {
textAlign: 'center',
justifyContent: 'center',
alignItems: 'center',
alignContent: 'center',
},
wrapperInfo: {
flexDirection: 'row',
marginTop: 22,
marginBottom: 15,
justifyContent: 'center',
},
wrapperInfoInfo: {
marginLeft: 34,
},
wrapperInfoName: {
fontWeight: 'bold',
fontSize: 17,
},
});