Skip to content

Commit 75833c2

Browse files
committed
Get data to show up correctly in recipe modal
1 parent f37fa05 commit 75833c2

File tree

4 files changed

+87
-53
lines changed

4 files changed

+87
-53
lines changed

Screens/IngredientsTabs/LightBoozeTab.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ function LightBoozeTab() {
1313
const ingredients = useSelector((state) => state.inventory);
1414
const dispatch = useDispatch();
1515
// dispatch(inventory.addIngredient('bourbon'))
16-
console.log("addIngredient", addIngredient),
17-
console.log("ingredients", ingredients);
1816

1917
return (
2018
<ScrollView>

Screens/RecipesScreen.js

Lines changed: 36 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
1-
import {
2-
ScrollView,
3-
Text,
4-
Modal,
5-
View,
6-
Pressable,
7-
StyleSheet,
8-
} from "react-native";
1+
import { ScrollView, Text, View, Pressable, StyleSheet } from "react-native";
92
import RecipeCard from "../components/recipe-components/RecipeCard";
103
import { Constants } from "../util/constants";
11-
import { useSelector, useDispatch } from "react-redux";
12-
import { ingredientsArray } from "../util/slices/inventorySlice";
4+
import { useSelector } from "react-redux";
5+
import RecipeModal from "../components/recipe-components/RecipeModal";
6+
import { useState, useEffect, useLayoutEffect } from "react";
137

148
function RecipesScreen() {
159
const drinkList = Constants.drinkList;
1610
const ingredients = useSelector((state) => state.inventory.ingredientsArray);
11+
const [modalVisible, setModalVisible] = useState(true);
12+
const [recipeTitle, setRecipeTitle] = useState("");
13+
const [recipeIngredients, setRecipeIngredients] = useState([]);
14+
const [recipeInstructions, setRecipeInstructions] = useState([]);
15+
16+
function showDrinkModal(title, ingredients, instructions) {
17+
setRecipeTitle(title);
18+
setRecipeIngredients(ingredients);
19+
setRecipeInstructions(instructions);
20+
setModalVisible(true);
21+
}
1722

1823
return (
1924
<ScrollView>
2025
<Text style={{ marginVertical: 20 }}>Recipes Screen</Text>
2126

22-
<Modal animationType="slide" transparent={true} visible={true}>
23-
<View style={styles.centeredView}>
24-
<View style={styles.modalView}>
25-
<Text style={styles.modalText}>This is the MODAL!</Text>
26-
<Pressable>
27-
<Text>Here is a pressable</Text>
28-
</Pressable>
29-
</View>
30-
</View>
31-
</Modal>
27+
<RecipeModal
28+
recipeTitle={recipeTitle}
29+
recipeIngredients={recipeIngredients}
30+
recipeInstructions={recipeInstructions}
31+
modalVisible={modalVisible}
32+
setModalVisible={setModalVisible}
33+
/>
3234

3335
{ingredients.map((ingredient) => (
3436
<Text>{ingredient}</Text>
@@ -41,39 +43,23 @@ function RecipesScreen() {
4143
return;
4244
}
4345
}
44-
return <RecipeCard>{drink.name}</RecipeCard>;
46+
console.log("drink", drink);
47+
return (
48+
<Pressable
49+
onPress={() =>
50+
showDrinkModal(
51+
drink.name,
52+
drink.ingredients[0].toString(),
53+
drink.instructions
54+
)
55+
}
56+
>
57+
<RecipeCard>{drink.name}</RecipeCard>
58+
</Pressable>
59+
);
4560
})}
4661
</ScrollView>
4762
);
4863
}
4964

5065
export default RecipesScreen;
51-
52-
const styles = StyleSheet.create({
53-
ceneteredView: {
54-
flex: 1,
55-
justifyContent: 'center',
56-
alignItems: 'center',
57-
marginTop: 22,
58-
},
59-
modalView: {
60-
margin: 20,
61-
marginTop: 280,
62-
backgroundColor: 'white',
63-
borderRadius: 20,
64-
padding: 35,
65-
alignItems: 'center',
66-
shadowColor: '#000',
67-
shadowOffset: {
68-
width: 0,
69-
height: 2,
70-
},
71-
shadowOpacity: 0.25,
72-
shadowRadius: 4,
73-
elevation: 5,
74-
},
75-
modalText: {
76-
color: 'green',
77-
fontSize: 12,
78-
}
79-
});
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Text, Modal, View, Pressable, StyleSheet } from "react-native";
2+
import { useState } from "react";
3+
4+
function RecipeModal({ recipeTitle, recipeIngredients, recipeInstructions, modalVisible, setModalVisible }) {
5+
6+
return (
7+
<Modal animationType="slide" transparent={true} visible={modalVisible}>
8+
<View style={styles.centeredView}>
9+
<View style={styles.modalView}>
10+
<Text style={styles.modalText}>{recipeTitle}</Text>
11+
<Text>Ingredients: {recipeIngredients}</Text>
12+
<Text>Instructions: {recipeInstructions}</Text>
13+
<Pressable onPress={() => setModalVisible(!modalVisible)}>
14+
<Text>Here is a pressable</Text>
15+
</Pressable>
16+
</View>
17+
</View>
18+
</Modal>
19+
);
20+
}
21+
22+
export default RecipeModal;
23+
24+
const styles = StyleSheet.create({
25+
ceneteredView: {
26+
flex: 1,
27+
justifyContent: "center",
28+
alignItems: "center",
29+
marginTop: 22,
30+
},
31+
modalView: {
32+
margin: 20,
33+
marginTop: 280,
34+
backgroundColor: "white",
35+
borderRadius: 20,
36+
padding: 35,
37+
alignItems: "center",
38+
shadowColor: "#000",
39+
shadowOffset: {
40+
width: 0,
41+
height: 2,
42+
},
43+
shadowOpacity: 0.25,
44+
shadowRadius: 4,
45+
elevation: 5,
46+
},
47+
modalText: {
48+
color: "green",
49+
fontSize: 24,
50+
},
51+
});

util/slices/inventorySlice.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export const inventorySlice = createSlice({
77
},
88
reducers: {
99
addIngredient: (state, action) => {
10-
console.log('addIngredient')
1110
state.ingredientsArray.push(action.payload);
1211
},
1312
removeIngredient: (state, action) => {

0 commit comments

Comments
 (0)