Diets Management
continuous-integration/drone/push Build is passing Details

WORK-RRE
Louison PARANT 1 year ago
parent 3dee4a4dd4
commit 31e7ed6bda

@ -0,0 +1,9 @@
export enum IngredientClass {
DairyFree = 'DAIRY_FREE',
GlutenFree = 'GLUTEN_FREE',
Porcless = 'PORCLESS',
Vegan = 'VEGAN',
Vegetarian = 'VEGETARIAN',
Pescatarian = 'PESCATARIAN',
None = 'NONE'
}

@ -1,30 +0,0 @@
export default class Profil {
private _name: string;
private _avatar: string;
private _allergy: string[];
private _diets: string[];
constructor( name: string, avatar: string, allergy: string[], diets: string[]) {
this._name = name;
this._avatar = avatar;
this._allergy = allergy;
this._diets = diets;
}
get name(): string {
return this._name;
}
get avatar(): string{
return this._avatar;
}
get allergy(): string[]{
return this._allergy;
}
get diets(): string[]{
return this._diets;
}
}

@ -105,7 +105,6 @@ export default function RecipeElement(props: RecipeElementProps) {
return categories[0];
}
console.log("LA LISTE DES CATEGORY : " + categories)
let bestMatch = { category: '', similarity: 0 };
for (const [name, categoriesList] of Object.entries(categoryMappings)) {
@ -122,20 +121,15 @@ export default function RecipeElement(props: RecipeElementProps) {
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':

@ -10,6 +10,7 @@ import ColorContext from '../theme/ColorContext';
import eventEmitter from './EventEmitter';
import AsyncStorage from '@react-native-async-storage/async-storage';
import ProfileService from '../Services/Profiles/ProfileService';
import { IngredientClass } from '../Models/IngredientClass';
export default function FiltersSelection(props) {
const {colors} = useContext(ColorContext);
@ -24,6 +25,7 @@ export default function FiltersSelection(props) {
const [dieAdd, setDieAdd] = useState([])
const [allAdd, setAllAdd] = useState([])
const [selectedDiets, setSelectedDiets] = useState([])
const [activeDiets, setActiveDiets] = useState([])
const fetchProfiles = async () => {
setProfiles(await profileService.getProfiles())
@ -234,7 +236,65 @@ export default function FiltersSelection(props) {
},
});
const goBack = () => props.navigation.goBack();
const handleSaveFilters = async () => {
let dieTemp = []
let retType = true
profiles.forEach((profile) => {
if(profile.isActive == "flex"){
profile.diets.forEach((diet) => {
retType = true
dieTemp.forEach((val) => {
if(val == diet){
retType = false
}
})
if(retType){
dieTemp.push(diet)
}
})
}
})
selectedDiets.forEach((diet) => {
retType = true
dieTemp.forEach((val) => {
if(val == diet){
retType = false
}
})
if(retType){
dieTemp.push(diet)
}
})
setActiveDiets(await handleCastFilters(dieTemp))
eventEmitter.emit("updateActiveDiets")
props.navigation.goBack()
}
const handleCastFilters = async (values) => {
let diets = []
values.forEach((val) => {
if (val == "Dairy free"){
diets.push(IngredientClass.DairyFree)
}
else if (val == "Gluten free"){
diets.push(IngredientClass.GlutenFree)
}
else if (val == "Porkless"){
diets.push(IngredientClass.Porcless)
}
else if (val == "Vegan"){
diets.push(IngredientClass.Vegan)
}
else if (val == "Vegetarian"){
diets.push(IngredientClass.Vegetarian)
}
else{
diets.push(IngredientClass.Pescatarian)
}
})
await AsyncStorage.setItem('activeDiets', JSON.stringify(diets));
return diets
}
return (
<SafeAreaProvider style={{flex: 1}}>
@ -273,7 +333,7 @@ export default function FiltersSelection(props) {
<ValidateButton title="Add Allergy" image="plus.png" colour={colors.buttonDetail} backColour={colors.buttonBackground} todo={() => props.navigation.navigate("IngredientSelection")}></ValidateButton>
</View>
<View style={{marginTop: "6%"}}/>
<ValidateButton title="Save Filters" image="save.png" colour={colors.buttonMain} backColour={colors.cardBackground} todo={goBack}></ValidateButton>
<ValidateButton title="Save Filters" image="save.png" colour={colors.buttonMain} backColour={colors.cardBackground} todo={handleSaveFilters}></ValidateButton>
<View style={{marginTop: "20%"}}/>
</LinearGradient>
</ScrollView>

@ -17,7 +17,8 @@ import plus from '../assets/images/plus_small.png';
import minus from '../assets/images/minus.png';
import RecipesServices from '../Services/Recipes/RecipesServices';
import Recipes from '../Models/Recipes';
import eventEmitter from './EventEmitter';
import AsyncStorage from '@react-native-async-storage/async-storage';
export default function RecipeSuggestion({ route, navigation }) {
const {colors} = useContext(ColorContext)
@ -32,6 +33,7 @@ export default function RecipeSuggestion({ route, navigation }) {
const recipeService = new RecipesServices();
const {ingredients} = route.params;
const limitedList = ingredients.slice(minCpt, maxCpt);
const [activeDiets, setActiveDiets] = useState([])
let selectedIngredients: string[];
@ -104,7 +106,8 @@ export default function RecipeSuggestion({ route, navigation }) {
};
useEffect(() => {
loadRecipes();
loadRecipes()
fetchActiveDiets()
}, []);
const styles = StyleSheet.create({
@ -196,6 +199,19 @@ export default function RecipeSuggestion({ route, navigation }) {
},
});
const subscriptionUpdateActiveDiets = eventEmitter.addListener('updateActiveDiets', async () => {
fetchActiveDiets()
subscriptionUpdateActiveDiets.remove();
});
const fetchActiveDiets = async () => {
const results = await AsyncStorage.getItem('activeDiets')
let existingActiveDiets = JSON.parse(results)
if(existingActiveDiets.length == 0){
existingActiveDiets = []
}
setActiveDiets(existingActiveDiets)
}
const ingredientElements = limitedList.map((source, index) => (
<View style={[styles.horizontalAlignment, {marginVertical: "3%"}]} key={index}>

Loading…
Cancel
Save