File tree Expand file tree Collapse file tree 3 files changed +55
-4
lines changed
components/recipe-components Expand file tree Collapse file tree 3 files changed +55
-4
lines changed Original file line number Diff line number Diff line change 1
- import { Text } from "react-native" ;
1
+ import { ScrollView , Text } from "react-native" ;
2
+ import RecipeCard from "../components/recipe-components/RecipeCard" ;
3
+ import { Constants } from "../util/constants" ;
4
+ import { useSelector , useDispatch } from "react-redux" ;
5
+ import { ingredientsArray } from "../util/slices/inventorySlice" ;
2
6
3
7
function RecipesScreen ( ) {
4
- return < Text style = { { marginTop : 20 } } > Recipes Screen</ Text > ;
8
+ const drinkList = Constants . drinkList ;
9
+ const ingredients = useSelector ( ( state ) => state . inventory . ingredientsArray ) ;
10
+
11
+ return (
12
+ < ScrollView >
13
+ < Text style = { { marginVertical : 20 } } > Recipes Screen</ Text >
14
+
15
+ { ingredients . map ( ( ingredient ) => (
16
+ < Text > { ingredient } </ Text >
17
+ ) ) }
18
+
19
+ { drinkList . map ( ( drink ) => {
20
+ let drinkIngredients = drink . ingredients ;
21
+ for ( let i = 0 ; i < drinkIngredients . length ; i ++ ) {
22
+ if ( ingredients . indexOf ( drinkIngredients [ i ] ) < 0 ) {
23
+ return ;
24
+ }
25
+ }
26
+ return < RecipeCard > { drink . name } </ RecipeCard > ;
27
+ } ) }
28
+ </ ScrollView >
29
+ ) ;
5
30
}
6
31
7
- export default RecipesScreen ;
32
+ export default RecipesScreen ;
Original file line number Diff line number Diff line change
1
+ import { View , Text , StyleSheet } from "react-native" ;
2
+
3
+ function RecipeCard ( { children} ) {
4
+ return < View style = { styles . container } >
5
+ < Text style = { styles . label } > { children } </ Text >
6
+ </ View >
7
+ }
8
+
9
+ export default RecipeCard ;
10
+
11
+ const styles = StyleSheet . create ( {
12
+ container : {
13
+ marginHorizontal : 12 ,
14
+ marginVertical : 12 ,
15
+ paddingVertical : 12 ,
16
+ borderColor : 'black' ,
17
+ borderWidth : 2 ,
18
+ borderRadius : 5 ,
19
+ alignItems : 'center' ,
20
+ } ,
21
+ label : {
22
+ fontSize : 18 ,
23
+ fontWeight : 'bold'
24
+ }
25
+ } )
26
+
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { createSlice } from "@reduxjs/toolkit";
3
3
export const inventorySlice = createSlice ( {
4
4
name : "inventory" ,
5
5
initialState : {
6
- ingredientsArray : [ 'water ' ] ,
6
+ ingredientsArray : [ 'Water ' ] ,
7
7
} ,
8
8
reducers : {
9
9
addIngredient : ( state , action ) => {
You can’t perform that action at this time.
0 commit comments