WORK-RHA2 #21

Merged
rayhan.hassou merged 9 commits from WORK-RHA2 into master 1 year ago

@ -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,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({
@ -74,7 +76,7 @@ export default function ListSelect(props: ListProps) {
}, },
badgesText: { badgesText: {
fontSize: 15, fontSize: 15,
color: colors.cardElementText, color: colors.badgeText,
}, },
box: { box: {
borderColor: "#3F3C42" borderColor: "#3F3C42"
@ -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}
@ -98,6 +100,7 @@ export default function ListSelect(props: ListProps) {
checkBoxStyles={styles.box} checkBoxStyles={styles.box}
notFoundText="All Diets Already Selected" notFoundText="All Diets Already Selected"
placeholder={props.title} placeholder={props.title}
labelStyles={styles.title}
label={props.title}/> label={props.title}/>
); );
} }

@ -5,12 +5,14 @@ import ColorContext from '../theme/ColorContext';
type ListProps = { type ListProps = {
title: string title: string
content: {value: string}[] content: string[]
} }
export default function ListWithoutSelect(props: ListProps) { export default function ListWithoutSelect(props: ListProps) {
const [selected, setSelected] = React.useState([]);
const { colors } = useContext(ColorContext); const { colors } = useContext(ColorContext);
const styles = StyleSheet.create({ const styles = StyleSheet.create({
titleBar: { titleBar: {
flexDirection: "row", flexDirection: "row",
@ -58,6 +60,7 @@ export default function ListWithoutSelect(props: ListProps) {
width: "100%", width: "100%",
minWidth: 250, minWidth: 250,
maxWidth: 250, maxWidth: 250,
backgroundColor: colors.cardElementBackground,
}, },
itemText: { itemText: {
fontSize: 13, fontSize: 13,
@ -71,11 +74,13 @@ export default function ListWithoutSelect(props: ListProps) {
box: { box: {
borderWidth: 0, borderWidth: 0,
flex: 0, flex: 0,
backgroundColor: colors.cardElementBackground,
} }
}); });
return ( return (
<MultipleSelectList <MultipleSelectList
setSelected={(val) => setSelected(val)}
data={props.content} data={props.content}
save="value" save="value"
search={false} search={false}
@ -84,8 +89,11 @@ export default function ListWithoutSelect(props: ListProps) {
inputStyles={styles.title} inputStyles={styles.title}
dropdownStyles={styles.itemList} dropdownStyles={styles.itemList}
dropdownItemStyles={styles.itemCell} dropdownItemStyles={styles.itemCell}
disabledItemStyles={styles.itemCell}
dropdownTextStyles={styles.itemText} dropdownTextStyles={styles.itemText}
disabledTextStyles={styles.itemText}
checkBoxStyles={styles.box} checkBoxStyles={styles.box}
disabledCheckBoxStyles={styles.box}
notFoundText="None" notFoundText="None"
placeholder={props.title} placeholder={props.title}
label={props.title}/> label={props.title}/>

@ -9,6 +9,7 @@ type ProfileProps = {
avatar: string avatar: string
diets: string[] diets: string[]
allergies: string[] allergies: string[]
onModification: () => void
onDeleteProfile: () => void onDeleteProfile: () => void
} }
@ -78,10 +79,10 @@ export default function ProfileDetails(props) {
}, },
modify: { modify: {
height: "100%", height: "100%",
width: "100%",
tintColor: colors.cardElementBorder, tintColor: colors.cardElementBorder,
resizeMode: 'contain', resizeMode: 'contain',
flex: 0.1, flex: 1,
marginLeft: "3%",
}, },
delete: { delete: {
height: "100%", height: "100%",
@ -128,7 +129,9 @@ export default function ProfileDetails(props) {
<View style={styles.pseudoBar}> <View style={styles.pseudoBar}>
<Image source={imageSource} style={styles.avatar}></Image> <Image source={imageSource} style={styles.avatar}></Image>
<Text style={styles.text}>{props.name}</Text> <Text style={styles.text}>{props.name}</Text>
<Pressable onPress={props.onModification} style={{flex: 0.1, marginRight: "1%",}}>
<Image source={require("../assets/images/modify.png")} style={styles.modify}></Image> <Image source={require("../assets/images/modify.png")} style={styles.modify}></Image>
</Pressable>
<Pressable onPress={props.onDeleteProfile} style={{flex: 0.1, marginLeft: "1%",}}> <Pressable onPress={props.onDeleteProfile} style={{flex: 0.1, marginLeft: "1%",}}>
<Image source={require("../assets/images/delete.png")} style={styles.delete}></Image> <Image source={require("../assets/images/delete.png")} style={styles.delete}></Image>
</Pressable> </Pressable>

@ -33,18 +33,15 @@ export default function ProfileElement(props : Profile) {
else{ else{
setSeparator("none") setSeparator("none")
} }
console.log(waiting, separator, props.name)
} }
let imageSource let imageSource
if (props.avatar == "plus.png"){ if(props.avatar == null){
imageSource = require('../assets/images/plus.png') console.log("NUUUULLLLLE" + props.avatar)
}
else if (props.avatar == "plus_small.png"){
imageSource = require('../assets/images/plus_small.png')
} }
else{ else{
imageSource = require('../assets/images/logo.png') imageSource = { uri: props.avatar };
console.log("MAAARCHHEEE" + props.avatar)
} }
const styles = StyleSheet.create({ const styles = StyleSheet.create({

@ -9,8 +9,8 @@ import ColorContext from '../theme/ColorContext';
type ProfileProps = { type ProfileProps = {
name: string name: string
avatar: string avatar: string
diets: string[] diets: {value: string}[]
allergies: string[] allergies: {value: string}[]
} }
export default function ProfileModification(props: ProfileProps) { export default function ProfileModification(props: ProfileProps) {
@ -60,7 +60,7 @@ export default function ProfileModification(props: ProfileProps) {
}, },
textInput: { textInput: {
fontSize: 15, fontSize: 15,
color: colors.cardTitle, color: colors.cardDetail,
borderRadius: 10, borderRadius: 10,
borderWidth: 2, borderWidth: 2,
borderStyle: 'dashed', borderStyle: 'dashed',
@ -92,11 +92,6 @@ export default function ProfileModification(props: ProfileProps) {
color: colors.cardElementBorder, color: colors.cardElementBorder,
flex: 1, flex: 1,
}, },
nbSelected: {
fontSize: 11,
color: colors.cardDetail,
textAlign: "right",
}
}); });
return ( return (
@ -108,7 +103,6 @@ export default function ProfileModification(props: ProfileProps) {
</View> </View>
<View style={styles.filterBar}> <View style={styles.filterBar}>
<Text style={styles.filters}>Filters</Text> <Text style={styles.filters}>Filters</Text>
<Text style={styles.nbSelected}>0 diets selected</Text>
</View> </View>
<ListSelect title="Diets" content={props.diets}></ListSelect> <ListSelect title="Diets" content={props.diets}></ListSelect>
<View style={{marginTop: "6%"}}/> <View style={{marginTop: "6%"}}/>

@ -19,7 +19,7 @@ export default function CookingStackScreen() {
options={{ options={{
headerStyle: {backgroundColor: theme === 'light' ? '#F2F0E4' : '#3F3C42'}, headerStyle: {backgroundColor: theme === 'light' ? '#F2F0E4' : '#3F3C42'},
headerTitle: () => ( headerTitle: () => (
<HeaderTitle title='Profile Modification'/> <HeaderTitle title='Ingredient Selection'/>
) )
}} }}
/> />

@ -34,7 +34,10 @@ export default function ProfilesStackScreen({ navigation }) {
} }
}) })
const _handleSearch = () => console.log('Searching'); const _handleSearch = () => {
console.log('Searching');
navigation.navigate('ProfileModification')
}
const _handleHeaderAdd = () => navigation.navigate('ProfileCreation'); const _handleHeaderAdd = () => navigation.navigate('ProfileCreation');
return ( return (

@ -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);
const handleCreateProfile = () => { if (!result.canceled) {
const profileData = { setAvatar(result.assets[0].uri);
name: "Nom du profil", // Remplacez par le nom du profil }
avatar: "Lien de l'avatar", // Remplacez par le lien de l'avatar
diets: die.map(item => item.value), // Liste des régimes
allergies: all, // Liste des allergies
}; };
localStorage.setItem('profile', JSON.stringify(profileData));
console.log("Profil créé :", profileData);
// Redirection vers la page précédente avec un message de confirmation let imageSource
if (props.avatar == "plus.png"){
imageSource = {uri: avatar}
}
else if (props.avatar == "plus_small.png"){
imageSource = {uri: avatar}
}
else{
imageSource = {uri: avatar}
}
const handleCreateProfile = async () => {
try {
// Ton code pour récupérer les profils existants et ajouter un nouveau profil
const newProfile = {
name: name,
avatar: avatar,
diets: selectedDiets,
allergies: all,
};
// Mettre à jour AsyncStorage avec le nouveau profil
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');
console.log('Profil créé :', newProfile);
props.navigation.goBack(); props.navigation.goBack();
// Affichage d'un message
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;

@ -70,7 +70,7 @@ export default function HomePage({ navigation, props }) {
}, },
filters: { filters: {
fontSize: 20, fontSize: 20,
color: colors.cardTitle, color: colors.cardElementBorder,
flex: 1, flex: 1,
}, },
nbSelected: { nbSelected: {
@ -121,6 +121,16 @@ export default function HomePage({ navigation, props }) {
} }
}); });
const nbActiveProfiles = () => {
let cpt = 0
profiles.forEach((val) => {
if(val.isActive == "flex"){
cpt += 1
}
})
return cpt
}
return ( return (
<SafeAreaProvider style={{flex: 1}}> <SafeAreaProvider style={{flex: 1}}>
<ScrollView> <ScrollView>
@ -130,7 +140,7 @@ export default function HomePage({ navigation, props }) {
<View style={{flexDirection: "column", alignItems: "flex-start", justifyContent: "center", width: "100%"}}> <View style={{flexDirection: "column", alignItems: "flex-start", justifyContent: "center", width: "100%"}}>
<View style={{flexDirection: "row"}}> <View style={{flexDirection: "row"}}>
<Text style={styles.text}>Welcome </Text> <Text style={styles.text}>Welcome </Text>
<Text style={styles.name}>Rayhân</Text> <Text style={styles.name}>Louison</Text>
<Text style={styles.text}>,</Text> <Text style={styles.text}>,</Text>
</View> </View>
<Text style={styles.text}>Glad to see you again!</Text> <Text style={styles.text}>Glad to see you again!</Text>
@ -140,7 +150,7 @@ export default function HomePage({ navigation, props }) {
<View style={styles.profilesSelection}> <View style={styles.profilesSelection}>
<View style={styles.filterBar}> <View style={styles.filterBar}>
<Text style={styles.filters}>Profiles</Text> <Text style={styles.filters}>Profiles</Text>
<Text style={styles.nbSelected}>2 selected</Text> <Text style={styles.nbSelected}>{nbActiveProfiles()} selected</Text>
</View> </View>
<View style={{marginTop: "3%"}}/> <View style={{marginTop: "3%"}}/>
<ProfileSelection listProfile={profiles} disableSelection={true}/> <ProfileSelection listProfile={profiles} disableSelection={true}/>

@ -3,7 +3,6 @@ import { View, StyleSheet, Text, Image, Pressable, ActivityIndicator, FlatList,
import { SafeAreaProvider } from 'react-native-safe-area-context'; import { SafeAreaProvider } from 'react-native-safe-area-context';
import { Searchbar } from 'react-native-paper'; import { Searchbar } from 'react-native-paper';
import FoodElementText from '../components/FoodElementText'; import FoodElementText from '../components/FoodElementText';
import CustomButton from '../components/CustomButton';
import plus from '../assets/images/plus.png'; import plus from '../assets/images/plus.png';
import moins from '../assets/images/minus.png'; import moins from '../assets/images/minus.png';
@ -29,7 +28,6 @@ export default function IngredientSelection(props) {
try { try {
setIsLoading(true); setIsLoading(true);
if (query === '') { if (query === '') {
// Si le query (prompt) est vide, charger tous les ingrédients
loadIngredients(); loadIngredients();
} else { } else {
const filtered = await ingredientService.getfilteredIngredient(query); const filtered = await ingredientService.getfilteredIngredient(query);
@ -42,7 +40,6 @@ export default function IngredientSelection(props) {
} }
}; };
// Appelée à chaque changement de la recherche
const handleSearch = (query) => { const handleSearch = (query) => {
setSearchQuery(query); setSearchQuery(query);
filterIngredients(query); filterIngredients(query);

@ -15,12 +15,12 @@ export default function ModifyProfile(props) {
return ( return (
<SafeAreaProvider style={{flex: 1}}> <SafeAreaProvider style={{flex: 1}}>
<ScrollView style={{minHeight: useWindowDimensions().height}}> <ScrollView style={{minHeight: useWindowDimensions().height}}>
<LinearGradient colors={['#2680AA', '#59BDCD']} 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="Johnny Silverhand" avatar="plus_small.png" diets={die} allergies={all}></ProfileModification> <ProfileModification name="Johnny Silverhand" avatar="plus_small.png" diets={die} allergies={all}></ProfileModification>
<View style={{marginTop: "3%"}}/> <View style={{marginTop: "3%"}}/>
<ValidateButton title="Update Profile" image="update.png" colour={colors.buttonMain} backColour={colors.buttonBackground} todo={() => (console.log("Profile Modified"))}></ValidateButton> <ValidateButton title="Update Profile" image="update.png" colour={colors.buttonMain} backColour={colors.cardBackground} todo={() => (console.log("Profile Modified"))}></ValidateButton>
<View style={{marginBottom: "20%"}}/> <View style={{marginTop: "20%"}}/>
</LinearGradient> </LinearGradient>
</ScrollView> </ScrollView>
</SafeAreaProvider> </SafeAreaProvider>
@ -28,14 +28,6 @@ export default function ModifyProfile(props) {
} }
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: {
height: "100%",
width: "100%",
flex: 1,
backgroundColor: '#3F3C42',
alignItems: 'center',
justifyContent: 'center',
},
linearGradient: { linearGradient: {
height: "100%", height: "100%",
width: "100%", width: "100%",

@ -1,7 +1,5 @@
import React, { useContext, useState } from 'react'; import React, { useContext, useEffect, useState } from 'react';
import { StyleSheet, View, Pressable, Text, Image, ScrollView, useWindowDimensions } from 'react-native'; import { StyleSheet, View, Modal, Pressable, Text, Image, ScrollView, useWindowDimensions } from 'react-native';
import {Modal, Portal, PaperProvider} from 'react-native-paper';
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';
@ -9,47 +7,85 @@ import { SafeAreaProvider } from 'react-native-safe-area-context';
import ProfileDetails from '../components/ProfileDetails'; 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 EventEmitter from './EventEmitter';
import Profil from '../Models/Profil';
import { PaperProvider, Portal } from 'react-native-paper';
export default function Profiles({navigation, props}) { export default function Profiles({navigation, props}) {
const { colors } = useContext(ColorContext) const { colors, toggleColors } = useContext(ColorContext)
const allJohnny = [{value: "Coconut"}, {value: "Skimmed Milk"}, {value: "Nuts"}]
const dieJohnny = [{value: "Gluten free"}, {value: "Porkless"}, {value: "Pescatarian"}]
const allJackie = [{value: "Tomato"}, {value: "Relic"}] const all = []
const dieJackie = [{value: "Porkless"}, {value: "Vegetarian"}] const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}]
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const raisePopUp = () => { const [opacity, setOpacity] = useState(1);
const [profiles, setProfiles] = useState([]);
const [selectedProfileIndex, setSelectedProfileIndex] = useState(null);
const raisePopUp = (index) => {
setSelectedProfileIndex(index)
setVisible(true) setVisible(true)
} }
const erasePopUp = () => { const erasePopUp = () => {
setVisible(false) setVisible(false)
} }
const profiles = [ const handleDeleteProfiles = async () => {
{ try {
name: "Johnny Silverhand", await AsyncStorage.removeItem('profiles');
avatar: "plus_small.png", console.log('Données supprimées avec succès !');
diets: dieJohnny, } catch (error) {
allergies: allJohnny, console.error('Erreur lors de la suppression des données :', error);
}, }
{ };
name: "Jackie Welles",
avatar: "plus_small.png", const handleDeleteProfile = async (index) => {
diets: dieJackie, try {
allergies: allJackie, const updatedProfiles = profiles.filter((profile, i) => i !== index);
}, await AsyncStorage.setItem('profiles', JSON.stringify(updatedProfiles));
// ... Ajoutez d'autres profils ici de la même manière fetchProfiles();
]; setSelectedProfileIndex(index);
erasePopUp();
} catch (error) {
console.error('Erreur lors de la suppression du profil :', error);
}
};
const confirmDelete = () => {
erasePopUp();
};
const handleGetProfiles = async () => {
try {
const existingProfiles = await AsyncStorage.getItem('profiles');
return JSON.parse(existingProfiles) || [];
} catch (error) {
console.log("ça maaaaaaaaarche poaaaaaaaaaaaas");
return [];
}
}
const fetchProfiles = async () => {
const existingProfiles = await handleGetProfiles();
setProfiles(existingProfiles);
};
const subscription = EventEmitter.addListener('profileAdded', async () => {
fetchProfiles();
});
useEffect(() => {
fetchProfiles();
console.log(profiles)
}, []);
const containerStyle = { const containerStyle = {
//minHeight: useWindowDimensions().height/2,
//width: useWindowDimensions().width,
height: "75%", height: "75%",
width: "100%", width: "100%",
}; };
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
height: "100%", height: "100%",
@ -168,32 +204,24 @@ export default function Profiles({navigation, props}) {
avatar={profile.avatar} avatar={profile.avatar}
diets={profile.diets} diets={profile.diets}
allergies={profile.allergies} allergies={profile.allergies}
onDeleteProfile={raisePopUp}/> onDeleteProfile={() => raisePopUp(index)}
{index < profiles.length - 1 && <View style={styles.separator} />} />
</View>
));
return (
<SafeAreaProvider style={{flex: 1}}>
<PaperProvider>
<ScrollView>
<LinearGradient colors={[colors.primary, colors.primaryComplement]} style={[styles.linearGradient, {minHeight: useWindowDimensions().height}]}>
<View style={styles.separator}/>
{profileComponents}
<View style={{marginBottom: "20%"}}/>
</LinearGradient>
</ScrollView>
<Portal> <Portal>
<Modal visible={visible} onDismiss={erasePopUp} contentContainerStyle={containerStyle} style={{marginTop: 0, justifyContent: "flex-start"}}> <Modal visible={visible} onDismiss={erasePopUp} contentContainerStyle={containerStyle} style={{marginTop: 0, justifyContent: "flex-start"}}>
<View style={styles.modal}> <View style={styles.modal}>
<View style={styles.viewModal}> <View style={styles.viewModal}>
<View style={styles.profileValidation}> <View style={styles.profileValidation}>
<ProfileDelete name="Johnny Silverhand" avatar="plus_small.png" diets={dieJohnny} allergies={allJohnny}></ProfileDelete> {/* <ProfileDelete
name={profiles[selectedProfileIndex].name}
avatar={profiles[selectedProfileIndex].avatar}
diets={profiles[selectedProfileIndex].diets}
allergies={profiles[selectedProfileIndex].allergies}
/> */}
</View> </View>
<View style={styles.decisionBarVertical}> <View style={styles.decisionBarVertical}>
<Text style={styles.validationQuestion}>Do you really want to delete this profile?</Text> <Text style={styles.validationQuestion}>Do you really want to delete this profile?</Text>
<View style={styles.decisionBar}> <View style={styles.decisionBar}>
<Pressable onPress={erasePopUp} style={{flex:0.5}}> <Pressable onPress={() => handleDeleteProfile(selectedProfileIndex)} style={{flex:0.5}}>
<View style={styles.yesButton}> <View style={styles.yesButton}>
<Image source={require("../assets/images/validate.png")} style={{tintColor: "#2DE04A", height: "100%", flex: 0.2, margin: "5%", resizeMode: "contain"}}/> <Image source={require("../assets/images/validate.png")} style={{tintColor: "#2DE04A", height: "100%", flex: 0.2, margin: "5%", resizeMode: "contain"}}/>
<Text style={styles.yesText}>Yes</Text> <Text style={styles.yesText}>Yes</Text>
@ -211,6 +239,23 @@ export default function Profiles({navigation, props}) {
</View> </View>
</Modal> </Modal>
</Portal> </Portal>
{index < profiles.length - 1 && <View style={styles.separator} />}
</View>
));
return (
<SafeAreaProvider style={{flex: 1}}>
<PaperProvider>
<ScrollView>
<LinearGradient colors={[colors.primary, colors.primaryComplement]} style={[styles.linearGradient, {minHeight: useWindowDimensions().height}]}>
<View style={styles.separator}/>
{profileComponents}
<View style={{marginBottom: "20%"}}/>
</LinearGradient>
</ScrollView>
</PaperProvider> </PaperProvider>
</SafeAreaProvider> </SafeAreaProvider>
); );

@ -14,7 +14,6 @@ export default function RecipeDetails(props) {
const {colors} = useContext(ColorContext); const {colors} = useContext(ColorContext);
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState();
const [response, setResponse] = useState<Recipes | undefined>(undefined); const [response, setResponse] = useState<Recipes | undefined>(undefined);
const recipesService = new RecipesService(); const recipesService = new RecipesService();
@ -23,7 +22,7 @@ export default function RecipeDetails(props) {
const recipe = await recipesService.getRecipeById(props.id); const recipe = await recipesService.getRecipeById(props.id);
setResponse(recipe); setResponse(recipe);
} catch (error) { } catch (error) {
setError(error); console.log(error);
} finally { } finally {
setIsLoading(false); setIsLoading(false);
} }

@ -37,6 +37,7 @@ export interface Theme {
yesButton: string, yesButton: string,
letterFilter: string, letterFilter: string,
foodElementBorder: string, foodElementBorder: string,
badgeText: string,
} }
export const LightTheme : Theme = { export const LightTheme : Theme = {
@ -66,6 +67,7 @@ export const LightTheme : Theme = {
yesButton: Moonstone, yesButton: Moonstone,
letterFilter: Moonstone, letterFilter: Moonstone,
foodElementBorder: Jet, foodElementBorder: Jet,
badgeText: Jet,
} }
export const DarkTheme : Theme = { export const DarkTheme : Theme = {
@ -95,5 +97,6 @@ export const DarkTheme : Theme = {
yesButton: CarolinaBlue, yesButton: CarolinaBlue,
letterFilter: CarolinaBlue, letterFilter: CarolinaBlue,
foodElementBorder: CarolinaBlue, foodElementBorder: CarolinaBlue,
badgeText: Alabaster,
} }

Loading…
Cancel
Save