Merge pull request 'WORK-RHA2' (#23) from WORK-RHA2 into master
continuous-integration/drone/push Build is passing Details

Reviewed-on: #23
WORK-RRE
Rayhân HASSOU 1 year ago
commit 121d8a5dcd

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

@ -14,7 +14,8 @@ const componentHeight = 60;
const componentWidth = 280;
export default function FoodElementText(props : FoodElementTextProps) {
export default function FoodElementText(props : any) {
const colors = useContext(ColorContext).colors
const styles = StyleSheet.create({

@ -1,12 +1,32 @@
import React, {useContext} from 'react';
import {StyleSheet, Pressable, Text, View, Image, ScrollView} from 'react-native';
import React, {useContext, useState} from 'react';
import {StyleSheet, Pressable, Text, View, Image, ScrollView, ImageSourcePropType} from 'react-native';
import brochette from '../assets/images/brochette.png';
import Union_left from '../assets/images/Union_left.png';
import Union_right from '../assets/images/Union_right.png';
import background from '../assets/images/Background.png';
import cake from '../assets/images/cake.png';
import Carrot_Cake from '../assets/images/Carrot_Cake.png';
import inconnu from '../assets/images/inconnu.png';
import fish from '../assets/images/fish.png';
import fish_meat from '../assets/images/fish_meat.png';
import vegan from '../assets/images/vegan.png';
import egg from '../assets/images/egg.png';
import pizza from '../assets/images/pizza.png';
import soupVeggie from '../assets/images/soupVeggie.png';
import soupFish from '../assets/images/soupfish.png'
import soupMeat from '../assets/images/soupMeat.png'
import meat_with_vegetable from '../assets/images/meat_with_vegetables.png';
import riceVegetable from '../assets/images/rice_vegetables.png';
import riceMeat from '../assets/images/Meat_and_Rice.png';
import riceFish from '../assets/images/rice_fish.png';
import riceEgg from '../assets/images/riceEgg.png';
import pasta from '../assets/images/pasta.png';
import ColorContext from '../theme/ColorContext';
import Recipes from '../Models/Recipes';
interface RecipeElementProps {
recipe: Recipes
navigateDetails: any
@ -24,6 +44,143 @@ function convertToHoursMinutes(totalMinutes: number): string {
export default function RecipeElement(props: RecipeElementProps) {
const {colors} = useContext(ColorContext)
const meatDictionary: string[] = ["beef", "chicken", "turkey", "steak", "rabbit", "duck"]
const porkDictionary: string[] = ["pork", "lardon", "bacon", "ham"]
const fishDictionary: string[] = ["tuna", "whiting", "mullet", "sardine", "mackerel", "salmon", "monkfish", "conger", "bass", "cod", "hake"]
const vegetablesDictionary: string[] = ["vegan", "vegetarian", "lentil", "artichoke", "aubergine", "beet", "chard", "broccoli", "carrot", "celery", "cabbage", "cauliflower", "zucchini", "spinach", "fennel", "curly", "bean", "lettuce", "apple", "corn", "onion", "parsnips", "leek", "pepper", "potato", "pumpkin", "radish", "scarole", "tomato"]
const riceDictionary: string[] = ["ric", "quinoa"]
const eggDictionary: string[] = ["egg", "omelette"];
const soupDictionary: string[] = ["soup"];
const pizzaDictionary: string[] = ["pizza"];
const dessertDictionary: string[] = ['cake', 'cupcake', 'muffin', 'cookie', 'brownie', 'pie', 'tart', 'macaron', 'doughnut', 'eclair', 'pancake', 'waffle', 'crepe', 'pudding', 'gelato', 'sorbet', 'ice cream', 'cheesecake', 'sugar'];
const pastaDictionary: string[] = [
'pasta',
'spaghetti',
'penne',
'fettuccine',
'macaroni',
'rigatoni',
'farfalle',
'linguine',
'lasagne',
'ravioli',
'tortellini',
'gnocchi',
'spaetzle',
'noodles',
'spatzle',
'spatzen',
];
const imagesDictionary = {
meat: meatDictionary,
pork: porkDictionary,
fish: fishDictionary,
egg: eggDictionary,
vegetables: vegetablesDictionary,
rice: riceDictionary,
pizza : pizzaDictionary,
soup : soupDictionary,
dessert : dessertDictionary,
pasta : pastaDictionary,
unknown: [],
};
function getCategoryFromList(categories: string[]) {
const categoryMappings = {
MeatAndVegetables: ['meat', 'vegetables'],
FishAndMeat: ['fish', 'meat'],
dessertDictionary: ['dessert'],
fruitCake: ['vegetables', 'dessert'],
riceEgg: ['rice', 'egg'],
riceMeat: ['rice', 'meat'],
riceFish: ['rice', 'fish'],
riceVegetable: ['rice', 'vegetables'],
soupMeat: ['soup', 'meat'],
soupVeggie: ['soup', 'vegetables'],
soupFish: ['soup', 'fish'],
};
if(categories.length == 1){
return categories[0];
}
console.log("LA LISTE DES CATEGORY : " + categories)
let bestMatch = { category: '', similarity: 0 };
for (const [name, categoriesList] of Object.entries(categoryMappings)) {
const matchingCategories = categories.filter(category => categoriesList.includes(category));
const similarity = matchingCategories.length;
if (similarity > bestMatch.similarity) {
bestMatch = { category: name, similarity };
}
}
return bestMatch.category;
}
function getImageForRecipe(recipeName: string) {
const categories = [];
console.log("NAAAAAME : " + recipeName)
for (const [category, words] of Object.entries(imagesDictionary)) {
const matchedWords = words.filter((word) => recipeName.toLowerCase().includes(word));
console.log("Matched Word : " + matchedWords)
if (matchedWords.length > 0) {
categories.push(category);
console.log(category)
}
}
console.log("ON ENTRE DANS LA 2EME FONCTION");
const categoryName = getCategoryFromList(categories);
console.log("CategoryName à la fin : " + categoryName);
switch (categoryName) {
case 'meat':
return brochette;
case 'pork':
return brochette;
case 'fish':
return fish;
case 'vegetables':
return vegan;
case 'pasta':
return pasta;
case 'MeatAndVegetables':
return meat_with_vegetable;
case 'FishAndMeat':
return fish_meat;
case 'egg':
return egg;
case 'dessert':
return cake;
case 'fruitCake':
return Carrot_Cake;
case 'riceEgg':
return riceEgg;
case 'riceMeat':
return riceMeat;
case 'riceFish':
return riceFish;
case 'riceVegetable':
return riceVegetable;
case 'pizza':
return pizza;
case 'soupVeggie':
return soupVeggie;
case 'soupMeat':
return soupMeat;
case 'soupFish':
return soupFish;
default:
return inconnu;
}
}
const styles = StyleSheet.create({
button: {
@ -87,7 +244,7 @@ export default function RecipeElement(props: RecipeElementProps) {
<View style={styles.view}>
<Text style={styles.text}>{props.recipe.id}</Text>
<Text style={styles.title}>{props.recipe.name}</Text>
<Image source={brochette} style={{width: 100, resizeMode: "contain"}}/>
<Image source={getImageForRecipe(props.recipe.name)} style={{width: 100, maxHeight: 90,resizeMode: "contain"}}/>
<View style={styles.horizontalAlignment}>
<Image source={Union_left} style={{width: "25%", marginRight: "3%", resizeMode: "contain"}} />
<Text style={styles.text}>Ingredients</Text>

@ -10,6 +10,7 @@ interface RecipeElementReduceProps {
title : string
image : string | null
duration : string
imageRecipe: any
}
export default function RecipeElementReduce(props: RecipeElementReduceProps) {
@ -65,7 +66,7 @@ export default function RecipeElementReduce(props: RecipeElementReduceProps) {
<View style={styles.view}>
<Text style={styles.text}>{props.number}</Text>
<Text style={styles.title}>{props.title}</Text>
<Image source={props.image ? props.image : brochette} style={{ width: 100, height: 100, resizeMode: "contain", zIndex: 2}}/>
<Image source={props.imageRecipe} style={{ width: 100, height: 100, resizeMode: "contain", zIndex: 2}}/>
<View style={{marginBottom: "20%"}}/>
<Image source={background} style={{width: "80%", resizeMode: "contain", position: "absolute", zIndex: 1, top: "90%"}}></Image>
<Text style={styles.smallText}>{props.duration}</Text>

@ -3,7 +3,6 @@ import { View, StyleSheet, Text, Image, Pressable, ActivityIndicator, FlatList,
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { Searchbar } from 'react-native-paper';
import { LinearGradient } from 'expo-linear-gradient';
import FoodElementText from '../components/FoodElementText';
import Ingredient from '../Models/Ingredient';
import IngredientService from '../Services/Ingredients/IngredientsServices';
@ -66,33 +65,29 @@ const loadIngredients = async () => {
ChangeAvailableSize(true)
}, []);
const AvailableItem = ({ value }: { value: Ingredient }) => (
const AvailableItem = React.memo(({ value }: { value: Ingredient }) => (
<>
<View style={styles.horizontalAlignment}>
<Pressable onPress={() => SelectIngredient(value)}>
<FoodElementText title={value.name}/>
</Pressable>
<Pressable onPress={() => SelectIngredient(value)}>
<Image source={plus} style={{ width: 20, height: 20, tintColor: colors.cardDetail }} />
</Pressable>
</View>
<View style={{ height: 20 }}></View>
</>
);
));
const ChooseItem = ({ value }: { value: Ingredient }) => (
const ChooseItem = React.memo(({ value }: { value: Ingredient }) => (
<>
<View style={styles.horizontalAlignment}>
<Pressable onPress={() => RemoveIngredient(value.id)}>
<FoodElementText title={value.name} />
</Pressable>
<Pressable onPress={() => RemoveIngredient(value.id)}>
<Image source={moins} style={{ width: 20, height: 20, tintColor: colors.cardDetail }} />
</Pressable>
</View>
<View style={{ height: 20 }}></View>
</>
);
));
const handleGetAvailableIngredient = async () => {
try {

@ -1,7 +1,6 @@
import React, { useEffect, useState, useContext } from 'react';
import { View, StyleSheet, Text, ScrollView, useWindowDimensions} from 'react-native';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import RecipeElementReduce from '../components/RecipeElementReduce';
import RecipesService from '../Services/Recipes/RecipesServices';
import Recipes from '../Models/Recipes';
@ -9,6 +8,25 @@ import { LinearGradient } from 'expo-linear-gradient';
import ListWithoutSelect from '../components/ListWithoutSelect';
import ColorContext from '../theme/ColorContext';
import Ingredient from '../Models/Ingredient';
import cake from '../assets/images/cake.png';
import Carrot_Cake from '../assets/images/Carrot_Cake.png';
import inconnu from '../assets/images/inconnu.png';
import fish from '../assets/images/fish.png';
import fish_meat from '../assets/images/fish_meat.png';
import vegan from '../assets/images/vegan.png';
import egg from '../assets/images/egg.png';
import pizza from '../assets/images/pizza.png';
import soupVeggie from '../assets/images/soupVeggie.png';
import soupFish from '../assets/images/soupfish.png'
import soupMeat from '../assets/images/soupMeat.png'
import meat_with_vegetable from '../assets/images/meat_with_vegetables.png';
import riceVegetable from '../assets/images/rice_vegetables.png';
import riceMeat from '../assets/images/Meat_and_Rice.png';
import riceFish from '../assets/images/rice_fish.png';
import riceEgg from '../assets/images/riceEgg.png';
import brochette from '../assets/images/brochette.png';
import pasta from '../assets/images/pasta.png';
export default function RecipeDetails({ route }) {
@ -23,6 +41,141 @@ export default function RecipeDetails({ route }) {
const { recipeId } = route.params;
const meatDictionary: string[] = ["beef", "chicken", "turkey", "steak", "rabbit", "duck"]
const porkDictionary: string[] = ["pork", "lardon", "bacon", "ham"]
const fishDictionary: string[] = ["tuna", "whiting", "mullet", "sardine", "mackerel", "salmon", "monkfish", "conger", "bass", "cod", "hake"]
const vegetablesDictionary: string[] = ["vegan", "vegetarian", "lentil", "artichoke", "aubergine", "beet", "chard", "broccoli", "carrot", "celery", "cabbage", "cauliflower", "zucchini", "spinach", "fennel", "curly", "bean", "lettuce", "apple", "corn", "onion", "parsnips", "leek", "pepper", "potato", "pumpkin", "radish", "scarole", "tomato"]
const riceDictionary: string[] = ["ric", "quinoa"]
const eggDictionary: string[] = ["egg", "omelette"];
const soupDictionary: string[] = ["soup"];
const pizzaDictionary: string[] = ["pizza"];
const dessertDictionary: string[] = ['cake', 'cupcake', 'muffin', 'cookie', 'brownie', 'pie', 'tart', 'macaron', 'doughnut', 'eclair', 'pancake', 'waffle', 'crepe', 'pudding', 'gelato', 'sorbet', 'ice cream', 'cheesecake', 'sugar'];
const pastaDictionary: string[] = [
'pasta',
'spaghetti',
'penne',
'fettuccine',
'macaroni',
'rigatoni',
'farfalle',
'linguine',
'lasagne',
'ravioli',
'tortellini',
'gnocchi',
'spaetzle',
'noodles',
'spatzle',
'spatzen',
];
const imagesDictionary = {
meat: meatDictionary,
pork: porkDictionary,
fish: fishDictionary,
egg: eggDictionary,
vegetables: vegetablesDictionary,
rice: riceDictionary,
pizza : pizzaDictionary,
soup : soupDictionary,
dessert : dessertDictionary,
pasta : pastaDictionary,
unknown: [],
};
function getCategoryFromList(categories: string[]) {
const categoryMappings = {
MeatAndVegetables: ['meat', 'vegetables'],
FishAndMeat: ['fish', 'meat'],
dessertDictionary: ['dessert'],
fruitCake: ['vegetables', 'dessert'],
riceEgg: ['rice', 'egg'],
riceMeat: ['rice', 'meat'],
riceFish: ['rice', 'fish'],
riceVegetable: ['rice', 'vegetables'],
soupMeat: ['soup', 'meat'],
soupVeggie: ['soup', 'vegetables'],
soupFish: ['soup', 'fish'],
};
if(categories.length == 1){
return categories[0];
}
console.log("LA LISTE DES CATEGORY : " + categories)
let bestMatch = { category: '', similarity: 0 };
for (const [name, categoriesList] of Object.entries(categoryMappings)) {
const matchingCategories = categories.filter(category => categoriesList.includes(category));
const similarity = matchingCategories.length;
if (similarity > bestMatch.similarity) {
bestMatch = { category: name, similarity };
}
}
return bestMatch.category;
}
function getImageForRecipe(recipeName: string) {
const categories = [];
console.log("NAAAAAME : " + recipeName)
for (const [category, words] of Object.entries(imagesDictionary)) {
const matchedWords = words.filter((word) => recipeName.toLowerCase().includes(word));
console.log("Matched Word : " + matchedWords)
if (matchedWords.length > 0) {
categories.push(category);
console.log(category)
}
}
console.log("ON ENTRE DANS LA 2EME FONCTION");
const categoryName = getCategoryFromList(categories);
console.log("CategoryName à la fin : " + categoryName);
switch (categoryName) {
case 'meat':
return brochette;
case 'pork':
return brochette;
case 'fish':
return fish;
case 'vegetables':
return vegan;
case 'pasta':
return pasta;
case 'MeatAndVegetables':
return meat_with_vegetable;
case 'FishAndMeat':
return fish_meat;
case 'egg':
return egg;
case 'dessert':
return cake;
case 'fruitCake':
return Carrot_Cake;
case 'riceEgg':
return riceEgg;
case 'riceMeat':
return riceMeat;
case 'riceFish':
return riceFish;
case 'riceVegetable':
return riceVegetable;
case 'pizza':
return pizza;
case 'soupVeggie':
return soupVeggie;
case 'soupMeat':
return soupMeat;
case 'soupFish':
return soupFish;
default:
return inconnu;
}
}
const loadRecipe = async () => {
try {
const recipe = await recipesService.getRecipeById(recipeId);
@ -98,6 +251,7 @@ export default function RecipeDetails({ route }) {
<LinearGradient colors={[colors.primary, colors.primaryComplement]} style={[styles.linearGradient, {minHeight: useWindowDimensions().height}]}>
<View style={{marginTop: "6%"}}>
<RecipeElementReduce
imageRecipe={getImageForRecipe(response.name)}
title={response.name}
number={response.id}
duration={convertToHoursMinutes(response.time_to_cook)} image={''}/>

Loading…
Cancel
Save