-
-
Notifications
You must be signed in to change notification settings - Fork 549
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee6c21c
commit 21b0dbe
Showing
5 changed files
with
229 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import React from 'react'; | ||
import {Provider} from 'react-redux'; | ||
|
||
import {store} from './redux/store'; | ||
import RootNavigator from './navigation/RootNavigator'; | ||
|
||
const App = () => { | ||
return <RootNavigator />; | ||
return ( | ||
<Provider store={store}> | ||
<RootNavigator /> | ||
</Provider> | ||
); | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,100 @@ | ||
import React from 'react'; | ||
import {View, Text, StyleSheet} from 'react-native'; | ||
import {Text, View, FlatList, TouchableOpacity, Image} from 'react-native'; | ||
import {useSelector, useDispatch} from 'react-redux'; | ||
import MaterialIcons from 'react-native-vector-icons/MaterialIcons'; | ||
|
||
import {removeFavorite} from '../redux/actions'; | ||
|
||
const Favorites = () => { | ||
const {favorites} = useSelector(state => state.moviesReducer); | ||
const dispatch = useDispatch(); | ||
const removeFromFavorites = movie => dispatch(removeFavorite(movie)); | ||
const handleRemoveFavorite = movie => { | ||
removeFromFavorites(movie); | ||
}; | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<Text>Favorites</Text> | ||
<View style={{flex: 1, marginTop: 44, paddingHorizontal: 20}}> | ||
<Text style={{fontSize: 22}}>Favorites</Text> | ||
<View style={{flex: 1, marginTop: 8}}> | ||
{favorites.length === 0 ? ( | ||
<Text style={{color: '#010101', fontSize: 18}}> | ||
Add a movie to the list. | ||
</Text> | ||
) : ( | ||
<FlatList | ||
data={favorites} | ||
keyExtractor={item => item.id.toString()} | ||
showsVerticalScrollIndicator={false} | ||
renderItem={({item}) => { | ||
const IMAGE_URL = | ||
'https://image.tmdb.org/t/p/w185' + item.poster_path; | ||
|
||
return ( | ||
<View style={{marginVertical: 12}}> | ||
<View style={{flexDirection: 'row', flex: 1}}> | ||
<Image | ||
source={{ | ||
uri: IMAGE_URL, | ||
}} | ||
resizeMode="cover" | ||
style={{width: 100, height: 150, borderRadius: 10}} | ||
/> | ||
<View style={{flex: 1, marginLeft: 12}}> | ||
<View> | ||
<Text style={{fontSize: 22, paddingRight: 16}}> | ||
{item.title} | ||
</Text> | ||
</View> | ||
<View | ||
style={{ | ||
flexDirection: 'row', | ||
marginTop: 10, | ||
alignItems: 'center', | ||
}}> | ||
<MaterialIcons | ||
color="green" | ||
name="thumb-up" | ||
size={32} | ||
/> | ||
<Text | ||
style={{ | ||
fontSize: 18, | ||
paddingLeft: 10, | ||
color: '#64676D', | ||
}}> | ||
{item.vote_count} | ||
</Text> | ||
<TouchableOpacity | ||
onPress={() => handleRemoveFavorite(item)} | ||
activeOpacity={0.7} | ||
style={{ | ||
marginLeft: 14, | ||
flexDirection: 'row', | ||
padding: 2, | ||
borderRadius: 20, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
height: 40, | ||
width: 40, | ||
}}> | ||
<MaterialIcons | ||
color="orange" | ||
size={32} | ||
name="favorite" | ||
/> | ||
</TouchableOpacity> | ||
</View> | ||
</View> | ||
</View> | ||
</View> | ||
); | ||
}} | ||
/> | ||
)} | ||
</View> | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
}); | ||
|
||
export default Favorites; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,112 @@ | ||
import React from 'react'; | ||
import {View, Text, StyleSheet} from 'react-native'; | ||
import React, {useEffect} from 'react'; | ||
import {View, Text, FlatList, Image, TouchableOpacity} from 'react-native'; | ||
import {useSelector, useDispatch} from 'react-redux'; | ||
import MaterialIcons from 'react-native-vector-icons/MaterialIcons'; | ||
|
||
import {getMovies, addFavorite, removeFavorite} from '../redux/actions'; | ||
|
||
const Movies = () => { | ||
const {movies, favorites} = useSelector(state => state.moviesReducer); | ||
const dispatch = useDispatch(); | ||
const fetchMovies = () => dispatch(getMovies()); | ||
const addToFavorites = movie => dispatch(addFavorite(movie)); | ||
const removeFromFavorites = movie => dispatch(removeFavorite(movie)); | ||
|
||
useEffect(() => { | ||
fetchMovies(); | ||
}, []); | ||
|
||
const handleAddFavorite = movie => { | ||
addToFavorites(movie); | ||
}; | ||
|
||
const handleRemoveFavorite = movie => { | ||
removeFromFavorites(movie); | ||
}; | ||
|
||
const exists = movie => { | ||
if (favorites.filter(item => item.id === movie.id).length > 0) { | ||
return true; | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<Text>Movies</Text> | ||
<View style={{flex: 1, marginTop: 44, paddingHorizontal: 20}}> | ||
<Text style={{fontSize: 22}}>Popular Movies</Text> | ||
<View style={{flex: 1, marginTop: 12}}> | ||
<FlatList | ||
data={movies} | ||
keyExtractor={item => item.id.toString()} | ||
renderItem={({item}) => { | ||
const IMAGE_URL = | ||
'https://image.tmdb.org/t/p/w185' + item.poster_path; | ||
return ( | ||
<View style={{marginVertical: 12}}> | ||
<View style={{flexDirection: 'row', flex: 1}}> | ||
<Image | ||
source={{ | ||
uri: IMAGE_URL, | ||
}} | ||
resizeMode="cover" | ||
style={{width: 100, height: 150, borderRadius: 10}} | ||
/> | ||
<View style={{flex: 1, marginLeft: 12}}> | ||
<View> | ||
<Text style={{fontSize: 22, paddingRight: 16}}> | ||
{item.title} | ||
</Text> | ||
</View> | ||
<View | ||
style={{ | ||
flexDirection: 'row', | ||
marginTop: 10, | ||
alignItems: 'center', | ||
}}> | ||
<MaterialIcons color="green" name="thumb-up" size={32} /> | ||
<Text | ||
style={{ | ||
fontSize: 18, | ||
paddingLeft: 10, | ||
color: '#64676D', | ||
}}> | ||
{item.vote_count} | ||
</Text> | ||
<TouchableOpacity | ||
onPress={() => | ||
exists(item) | ||
? handleRemoveFavorite(item) | ||
: handleAddFavorite(item) | ||
} | ||
activeOpacity={0.7} | ||
style={{ | ||
marginLeft: 14, | ||
flexDirection: 'row', | ||
padding: 2, | ||
borderRadius: 20, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
height: 40, | ||
width: 40, | ||
}}> | ||
<MaterialIcons | ||
color="orange" | ||
size={32} | ||
name={exists(item) ? 'favorite' : 'favorite-outline'} | ||
/> | ||
</TouchableOpacity> | ||
</View> | ||
</View> | ||
</View> | ||
</View> | ||
); | ||
}} | ||
showsVerticalScrollIndicator={false} | ||
/> | ||
</View> | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
}); | ||
|
||
export default Movies; |