features add profiles is available
continuous-integration/drone/push Build is passing Details

pull/20/head
Rayhân HASSOU 1 year ago
commit 1110cafa4c

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

@ -6,6 +6,8 @@ import ColorContext from '../theme/ColorContext';
interface FoodElementTextProps { interface FoodElementTextProps {
title : string title : string
mainColour: string
secondaryColour: string
} }
const componentHeight = 60; const componentHeight = 60;
@ -21,7 +23,7 @@ export default function FoodElementText(props : any) {
justifyContent: 'center', justifyContent: 'center',
width: "80%", width: "80%",
borderRadius: 5, borderRadius: 5,
backgroundColor: colors.carrouselBackground, backgroundColor: props.mainColour ? props.mainColour : colors.ingredientBackground,
marginHorizontal: "3%", marginHorizontal: "3%",
}, },
text: { text: {
@ -42,7 +44,7 @@ export default function FoodElementText(props : any) {
height: 50, height: 50,
borderRadius: 5, borderRadius: 5,
borderWidth: 2, borderWidth: 2,
borderColor: colors.cardDetail, borderColor: props.secondaryColour ? props.secondaryColour : colors.foodElementBorder,
flexDirection: 'row', flexDirection: 'row',
justifyContent: 'space-between', justifyContent: 'space-between',
}, },

@ -6,10 +6,12 @@ import ColorContext from '../theme/ColorContext';
type ListProps = { type ListProps = {
title: string title: string
content : string[] content : string[]
val : string[]
setSelected: any;
} }
export default function ListSelect(props: ListProps) { export default function ListSelect(props: ListProps) {
const [selected, setSelected] = React.useState([]);
const {colors} = useContext(ColorContext); const {colors} = useContext(ColorContext);
const styles = StyleSheet.create({ const styles = StyleSheet.create({
@ -83,7 +85,7 @@ export default function ListSelect(props: ListProps) {
return ( return (
<MultipleSelectList <MultipleSelectList
setSelected={(val) => setSelected(val)} setSelected={(val) => props.setSelected(val)}
data={props.content} data={props.content}
save="value" save="value"
search={false} search={false}

@ -5,7 +5,7 @@ import ColorContext from '../theme/ColorContext';
type ListProps = { type ListProps = {
title: string title: string
content: {title: string}[] content: {value: string}[]
} }
export default function ListWithoutSelect(props: ListProps) { export default function ListWithoutSelect(props: ListProps) {

@ -6,8 +6,8 @@ import ColorContext from '../theme/ColorContext';
type ProfileProps = { type ProfileProps = {
name: string name: string
avatar: string avatar: string
diets: {title: string}[] diets: {value: string}[]
allergies: {title: string}[] allergies: {value: string}[]
} }
export default function ProfileDelete(props: ProfileProps) { export default function ProfileDelete(props: ProfileProps) {
@ -84,7 +84,7 @@ export default function ProfileDelete(props: ProfileProps) {
}, },
filters: { filters: {
fontSize: 20, fontSize: 20,
color: colors.cardElementBackground, color: colors.cardElementBorder,
flex: 1, flex: 1,
padding: "2%", padding: "2%",
paddingLeft: 0, paddingLeft: 0,

@ -17,6 +17,7 @@
"axios": "^1.6.2", "axios": "^1.6.2",
"expo": "~49.0.15", "expo": "~49.0.15",
"expo-blur": "^12.4.1", "expo-blur": "^12.4.1",
"expo-image-picker": "~14.3.2",
"expo-linear-gradient": "~12.3.0", "expo-linear-gradient": "~12.3.0",
"expo-splash-screen": "~0.20.5", "expo-splash-screen": "~0.20.5",
"expo-status-bar": "~1.6.0", "expo-status-bar": "~1.6.0",
@ -9282,6 +9283,25 @@
"expo": "*" "expo": "*"
} }
}, },
"node_modules/expo-image-loader": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/expo-image-loader/-/expo-image-loader-4.3.0.tgz",
"integrity": "sha512-2kqJIO+oYM8J3GbvTUHLqTSpt1dLpOn/X0eB4U4RTuzz/faj8l/TyQELsMBLlGAkweNUuG9LqznbaBz+WuSFEw==",
"peerDependencies": {
"expo": "*"
}
},
"node_modules/expo-image-picker": {
"version": "14.3.2",
"resolved": "https://registry.npmjs.org/expo-image-picker/-/expo-image-picker-14.3.2.tgz",
"integrity": "sha512-xr/YeQMIYheXecWP033F2SPwpBlBR5xVCx7YSfSCTH8Y9pw7Z886agqKGbS9QBVGlzJ5qecJktZ6ASSzeslDVg==",
"dependencies": {
"expo-image-loader": "~4.3.0"
},
"peerDependencies": {
"expo": "*"
}
},
"node_modules/expo-keep-awake": { "node_modules/expo-keep-awake": {
"version": "12.3.0", "version": "12.3.0",
"resolved": "https://registry.npmjs.org/expo-keep-awake/-/expo-keep-awake-12.3.0.tgz", "resolved": "https://registry.npmjs.org/expo-keep-awake/-/expo-keep-awake-12.3.0.tgz",
@ -24641,6 +24661,20 @@
"fontfaceobserver": "^2.1.0" "fontfaceobserver": "^2.1.0"
} }
}, },
"expo-image-loader": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/expo-image-loader/-/expo-image-loader-4.3.0.tgz",
"integrity": "sha512-2kqJIO+oYM8J3GbvTUHLqTSpt1dLpOn/X0eB4U4RTuzz/faj8l/TyQELsMBLlGAkweNUuG9LqznbaBz+WuSFEw==",
"requires": {}
},
"expo-image-picker": {
"version": "14.3.2",
"resolved": "https://registry.npmjs.org/expo-image-picker/-/expo-image-picker-14.3.2.tgz",
"integrity": "sha512-xr/YeQMIYheXecWP033F2SPwpBlBR5xVCx7YSfSCTH8Y9pw7Z886agqKGbS9QBVGlzJ5qecJktZ6ASSzeslDVg==",
"requires": {
"expo-image-loader": "~4.3.0"
}
},
"expo-keep-awake": { "expo-keep-awake": {
"version": "12.3.0", "version": "12.3.0",
"resolved": "https://registry.npmjs.org/expo-keep-awake/-/expo-keep-awake-12.3.0.tgz", "resolved": "https://registry.npmjs.org/expo-keep-awake/-/expo-keep-awake-12.3.0.tgz",

@ -31,7 +31,8 @@
"react-native-splash-screen": "^3.3.0", "react-native-splash-screen": "^3.3.0",
"react-native-virtualized-view": "^1.0.0", "react-native-virtualized-view": "^1.0.0",
"react-native-web": "~0.19.6", "react-native-web": "~0.19.6",
"typescript": "^5.1.3" "typescript": "^5.1.3",
"expo-image-picker": "~14.3.2"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.20.0" "@babel/core": "^7.20.0"

@ -1,32 +1,81 @@
import React, { useContext } from 'react'; import React, { useContext, useState } from 'react';
import {StyleSheet, View, ScrollView, useWindowDimensions} from 'react-native'; import {StyleSheet, View, ScrollView, useWindowDimensions, TextInput, Image, Text, NativeEventEmitter, Pressable} from 'react-native';
import { LinearGradient } from 'expo-linear-gradient'; import { LinearGradient } from 'expo-linear-gradient';
import { SafeAreaProvider } from 'react-native-safe-area-context'; import { SafeAreaProvider } from 'react-native-safe-area-context';
import ProfileModification from '../components/ProfileModification';
import ValidateButton from '../components/ValidateButton'; import ValidateButton from '../components/ValidateButton';
import ColorContext from '../theme/ColorContext'; import ColorContext from '../theme/ColorContext';
import ListWithoutSelect from '../components/ListWithoutSelect';
import ListSelect from '../components/ListSelect';
import AsyncStorage from '@react-native-async-storage/async-storage';
import EventEmitter from './EventEmitter';
import * as ImagePicker from 'expo-image-picker';
export default function CreateProfile(props) { export default function CreateProfile(props) {
const { colors } = useContext(ColorContext) const { colors } = useContext(ColorContext)
const all = [] const all = []
const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}] const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}]
const [name, onChangeName] = useState();
const [avatar, setAvatar] = useState<string>('');
const [selectedDiets, setSelectedDiets] = useState([]);
const handleSelectedDiets = (selectedValues) => {
setSelectedDiets(selectedValues);
};
const pickImage = async () => {
// No permissions request is necessary for launching the image library
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true,
aspect: [4, 3],
quality: 1,
});
console.log(result);
if (!result.canceled) {
setAvatar(result.assets[0].uri);
}
};
let imageSource
if (props.avatar == "plus.png"){
imageSource = require('../assets/images/plus.png')
}
else if (props.avatar == "plus_small.png"){
imageSource = require('../assets/images/plus_small.png')
}
else{
imageSource = require('../assets/images/logo.png')
}
const handleCreateProfile = () => { const handleCreateProfile = async () => {
const profileData = { try {
name: "Nom du profil", // Remplacez par le nom du profil // Ton code pour récupérer les profils existants et ajouter un nouveau profil
avatar: "Lien de l'avatar", // Remplacez par le lien de l'avatar const newProfile = {
diets: die.map(item => item.value), // Liste des régimes name: name,
allergies: all, // Liste des allergies avatar: avatar,
}; diets: selectedDiets,
allergies: all,
};
localStorage.setItem('profile', JSON.stringify(profileData)); // Mettre à jour AsyncStorage avec le nouveau profil
console.log("Profil créé :", profileData); let existingProfiles = await AsyncStorage.getItem('profiles');
existingProfiles = existingProfiles ? JSON.parse(existingProfiles) : [];
const updatedProfiles = [...existingProfiles, newProfile];
await AsyncStorage.setItem('profiles', JSON.stringify(updatedProfiles));
EventEmitter.emit('profileAdded');
// Redirection vers la page précédente avec un message de confirmation console.log('Profil créé :', newProfile);
props.navigation.goBack();
// Affichage d'un message props.navigation.goBack();
alert("Profil créé !");
alert('Profil créé !');
} catch (error) {
console.error('Erreur lors de la création du profil :', error);
}
}; };
const styles = StyleSheet.create({ const styles = StyleSheet.create({
@ -36,7 +85,74 @@ export default function CreateProfile(props) {
flex: 1, flex: 1,
padding: "2%", padding: "2%",
paddingTop: 0, paddingTop: 0,
},background: {
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
borderRadius: 15,
backgroundColor: colors.cardBackground,
padding: "3%",
marginHorizontal: "3%",
borderWidth: 1,
borderColor: colors.blocBorder,
},
pseudoBar: {
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
width: "100%",
marginHorizontal: "3%",
marginBottom: "3%",
},
avatar: {
padding: "5%",
resizeMode: 'contain',
borderWidth: 2,
borderColor: colors.cardElementBorder,
borderRadius: 45,
height: "100%",
flex: 0.04,
},
textInput: {
fontSize: 15,
color: colors.cardTitle,
borderRadius: 10,
borderWidth: 2,
borderStyle: 'dashed',
borderColor: colors.cardElementBorder,
alignItems: 'center',
textAlign: 'left',
flex: 0.8,
marginLeft: "7%",
padding: "2%",
},
modify: {
height: "100%",
tintColor: colors.cardElementBorder,
resizeMode: 'contain',
flex: 0.1,
marginLeft: "3%",
},
filterBar: {
flexDirection: "row",
width: "85%",
paddingTop: "3%",
paddingBottom: "2%",
alignItems: "flex-end",
justifyContent: "center",
},
filters: {
fontSize: 20,
color: colors.cardElementBorder,
flex: 1,
}, },
nbSelected: {
fontSize: 11,
color: colors.cardDetail,
textAlign: "right",
}
}); });
return ( return (
@ -44,7 +160,22 @@ export default function CreateProfile(props) {
<ScrollView> <ScrollView>
<LinearGradient colors={[colors.primary, colors.primaryComplement]} style={[styles.linearGradient, {minHeight: useWindowDimensions().height}]}> <LinearGradient colors={[colors.primary, colors.primaryComplement]} style={[styles.linearGradient, {minHeight: useWindowDimensions().height}]}>
<View style={{marginTop: "6%"}}/> <View style={{marginTop: "6%"}}/>
<ProfileModification name="" avatar="plus_small.png" diets={die} allergies={all}></ProfileModification> <View style={styles.background}>
<View style={styles.pseudoBar}>
<Pressable onPress={pickImage}>
<Image source={imageSource} style={styles.avatar}></Image>
</Pressable>
<TextInput style={styles.textInput} value={name} onChangeText={onChangeName} placeholder="Name"></TextInput>
</View>
<View style={styles.filterBar}>
<Text style={styles.filters}>Filters</Text>
<Text style={styles.nbSelected}>0 diets selected</Text>
</View>
<ListSelect title="Diets" content={die} setSelected={handleSelectedDiets}></ListSelect>
<View style={{marginTop: "6%"}}/>
<ListWithoutSelect title="Allergies" content={all}></ListWithoutSelect>
<View style={{marginTop: "3%"}}/>
</View>
<View style={{marginTop: "3%"}}/> <View style={{marginTop: "3%"}}/>
<ValidateButton title="Create Profile" image="plus.png" colour={colors.buttonMain} backColour={colors.cardBackground} todo={handleCreateProfile}></ValidateButton> <ValidateButton title="Create Profile" image="plus.png" colour={colors.buttonMain} backColour={colors.cardBackground} todo={handleCreateProfile}></ValidateButton>
<View style={{marginTop: "20%"}}/> <View style={{marginTop: "20%"}}/>

@ -0,0 +1,5 @@
import { NativeEventEmitter } from 'react-native';
const eventEmitter = new NativeEventEmitter();
export default eventEmitter;

@ -167,7 +167,7 @@ export default function HomePage({ navigation, props }) {
<Pressable onPress={decreaseCounter}> <Pressable onPress={decreaseCounter}>
<Image source={bracketLeft} style={{width: 40, height: 40, resizeMode: "contain"}} tintColor={colors.carrouselText}/> <Image source={bracketLeft} style={{width: 40, height: 40, resizeMode: "contain"}} tintColor={colors.carrouselText}/>
</Pressable> </Pressable>
<FoodElementText title={ingredientList[cpt].title}/> <FoodElementText title={ingredientList[cpt].title} mainColour={colors.carrouselBackground} secondaryColour={colors.cardDetail}/>
<Pressable onPress={increaseCounter}> <Pressable onPress={increaseCounter}>
<Image source={bracketRight} style={{width: 40, height: 40, resizeMode: "contain"}} tintColor={colors.carrouselText} /> <Image source={bracketRight} style={{width: 40, height: 40, resizeMode: "contain"}} tintColor={colors.carrouselText} />
</Pressable> </Pressable>

@ -19,7 +19,9 @@ export default function IngredientSelection(props) {
const [selectedIngredients, setSelectedIngredients] = useState([]); const [selectedIngredients, setSelectedIngredients] = useState([]);
const ingredientService = new IngredientService(); const ingredientService = new IngredientService();
const {colors} = useContext(ColorContext); const {colors} = useContext(ColorContext);
const [availableSize, setAvailableSize] = useState(0);
const [listVisibility, setListVisibility] = useState("none");
const [availableVisibility, setAvailableVisibility] = useState("none");
const [searchQuery, setSearchQuery] = useState(''); const [searchQuery, setSearchQuery] = useState('');
const filterIngredients = async (query) => { const filterIngredients = async (query) => {
@ -63,10 +65,10 @@ const loadIngredients = async () => {
<View style={styles.horizontalAlignment}> <View style={styles.horizontalAlignment}>
<FoodElementText title={value.name} /> <FoodElementText title={value.name} />
<Pressable onPress={() => SelectIngredient(value)}> <Pressable onPress={() => SelectIngredient(value)}>
<Image source={plus} style={{ width: 20, height: 20 }} /> <Image source={plus} style={{ width: 20, height: 20, tintColor: colors.cardDetail }} />
</Pressable> </Pressable>
</View> </View>
<View style={{ height: 30 }}></View> <View style={{ height: 20 }}></View>
</> </>
); );
@ -75,26 +77,65 @@ const loadIngredients = async () => {
<View style={styles.horizontalAlignment}> <View style={styles.horizontalAlignment}>
<FoodElementText title={value.name} /> <FoodElementText title={value.name} />
<Pressable onPress={() => RemoveIngredient(value.id)}> <Pressable onPress={() => RemoveIngredient(value.id)}>
<Image source={moins} style={{ width: 20, height: 20 }} /> <Image source={moins} style={{ width: 20, height: 20, tintColor: colors.cardDetail }} />
</Pressable> </Pressable>
</View> </View>
<View style={{ height: 30 }}></View> <View style={{ height: 20 }}></View>
</> </>
); );
const SelectIngredient = (newIngredient: Ingredient) => { const SelectIngredient = (newIngredient: Ingredient) => {
const exists = selectedIngredients.find((ingredient) => ingredient.id === newIngredient.id); const exists = selectedIngredients.find((ingredient) => ingredient.id === newIngredient.id);
console.log("Test 1: ", selectedIngredients.length)
if (!exists) { if (!exists) {
setSelectedIngredients([...selectedIngredients, newIngredient]); setSelectedIngredients([...selectedIngredients, newIngredient]);
} }
console.log("Test 2: ", selectedIngredients.length)
ChangeAvailableSize(false)
}; };
const RemoveIngredient = (idIngredient: number) => { const RemoveIngredient = (idIngredient: number) => {
console.log("Test 1 Remove: ", selectedIngredients.length)
const updatedIngredients = selectedIngredients.filter((ingredient) => ingredient.id !== idIngredient); const updatedIngredients = selectedIngredients.filter((ingredient) => ingredient.id !== idIngredient);
setSelectedIngredients(updatedIngredients); setSelectedIngredients(updatedIngredients);
console.log("Test 2 Remove: ", selectedIngredients.length)
ChangeAvailableSize(true)
}; };
const ChangeAvailableSize = (remove: boolean) => {
if(remove){
if (selectedIngredients.length == 1){
setAvailableSize(0)
}
else if (selectedIngredients.length == 2){
setAvailableSize(90)
}
else if (selectedIngredients.length == 3){
setAvailableSize(180)
}
else if (selectedIngredients.length == 4){
setAvailableSize(260)
}
else{
setAvailableSize(280)
}
}
else{
if (selectedIngredients.length == 0){
setAvailableSize(90)
}
else if (selectedIngredients.length == 1){
setAvailableSize(180)
}
else if (selectedIngredients.length == 2){
setAvailableSize(260)
}
else{
setAvailableSize(280)
}
}
}
const handleLetterPress = async (letter: string) => { const handleLetterPress = async (letter: string) => {
try { try {
const ingredientsByLetter = await ingredientService.getIngredientByLetter(letter); const ingredientsByLetter = await ingredientService.getIngredientByLetter(letter);
@ -106,6 +147,24 @@ const loadIngredients = async () => {
} }
}; };
const changeListVisibility = () => {
if(listVisibility == "none"){
setListVisibility("flex")
}
else{
setListVisibility("none")
}
};
const changeAvailableVisibility = () => {
if(availableVisibility == "none"){
setAvailableVisibility("flex")
}
else{
setAvailableVisibility("none")
}
};
const styles = StyleSheet.create({ const styles = StyleSheet.create({
linearGradient: { linearGradient: {
width: "100%", width: "100%",
@ -136,46 +195,56 @@ const loadIngredients = async () => {
<LinearGradient colors={[colors.primary, colors.primaryComplement]} style={[styles.linearGradient, {minHeight: useWindowDimensions().height}]}> <LinearGradient colors={[colors.primary, colors.primaryComplement]} style={[styles.linearGradient, {minHeight: useWindowDimensions().height}]}>
<View style={{marginTop: "6%"}}/> <View style={{marginTop: "6%"}}/>
<View style={styles.element}> <View style={styles.element}>
<View style={[styles.horizontalAlignment, { margin: "2%" }]}> <View style={{justifyContent: "center"}}>
{alphabetArray.map((source, index) => ( <Pressable onPress={changeListVisibility} style={{alignItems: "center"}}>
<Pressable key={index} onPress={() => handleLetterPress(source)}> <Image source={require("../assets/images/arrow.png")} style={{tintColor: colors.cardDetail}}/>
<Text style={{ color: colors.letterFilter }}>{source}</Text> </Pressable>
</Pressable>
))}
</View>
<View>
<Searchbar
placeholder="Search"
onChangeText={handleSearch}
value={searchQuery}
style={{margin: "3%",
backgroundColor: colors.cardBackground,
borderWidth : 1,
borderColor: colors.cardElementBorder,
borderRadius: 15,
}}/>
</View> </View>
<View style={{height: 280}}> <View style={{display: listVisibility}}>
<FlatList <View style={[styles.horizontalAlignment, { margin: "2%" }]}>
data={response ? response : []} {alphabetArray.map((source, index) => (
renderItem={({ item }) => ( <Pressable key={index} onPress={() => handleLetterPress(source)}>
<AvailableItem value={item} /> <Text style={{ color: colors.letterFilter }}>{source}</Text>
)} </Pressable>
keyExtractor={(item, index) => index.toString()} ))}
ListEmptyComponent={() => ( </View>
isLoading ? <ActivityIndicator size="large" /> : <Text>Erreur lors du traitement des données</Text> <View>
)} <Searchbar
style={{ flex: 1 }} placeholder="Search"
/> onChangeText={handleSearch}
<View style={{ marginTop: '6%' }}></View> value={searchQuery}
style={{margin: "3%",
backgroundColor: colors.cardBackground,
borderWidth : 1,
borderColor: colors.cardElementBorder,
borderRadius: 15,
}}/>
</View>
<View style={{height: 280}}>
<FlatList
data={response ? response : []}
renderItem={({ item }) => (
<AvailableItem value={item} />
)}
keyExtractor={(item, index) => index.toString()}
ListEmptyComponent={() => (
isLoading ? <ActivityIndicator size="large" /> : <Text>Erreur lors du traitement des données</Text>
)}
style={{ flex: 1 }}
/>
<View style={{ marginTop: '6%' }}></View>
</View>
</View> </View>
</View> </View>
<View style={{marginTop: "6%"}}/> <View style={{marginTop: "6%"}}/>
<View style={styles.element}> <View style={styles.element}>
<View style={[styles.horizontalAlignment, {justifyContent: "flex-start", marginLeft: "5%"}]}> <Pressable onPress={changeAvailableVisibility}>
<Text style={{fontSize: 20, color: colors.cardElementBorder}}>Available</Text> <View style={[styles.horizontalAlignment, {justifyContent: "flex-start", marginHorizontal: "5%", marginBottom: "4%"}]}>
</View> <Text style={{fontSize: 20, color: colors.cardElementBorder, flex: 1}}>Available</Text>
<View style={{height: 280}}> <Image source={require("../assets/images/arrow.png")} style={{tintColor: colors.cardDetail}}/>
</View>
</Pressable>
<View style={{height: availableSize, display: availableVisibility}}>
<FlatList <FlatList
data={selectedIngredients} data={selectedIngredients}
renderItem={({ item }) => ( renderItem={({ item }) => (
@ -188,7 +257,7 @@ const loadIngredients = async () => {
</View> </View>
</View> </View>
<View style={{marginTop: "8%"}}></View> <View style={{marginTop: "8%"}}></View>
<ValidateButton title="Find a recipe" image="validate.png" colour={colors.buttonMain} backColour={colors.cardBackground} /> <ValidateButton title="Find a recipe" image="validate.png" colour={colors.buttonMain} backColour={colors.cardBackground}/>
<View style={{marginBottom: "20%"}}></View> <View style={{marginBottom: "20%"}}></View>
</LinearGradient> </LinearGradient>
</SafeAreaProvider> </SafeAreaProvider>

@ -8,6 +8,8 @@ import ProfileDetails from '../components/ProfileDetails';
import ProfileDelete from '../components/ProfileDelete'; import ProfileDelete from '../components/ProfileDelete';
import ColorContext from '../theme/ColorContext'; import ColorContext from '../theme/ColorContext';
import AsyncStorage from '@react-native-async-storage/async-storage'; import AsyncStorage from '@react-native-async-storage/async-storage';
import EventEmitter from './EventEmitter';
import Profil from '../Models/Profil';
export default function Profiles({navigation, props}) { export default function Profiles({navigation, props}) {
const { colors, toggleColors } = useContext(ColorContext) const { colors, toggleColors } = useContext(ColorContext)
@ -46,13 +48,18 @@ export default function Profiles({navigation, props}) {
return []; return [];
} }
} }
const fetchProfiles = async () => {
const existingProfiles = await handleGetProfiles();
setProfiles(existingProfiles);
};
const subscription = EventEmitter.addListener('profileAdded', async () => {
fetchProfiles();
});
useEffect(() => { useEffect(() => {
const fetchProfiles = async () => { handleDeleteProfiles();
const existingProfiles = await handleGetProfiles();
setProfiles(existingProfiles);
};
fetchProfiles(); fetchProfiles();
}, []); }, []);
@ -81,7 +88,7 @@ export default function Profiles({navigation, props}) {
modal: { modal: {
position: 'absolute', position: 'absolute',
top: '8%', top: '0%',
justifyContent: "center", justifyContent: "center",
alignItems: "center", alignItems: "center",
width: "100%", width: "100%",
@ -170,12 +177,12 @@ export default function Profiles({navigation, props}) {
const profileComponents = profiles.map((profile, index) => ( const profileComponents = profiles.map((profile, index) => (
<View key={index}> <View key={index}>
<ProfileDetails <ProfileDetails
name={profile.name} name={profile.name}
avatar={profile.avatar} avatar={profile.avatar}
diets={profile.diets} diets={profile.diets}
allergies={profile.allergies} allergies={profile.allergies}
onDeleteProfile={raisePopUp} onDeleteProfile={() => raisePopUp()} // <- Modification ici
/> />
{index < profiles.length - 1 && <View style={styles.separator} />} {index < profiles.length - 1 && <View style={styles.separator} />}
</View> </View>
)); ));

@ -36,6 +36,7 @@ export interface Theme {
buttonMain: string, buttonMain: string,
yesButton: string, yesButton: string,
letterFilter: string, letterFilter: string,
foodElementBorder: string,
} }
export const LightTheme : Theme = { export const LightTheme : Theme = {
@ -64,6 +65,7 @@ export const LightTheme : Theme = {
buttonMain: Ecru, buttonMain: Ecru,
yesButton: Moonstone, yesButton: Moonstone,
letterFilter: Moonstone, letterFilter: Moonstone,
foodElementBorder: Jet,
} }
export const DarkTheme : Theme = { export const DarkTheme : Theme = {
@ -92,5 +94,6 @@ export const DarkTheme : Theme = {
buttonMain: CarolinaBlue, buttonMain: CarolinaBlue,
yesButton: CarolinaBlue, yesButton: CarolinaBlue,
letterFilter: CarolinaBlue, letterFilter: CarolinaBlue,
foodElementBorder: CarolinaBlue,
} }

Loading…
Cancel
Save