-
Notifications
You must be signed in to change notification settings - Fork 1
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
6c20d3e
commit 0633dd1
Showing
20 changed files
with
614 additions
and
94 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from "react"; | ||
import { StyleSheet, Text } from "react-native"; | ||
|
||
const BoldText = (props) => { | ||
return ( | ||
<Text {...props} style={[styles.boldText, props.style]}> | ||
{props.children} | ||
</Text> | ||
); | ||
}; | ||
|
||
export default BoldText; | ||
|
||
const styles = StyleSheet.create({ | ||
boldText: { | ||
fontFamily: "Quicksand-Bold", | ||
}, | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from "react"; | ||
import { createStackNavigator } from "@react-navigation/stack"; | ||
import Favorites from "../screens/Favorites"; | ||
import Colors from "../constants/Colors"; | ||
import CharacterProfile from "../screens/CharacterProfile"; | ||
import ProfileHeaderRight from "./ProfileHeaderRight"; | ||
const Stack = createStackNavigator(); | ||
const FavoritesAndProfileStack = () => { | ||
return ( | ||
<Stack.Navigator> | ||
<Stack.Screen | ||
name="Favorites" | ||
options={{ headerShown: false }} | ||
component={Favorites} | ||
/> | ||
<Stack.Screen | ||
options={({ route }) => { | ||
const { character } = route.params; | ||
|
||
return { | ||
headerTitle: character.name, | ||
headerStyle: { | ||
backgroundColor: Colors.primary, | ||
elevation: 0, | ||
shadowColor: "transparent", | ||
}, | ||
headerTintColor: "white", | ||
headerTitleStyle: { | ||
fontFamily: "Quicksand-SB", | ||
}, | ||
headerRight: () => <ProfileHeaderRight route={route} />, | ||
|
||
headerRightContainerStyle: { | ||
width: 50, | ||
justifyContent: "center", | ||
alignItems: "center", | ||
height: "100%", | ||
}, | ||
headerLeftContainerStyle: { | ||
width: 50, | ||
justifyContent: "center", | ||
alignItems: "center", | ||
height: "100%", | ||
}, | ||
}; | ||
}} | ||
name="CharacterProfile" | ||
component={CharacterProfile} | ||
/> | ||
</Stack.Navigator> | ||
); | ||
}; | ||
|
||
export default FavoritesAndProfileStack; |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { TouchableOpacity, View, Text } from "react-native"; | ||
import Home from "../screens/Home"; | ||
import CharacterProfile from "../screens/CharacterProfile"; | ||
import React, { useState, useEffect } from "react"; | ||
import { createStackNavigator } from "@react-navigation/stack"; | ||
import Colors from "../constants/Colors"; | ||
import { Ionicons } from "@expo/vector-icons"; | ||
import ProfileHeaderRight from "./ProfileHeaderRight"; | ||
const Stack = createStackNavigator(); | ||
|
||
const HomeAndProfileStack = () => { | ||
return ( | ||
<Stack.Navigator> | ||
<Stack.Screen | ||
options={{ headerShown: false }} | ||
name="Home" | ||
component={Home} | ||
/> | ||
<Stack.Screen | ||
options={({ route }) => { | ||
const { character } = route.params; | ||
const { char_id } = character; | ||
return { | ||
headerTitle: character.name, | ||
headerStyle: { | ||
backgroundColor: Colors.primary, | ||
elevation: 0, | ||
shadowColor: "transparent", | ||
}, | ||
headerTintColor: "white", | ||
headerTitleStyle: { | ||
fontFamily: "Quicksand-SB", | ||
}, | ||
headerRight: () => <ProfileHeaderRight route={route} />, | ||
|
||
headerRightContainerStyle: { | ||
width: 50, | ||
justifyContent: "center", | ||
alignItems: "center", | ||
height: "100%", | ||
}, | ||
headerLeftContainerStyle: { | ||
width: 50, | ||
justifyContent: "center", | ||
alignItems: "center", | ||
height: "100%", | ||
}, | ||
}; | ||
}} | ||
name="CharacterProfile" | ||
component={CharacterProfile} | ||
/> | ||
</Stack.Navigator> | ||
); | ||
}; | ||
export default HomeAndProfileStack; |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React, { useState, useEffect, useContext } from "react"; | ||
import { ReducerContext } from "../contexts"; | ||
import { ACTIONS } from "../contexts/reducer"; | ||
import { StyleSheet, TouchableOpacity } from "react-native"; | ||
import { Ionicons } from "@expo/vector-icons"; | ||
const ProfileHeaderRight = ({ route }) => { | ||
const context = useContext(ReducerContext); | ||
|
||
const { character } = route.params; | ||
const { char_id } = character; | ||
const [starred, setStarred] = useState(false); | ||
const toggleStar = () => setStarred(!starred); | ||
useEffect(() => { | ||
const isCharacterFavorited = context.state.favorites.some( | ||
(fav) => fav.char_id === char_id | ||
); | ||
if (isCharacterFavorited) setStarred(true); | ||
else setStarred(false); | ||
}, [context.state.favorites.length]); | ||
|
||
const toggleFavorites = () => { | ||
if (starred) { | ||
// If character is already starred, we should setStarred to false, and remove character from favorites | ||
toggleStar(); | ||
const newFavs = context.state.favorites.filter( | ||
(fav) => fav.char_id !== char_id | ||
); | ||
context.dispatch({ type: ACTIONS.REMOVE_FAVORITE, newFavs }); | ||
} else { | ||
toggleStar(); | ||
context.dispatch({ type: ACTIONS.ADD_FAVORITE, character }); | ||
} | ||
}; | ||
return ( | ||
<TouchableOpacity onPress={toggleFavorites}> | ||
<Ionicons | ||
name={starred ? "ios-star" : "star-outline"} | ||
color={"white"} | ||
size={23} | ||
/> | ||
</TouchableOpacity> | ||
); | ||
}; | ||
|
||
export default ProfileHeaderRight; | ||
|
||
const styles = StyleSheet.create({}); |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { createContext } from "react"; | ||
|
||
export const ReducerContext = createContext(); | ||
export const reducerInitalState = { | ||
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export const ACTIONS = { | ||
REMOVE_FAVORITE: "REMOVE_FAVORITE", | ||
ADD_FAVORITE: "ADD_FAVORITE", | ||
}; | ||
|
||
const reducer = (state, action) => { | ||
if (action.type === ACTIONS.ADD_FAVORITE) { | ||
return { | ||
...state, | ||
favorites: [...state.favorites, { ...action.character }], | ||
}; | ||
} | ||
if (action.type === ACTIONS.REMOVE_FAVORITE) { | ||
return { ...state, favorites: action.newFavs }; | ||
} | ||
return { ...state }; | ||
}; | ||
|
||
export default reducer; |
Oops, something went wrong.